alessandro trinca tornidor commited on
Commit
0c9e62a
1 Parent(s): 9bca4cd

[ci] add the option to install the project in a 'bare metal' installation, see README.md for instructions

Browse files
Dockerfile CHANGED
@@ -162,7 +162,8 @@ COPY samgis_lisa_on_cuda ${LAMBDA_TASK_ROOT}/samgis_lisa_on_cuda
162
  COPY wrappers ${LAMBDA_TASK_ROOT}/wrappers
163
  COPY scripts ${LAMBDA_TASK_ROOT}/scripts
164
  RUN chmod +x ${LAMBDA_TASK_ROOT}/scripts/entrypoint.sh
165
- RUN ls -l ${LAMBDA_TASK_ROOT}/scripts/entrypoint.sh
 
166
 
167
  RUN ls -l /usr/bin/which
168
  RUN /usr/bin/which python
@@ -193,4 +194,4 @@ RUN ls -l ${FASTAPI_STATIC}/ || true
193
  RUN ls -l ${FASTAPI_STATIC}/dist || true
194
  RUN ls -l ${FASTAPI_STATIC}/node_modules || true
195
 
196
- CMD ["/var/task/scripts/entrypoint.sh"]
 
162
  COPY wrappers ${LAMBDA_TASK_ROOT}/wrappers
163
  COPY scripts ${LAMBDA_TASK_ROOT}/scripts
164
  RUN chmod +x ${LAMBDA_TASK_ROOT}/scripts/entrypoint.sh
165
+ RUN chown +x ${LAMBDA_TASK_ROOT}/scripts/docker_entrypoint.sh
166
+ RUN ls -l ${LAMBDA_TASK_ROOT}/scripts/entrypoint.sh ${LAMBDA_TASK_ROOT}/scripts/docker_entrypoint.sh
167
 
168
  RUN ls -l /usr/bin/which
169
  RUN /usr/bin/which python
 
194
  RUN ls -l ${FASTAPI_STATIC}/dist || true
195
  RUN ls -l ${FASTAPI_STATIC}/node_modules || true
196
 
197
+ CMD ["/var/task/scripts/docker_entrypoint.sh"]
README.md CHANGED
@@ -9,6 +9,7 @@ license: mit
9
  ---
10
 
11
  ## Segment Anything models
 
12
  It's possible to prepare the model files using https://github.com/vietanhdev/samexporter/ or using the ones
13
  from https://huggingface.co/aletrn/sam-quantized (copy them within the folder `/machine_learning_models`).
14
 
@@ -90,8 +91,9 @@ cd docs && make clean html && cd ../
90
  ```
91
 
92
  The static documentation it's now ready at the path `docs/_build/html/index.html`.
93
-
94
  To create a work in progress openapi json or yaml file use
 
95
  - `extract-openapi-fastapi.py`
96
  - `extract-openapi-lambda.py` (useful to export the json schema request and response from lambda app api)
97
 
@@ -113,3 +115,24 @@ it's possible to dynamically create a new support folder adding it to a json str
113
  ```
114
 
115
  The python script create_folders_and_variables_if_not_exists.py will read this env variable, removing any files that exists with these pathnames and assert the correct creation of all the folders. Also these folders must exist as env variables, so the script assert that an env variable exists with its path.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
  ## Segment Anything models
12
+
13
  It's possible to prepare the model files using https://github.com/vietanhdev/samexporter/ or using the ones
14
  from https://huggingface.co/aletrn/sam-quantized (copy them within the folder `/machine_learning_models`).
15
 
 
91
  ```
92
 
93
  The static documentation it's now ready at the path `docs/_build/html/index.html`.
94
+
95
  To create a work in progress openapi json or yaml file use
96
+
97
  - `extract-openapi-fastapi.py`
98
  - `extract-openapi-lambda.py` (useful to export the json schema request and response from lambda app api)
99
 
 
115
  ```
116
 
117
  The python script create_folders_and_variables_if_not_exists.py will read this env variable, removing any files that exists with these pathnames and assert the correct creation of all the folders. Also these folders must exist as env variables, so the script assert that an env variable exists with its path.
118
+
119
+ It's possible to use the project in a bare metal installation (not within a docker container). To do this
120
+
121
+ - download this project
122
+ - prepare a virtualenv and install the python dependencies
123
+ - install nodejs LTS
124
+ - create a .env_source file (in this case `HOME=/home/jovyan`)
125
+
126
+ ```bash
127
+ export FOLDER_MAP='{"WORKDIR":"/home/jovyan/workspace/samgis-lisa-on-cuda","XDG_CACHE_HOME":"/home/jovyan/.cache","PROJECT_ROOT_FOLDER":"/home/jovyan/","MPLCONFIGDIR":"/home/jovyan/.cache/matplotlib","TRANSFORMERS_CACHE":"/home/jovyan/.cache/transformers","PYTORCH_KERNEL_CACHE_PATH":"/home/jovyan/.cache/torch/kernels","FASTAPI_STATIC":"/home/jovyan/workspace/samgis-lisa-on-cuda/static","VIS_OUTPUT":"/home/jovyan/workspace/samgis-lisa-on-cuda/vis_output"}'
128
+ export WORKDIR="$HOME/workspace/samgis-lisa-on-cuda"
129
+ export XDG_CACHE_HOME="$HOME/.cache"
130
+ export PROJECT_ROOT_FOLDER="$HOME/"
131
+ export MPLCONFIGDIR="$HOME/.cache/matplotlib"
132
+ export TRANSFORMERS_CACHE="$HOME/.cache/transformers"
133
+ export PYTORCH_KERNEL_CACHE_PATH="$HOME/.cache/torch/kernels"
134
+ export FASTAPI_STATIC="$HOME/workspace/samgis-lisa-on-cuda/static"
135
+ export VIS_OUTPUT="$HOME/workspace/samgis-lisa-on-cuda/vis_output"
136
+ ```
137
+
138
+ - execute the script `baremetal_entrypoint.sh` instead than `docker_entrypoint.sh`.
scripts/baremetal_entrypoint.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ if [ -z "${WORKDIR}" ];
4
+ then
5
+ WORKDIR=$1
6
+ fi
7
+
8
+ if [ -z "${XDG_CACHE_HOME}" ];
9
+ then
10
+ XDG_CACHE_HOME=$HOME/.cache
11
+ fi
12
+
13
+ echo "WORKDIR: ${WORKDIR} ..."
14
+ echo "XDG_CACHE_HOME: ${XDG_CACHE_HOME} ..."
15
+
16
+ cd ${WORKDIR}
17
+
18
+ if [ ! -f "${WORKDIR}/.env_source" ];
19
+ then
20
+ echo "missing ${WORKDIR}/.env_source file, exit now..."
21
+ exit 1
22
+ fi
23
+
24
+ source ${WORKDIR}/.env_source
25
+ echo "FOLDERS_MAP: ${FOLDERS_MAP} ..."
26
+
27
+ which python
28
+ python --version
29
+ python ${WORKDIR}/scripts/create_folders_and_variables_if_not_exists.py
30
+
31
+ cd ${WORKDIR}/static
32
+ npm install -g npm pnpm
33
+ pnpm install
34
+ pnpm tailwindcss -i ${WORKDIR}/static/src/input.css -o ${WORKDIR}/static/dist/output.css
35
+ cd ${WORKDIR}
36
+
37
+ chmod +x ${WORKDIR}/scripts/entrypoint.sh
38
+ bash ${WORKDIR}/scripts/entrypoint.sh
39
+
40
+ exit 0
scripts/create_folders_and_variables_if_not_exists.py CHANGED
@@ -18,6 +18,9 @@ def create_folder_if_not_exists(pathname: Path | str):
18
  except PermissionError as pe:
19
  print(f"permission denied on removing pathname before folder creation:{pe}.")
20
  logging.error(f"permission denied on removing pathname before folder creation:{pe}.")
 
 
 
21
 
22
  print(f"Creating pathname: {current_pathname} ...")
23
  logging.info(f"Creating pathname: {current_pathname} ...")
@@ -35,4 +38,5 @@ if __name__ == '__main__':
35
  print(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
36
  logging.info(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
37
  create_folder_if_not_exists(folder_env_path)
 
38
  assert os.getenv(folder_env_ref) == folder_env_path
 
18
  except PermissionError as pe:
19
  print(f"permission denied on removing pathname before folder creation:{pe}.")
20
  logging.error(f"permission denied on removing pathname before folder creation:{pe}.")
21
+ except IsADirectoryError as errdir:
22
+ print(f"that's a directory:{errdir}.")
23
+ logging.error(f"that's a directory:{errdir}.")
24
 
25
  print(f"Creating pathname: {current_pathname} ...")
26
  logging.info(f"Creating pathname: {current_pathname} ...")
 
38
  print(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
39
  logging.info(f"folder_env_ref:{folder_env_ref}, folder_env_path:{folder_env_path}.")
40
  create_folder_if_not_exists(folder_env_path)
41
+ print("========")
42
  assert os.getenv(folder_env_ref) == folder_env_path
scripts/docker_entrypoint.sh ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ export WORKDIR="/var/task"
4
+ export XDG_CACHE_HOME="/data"
5
+
6
+ echo "FOLDERS_MAP:${FOLDERS_MAP} ..."
7
+ source ${WORKDIR}/.venv/bin/activate
8
+
9
+ which python
10
+ python --version
11
+ python ${WORKDIR}/scripts/create_folders_and_variables_if_not_exists.py
12
+
13
+ chmod +x ${WORKDIR}/scripts/entrypoint.sh
14
+ bash ${WORKDIR}/scripts/entrypoint.sh
15
+
16
+ exit 0
scripts/entrypoint.sh CHANGED
@@ -1,16 +1,5 @@
1
  #!/usr/bin/env bash
2
 
3
- WORKDIR="/var/task"
4
- XDG_CACHE_HOME="/data"
5
-
6
- echo "FOLDERS_MAP:${FOLDERS_MAP} ..."
7
-
8
- source ${WORKDIR}/.venv/bin/activate
9
-
10
- which python
11
- python --version
12
- python ${WORKDIR}/scripts/create_folders_and_variables_if_not_exists.py
13
-
14
  free -m
15
  which nvcc || true
16
  nvcc -V || true
 
1
  #!/usr/bin/env bash
2
 
 
 
 
 
 
 
 
 
 
 
 
3
  free -m
4
  which nvcc || true
5
  nvcc -V || true