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 6, 2023
1 parent c2608dc commit b8fff41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
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.
- 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
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 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 b8fff41

Please sign in to comment.