Skip to content

Commit

Permalink
support python 3.12
Browse files Browse the repository at this point in the history
- 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'.
  • Loading branch information
itaru2622 committed Oct 10, 2023
1 parent c2608dc commit 8b12cb6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
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
```

## other usage on linux:
you can:
- set any uvicorn options by opts environment.
- change requirement file path by py_requirements environment.
- set any uvicorn options by opts environment variable.
- 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
apt install -y ${apt_requirements}
pip3 install -r ${py_requirements}
uvicorn ${opts} ${app}
```

## build docker image
Expand Down
4 changes: 4 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

if [ -r "${apt_requirements}" ]; then
apt update; 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
Expand Down

0 comments on commit 8b12cb6

Please sign in to comment.