alessandro trinca tornidor commited on
Commit
8c1771d
1 Parent(s): fcb8c81

[refactor] use entrypoint.sh as CMD Dockerfile, add FOLDERS_MAP env file to dynamic folder creation

Browse files
Dockerfile CHANGED
@@ -184,4 +184,4 @@ RUN ls -l ${FASTAPI_STATIC}/ || true
184
  RUN ls -l ${FASTAPI_STATIC}/dist || true
185
  RUN ls -l ${FASTAPI_STATIC}/node_modules || true
186
 
187
- CMD ["uvicorn", "wrappers.fastapi_wrapper:app", "--host", "0.0.0.0", "--port", "7860"]
 
184
  RUN ls -l ${FASTAPI_STATIC}/dist || true
185
  RUN ls -l ${FASTAPI_STATIC}/node_modules || true
186
 
187
+ CMD ["/var/task/scripts/entrypoint.sh"]
scripts/create_folders_and_variables_if_not_exists.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import logging
3
+ import os
4
+ from pathlib import Path
5
+
6
+
7
+ def stats_pathname(pathname: Path | str):
8
+ current_pathname = Path(pathname)
9
+ return current_pathname.is_dir()
10
+
11
+
12
+ def create_folder_if_not_exists(pathname: Path | str):
13
+ current_pathname = Path(pathname)
14
+ try:
15
+ print(f"Pathname exists? {current_pathname.exists()}, That's a folder? {current_pathname.is_dir()}...")
16
+ logging.info(f"Pathname exists? {current_pathname.exists()}, That's a folder? {current_pathname.is_dir()}...")
17
+ current_pathname.unlink(missing_ok=True)
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} ...")
24
+ current_pathname.mkdir(mode=0o770, parents=True, exist_ok=True)
25
+
26
+ print(f"assertion: pathname exists and is a folder: {current_pathname} ...")
27
+ logging.info(f"assertion: pathname exists and is a folder: {current_pathname} ...")
28
+ assert current_pathname.is_dir()
29
+
30
+
31
+ if __name__ == '__main__':
32
+ folders_string = os.getenv("FOLDERS_MAP")
33
+ folders_dict = json.loads(folders_string)
34
+ for folder_env_ref, folder_env_path in folders_dict.items():
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
scripts/entrypoint.sh CHANGED
@@ -2,63 +2,26 @@
2
 
3
  WORKDIR="/var/task"
4
  XDG_CACHE_HOME="/data"
5
- PROJECT_ROOT_FOLDER=${XDG_CACHE_HOME}
6
- MPLCONFIGDIR=${XDG_CACHE_HOME}/.cache/matplotlib
7
- TRANSFORMERS_CACHE=${XDG_CACHE_HOME}/.cache/transformers
8
- FASTAPI_STATIC=${WORKDIR}/static
9
- VIS_OUTPUT=${XDG_CACHE_HOME}/vis_output
10
 
11
- echo "WORKDIR content: ${WORKDIR}, before creating the FASTAPI_STATIC symlink ..."
12
- ls -ld ${WORKDIR}
13
- ls -lA ${WORKDIR}
14
- cd ${WORKDIR}
15
-
16
- ln -s ${FASTAPI_STATIC} .
17
- echo "WORKDIR content: ${WORKDIR}, after creating the FASTAPI_STATIC symlink ..."
18
- ls -ld ${WORKDIR}
19
- ls -lA ${WORKDIR}
20
- ls -lA ${WORKDIR}/static
21
-
22
- echo "XDG_CACHE_HOME content: ${XDG_CACHE_HOME}, before creating the folders ..."
23
- ls -ld ${XDG_CACHE_HOME}/
24
- ls -l ${XDG_CACHE_HOME}/
25
-
26
- mkdir -p ${XDG_CACHE_HOME}/.cache
27
- mkdir -p ${MPLCONFIGDIR}
28
- mkdir -p ${TRANSFORMERS_CACHE}
29
- mkdir -p ${FASTAPI_STATIC}
30
- mkdir -p ${VIS_OUTPUT}
31
- chmod 770 -R ${FASTAPI_STATIC}
32
- chmod 770 -R ${VIS_OUTPUT}
33
- chmod 770 -R ${XDG_CACHE_HOME}/.cache
34
-
35
- echo "XDG_CACHE_HOME content: ${XDG_CACHE_HOME}, after creating the folders ..."
36
- ls -ld ${XDG_CACHE_HOME}/
37
- ls -lA ${XDG_CACHE_HOME}/
38
- export WORKDIR
39
- export XDG_CACHE_HOME
40
- export MPLCONFIGDIR
41
- export TRANSFORMERS_CACHE
42
- export FASTAPI_STATIC
43
- export VIS_OUTPUT
44
- export PROJECT_ROOT_FOLDER
45
 
46
  source ${WORKDIR}/venv/bin/activate
47
 
48
  which python
49
  python --version
 
50
 
51
  free -m
52
- which nvcc
53
- nvcc -V
54
- which nvidia-smi
55
- nvidia-smi
56
  pip list
57
 
58
  which uvicorn
59
  ls -l ${WORKDIR}/venv/bin/uvicorn
60
 
61
- df -h / /data /home /var/task
62
 
63
  echo "WORKDIR - /var/task"
64
  ls -l ${WORKDIR}
 
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}/script/create_folders_and_variables_if_not_exists.py
13
 
14
  free -m
15
+ which nvcc || true
16
+ nvcc -V || true
17
+ which nvidia-smi || true
18
+ nvidia-smi || true
19
  pip list
20
 
21
  which uvicorn
22
  ls -l ${WORKDIR}/venv/bin/uvicorn
23
 
24
+ df -h / /home ${WORKDIR} ${XDG_CACHE_HOME}
25
 
26
  echo "WORKDIR - /var/task"
27
  ls -l ${WORKDIR}