From b8fff418f17991f920c5bd1e3dbd6a852326473f Mon Sep 17 00:00:00 2001 From: itaru2622 Date: Fri, 6 Oct 2023 22:54:18 +0900 Subject: [PATCH] support python 3.12 - update start.sh, support installing extra apt package on startup if requirements-apt.txt exists. - requirements-apt.txt is inspired from requirements.txt in python pip. the line starts with '#' will be ignored, so that we can add comment in requirements-apt.txt. - requirements-apt.txt is rename-able by environment variable 'apt_requirements'. --- Dockerfile | 1 + README.md | 6 ++++-- start.sh | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1454754..f71eacd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ RUN mkdir -p /app; echo "set mouse-=a" > /root/.vimrc; COPY ./start.sh /usr/local/bin/start.sh WORKDIR /app ENV py_requirements=./requirements.txt +ENV apt_requirements=./requirements-apt.txt ENV app=main:app ENV opts='' CMD /usr/local/bin/start.sh diff --git a/README.md b/README.md index 71760cb..850129e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ docker run --rm -it -p 8000:8000 -v ${PWD}:/app itaru2622/fastapi:bookworm # the above cmd start docker container with: +apt install -y /app/requirements-apt.txt pip3 install -r /app/requirements.txt uvicorn main:app ``` @@ -10,10 +11,11 @@ uvicorn main:app ## other usage on linux: you can: - set any uvicorn options by opts environment. -- change requirement file path by py_requirements environment. +- change requirement file path for apt install by apt_requirements environment variable. +- change requirement file path for pip install by py_requirements environment variable. - change app name by app environment according to your implementation ```bash -docker run --rm -it -p 8000:8000 -v ${PWD}:${PWD} -w ${PWD} -e py_requirements=${PWD}/requirements.txt -e app=main:app -e opts='--host 0.0.0.0 --reload --reload-include "*.py" --reload-include "*.conf"' itaru2622/fastapi:bookworm +docker run --rm -it -p 8000:8000 -v ${PWD}:${PWD} -w ${PWD} -e py_requirements=${PWD}/requirements.txt -e apt_requirements=${PWD}/requirements-apt.txt -e app=main:app -e opts='--host 0.0.0.0 --reload --reload-include "*.py" --reload-include "*.conf"' itaru2622/fastapi:bookworm # the above cmd start docker container with: pip3 install -r /app/requirements.txt uvicorn --host 0.0.0.0 --reload main:app diff --git a/start.sh b/start.sh index 21db510..6d25d12 100755 --- a/start.sh +++ b/start.sh @@ -1,5 +1,9 @@ #!/bin/bash +if [ -r "${apt_requirements}" ]; then + apt install -y `cat ${apt_requirements} | grep -v ^#` +fi + if [ -r "./setup.py" ] || [ -r "./setup.cfg" ] || [ -r "./pyproject.toml" ]; then pip3 install . elif [ -r "${py_requirements}" ]; then