Skip to content

Commit df21f12

Browse files
committed
Use inboard with Python 3.9 for back-end
- Update Dockerfile for inboard: https://inboard.bws.bio - Set inboard environment variables: `APP_MODULE`, `PRE_START_PATH` - Remove references to `start-reload.sh` (not present in inboard) - Update pyproject.toml for inboard: Gunicorn 20, Uvicorn 0.14, and FastAPI 0.66 (and thereby Starlette and pydantic) are managed there. - Update Python version in pyproject.toml to 3.9
1 parent 490c554 commit df21f12

File tree

6 files changed

+24
-50
lines changed

6 files changed

+24
-50
lines changed

Diff for: {{cookiecutter.project_slug}}/.env

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ DOCKER_IMAGE_CELERYWORKER={{cookiecutter.docker_image_celeryworker}}
1414
DOCKER_IMAGE_FRONTEND={{cookiecutter.docker_image_frontend}}
1515

1616
# Backend
17+
BACKEND_APP_MODULE=app.main:app
1718
BACKEND_CORS_ORIGINS={{cookiecutter.backend_cors_origins}}
19+
BACKEND_PRE_START_PATH=/app/prestart.sh
1820
PROJECT_NAME={{cookiecutter.project_name}}
1921
SECRET_KEY={{cookiecutter.secret_key}}
2022
FIRST_SUPERUSER={{cookiecutter.first_superuser}}

Diff for: {{cookiecutter.project_slug}}/README.md

+1-21
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ During development, you can change Docker Compose settings that will only affect
8282

8383
The changes to that file only affect the local development environment, not the production environment. So, you can add "temporary" changes that help the development workflow.
8484

85-
For example, the directory with the backend code is mounted as a Docker "host volume", mapping the code you change live to the directory inside the container. That allows you to test your changes right away, without having to build the Docker image again. It should only be done during development, for production, you should build the Docker image with a recent version of the backend code. But during development, it allows you to iterate very fast.
86-
87-
There is also a command override that runs `/start-reload.sh` (included in the base image) instead of the default `/start.sh` (also included in the base image). It starts a single server process (instead of multiple, as would be for production) and reloads the process whenever the code changes. Have in mind that if you have a syntax error and save the Python file, it will break and exit, and the container will stop. After that, you can restart the container by fixing the error and running again:
85+
For example, the directory with the backend code is mounted as a Docker "host volume", mapping the code you change live to the directory inside the container. That allows you to test your changes right away, without having to build the Docker image again. It should only be done during development, for production, you should build the Docker image with a recent version of the backend code. But during development, it allows you to iterate very fast. Have in mind that if you have a syntax error and save the Python file, it will break and exit, and the container will stop. After that, you can restart the container by fixing the error and running again:
8886

8987
```console
9088
$ docker-compose up -d
@@ -112,24 +110,6 @@ root@7f2607af31c3:/app#
112110

113111
that means that you are in a `bash` session inside your container, as a `root` user, under the `/app` directory.
114112

115-
There you can use the script `/start-reload.sh` to run the debug live reloading server. You can run that script from inside the container with:
116-
117-
```console
118-
$ bash /start-reload.sh
119-
```
120-
121-
...it will look like:
122-
123-
```console
124-
root@7f2607af31c3:/app# bash /start-reload.sh
125-
```
126-
127-
and then hit enter. That runs the live reloading server that auto reloads when it detects code changes.
128-
129-
Nevertheless, if it doesn't detect a change but a syntax error, it will just stop with an error. But as the container is still alive and you are in a Bash session, you can quickly restart it after fixing the error, running the same command ("up arrow" and "Enter").
130-
131-
...this previous detail is what makes it useful to have the container alive doing nothing and then, in a Bash session, make it run the live reload server.
132-
133113
### Backend tests
134114

135115
To test the backend run:

Diff for: {{cookiecutter.project_slug}}/backend/app/pyproject.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ description = ""
55
authors = ["Admin <[email protected]>"]
66

77
[tool.poetry.dependencies]
8-
python = "^3.7"
9-
uvicorn = "^0.11.3"
10-
fastapi = "^0.54.1"
8+
python = "^3.9"
9+
inboard = {version = "^0.10.2", extras = ["fastapi"]}
1110
python-multipart = "^0.0.5"
1211
email-validator = "^1.0.5"
1312
requests = "^2.23.0"
1413
celery = "^4.4.2"
1514
passlib = {extras = ["bcrypt"], version = "^1.7.2"}
1615
tenacity = "^6.1.0"
17-
pydantic = "^1.4"
1816
emails = "^0.5.15"
1917
raven = "^6.10.0"
20-
gunicorn = "^20.0.4"
2118
jinja2 = "^2.11.2"
2219
psycopg2-binary = "^2.8.5"
2320
alembic = "^1.4.2"
+6-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
2-
3-
WORKDIR /app/
4-
5-
# Install Poetry
6-
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \
7-
cd /usr/local/bin && \
8-
ln -s /opt/poetry/bin/poetry && \
9-
poetry config virtualenvs.create false
1+
FROM ghcr.io/br3ndonland/inboard:fastapi-python3.9
102

113
# Copy poetry.lock* in case it doesn't exist in the repo
124
COPY ./app/pyproject.toml ./app/poetry.lock* /app/
135

6+
WORKDIR /app/
7+
148
# Allow installing dev dependencies to run tests
159
ARG INSTALL_DEV=false
1610
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
@@ -21,5 +15,6 @@ RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; els
2115
ARG INSTALL_JUPYTER=false
2216
RUN bash -c "if [ $INSTALL_JUPYTER == 'true' ] ; then pip install jupyterlab ; fi"
2317

24-
COPY ./app /app
25-
ENV PYTHONPATH=/app
18+
ARG BACKEND_APP_MODULE=app.main:app BACKEND_PRE_START_PATH=/app/prestart.sh
19+
ENV APP_MODULE=${BACKEND_APP_MODULE} PRE_START_PATH=${BACKEND_PRE_START_PATH}
20+
COPY ./app/ /app/

Diff for: {{cookiecutter.project_slug}}/docker-compose.override.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
version: "3.3"
22
services:
3-
43
proxy:
54
ports:
65
- "80:80"
@@ -40,18 +39,18 @@ services:
4039
ports:
4140
- "8888:8888"
4241
volumes:
43-
- ./backend/app:/app
42+
- ./backend/app/app:/app/app
4443
environment:
4544
- JUPYTER=jupyter lab --ip=0.0.0.0 --allow-root --NotebookApp.custom_display_url=http://127.0.0.1:8888
4645
- SERVER_HOST=http://${DOMAIN?Variable not set}
4746
build:
4847
context: ./backend
4948
dockerfile: backend.dockerfile
5049
args:
50+
BACKEND_APP_MODULE: ${BACKEND_APP_MODULE-app.main:app}
51+
BACKEND_PRE_START_PATH: ${BACKEND_PRE_START_PATH-/app/prestart.sh}
5152
INSTALL_DEV: ${INSTALL_DEV-true}
5253
INSTALL_JUPYTER: ${INSTALL_JUPYTER-true}
53-
# command: bash -c "while true; do sleep 1; done" # Infinite loop to keep container live doing nothing
54-
command: /start-reload.sh
5554
labels:
5655
- traefik.enable=true
5756
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}

Diff for: {{cookiecutter.project_slug}}/docker-compose.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
version: "3.3"
22
services:
3-
43
proxy:
54
image: traefik:v2.2
65
networks:
@@ -62,7 +61,7 @@ services:
6261
# Redirect a domain without www to www
6362
# To enable it remove the previous line and uncomment the next
6463
# - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
65-
# Middleware to redirect www, to disable it remove the next line
64+
# Middleware to redirect www, to disable it remove the next line
6665
- traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
6766
# Middleware to redirect www, and redirect HTTP to HTTPS
6867
# to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
@@ -110,7 +109,7 @@ services:
110109
# image: rabbitmq:3-management
111110
#
112111
# You also have to change the flower command
113-
112+
114113
flower:
115114
image: mher/flower
116115
networks:
@@ -136,9 +135,9 @@ services:
136135
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
137136
- traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
138137
- traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555
139-
138+
140139
backend:
141-
image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
140+
image: "${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}"
142141
depends_on:
143142
- db
144143
env_file:
@@ -152,16 +151,18 @@ services:
152151
context: ./backend
153152
dockerfile: backend.dockerfile
154153
args:
154+
BACKEND_APP_MODULE: ${BACKEND_APP_MODULE-app.main:app}
155+
BACKEND_PRE_START_PATH: ${BACKEND_PRE_START_PATH-/app/prestart.sh}
155156
INSTALL_DEV: ${INSTALL_DEV-false}
156157
deploy:
157158
labels:
158159
- traefik.enable=true
159160
- traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
160161
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
161162
- traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
162-
163+
163164
celeryworker:
164-
image: '${DOCKER_IMAGE_CELERYWORKER?Variable not set}:${TAG-latest}'
165+
image: "${DOCKER_IMAGE_CELERYWORKER?Variable not set}:${TAG-latest}"
165166
depends_on:
166167
- db
167168
- queue
@@ -177,9 +178,9 @@ services:
177178
dockerfile: celeryworker.dockerfile
178179
args:
179180
INSTALL_DEV: ${INSTALL_DEV-false}
180-
181+
181182
frontend:
182-
image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
183+
image: "${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}"
183184
build:
184185
context: ./frontend
185186
args:

0 commit comments

Comments
 (0)