Skip to content

Commit 53f6818

Browse files
committed
Use array syntax in Dockerfile, minor improvements
1 parent e8b19c8 commit 53f6818

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

Dockerfile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ RUN apt-get update \
2020
RUN pip install --no-cache-dir -U pip
2121
RUN pip install --no-cache-dir -U poetry
2222

23+
# We run everything by poetry run from now on, so that PATH will be handled
24+
# for binaries installed in virtual environments
25+
ENTRYPOINT ["poetry", "run"]
26+
2327
FROM base as base_builder
2428
# Install build system requirements (gcc, library headers, etc.)
2529
# for compiled Python requirements like psycopg2
@@ -37,9 +41,12 @@ COPY --chown=nonroot:nonroot pyproject.toml .
3741
COPY --chown=nonroot:nonroot poetry.lock .
3842

3943
# Test image, contains all files and dependencies
40-
FROM base_builder as test
44+
FROM base_builder as dev
4145
RUN poetry install --with http,grpc,dev
4246
COPY --chown=nonroot:nonroot . .
47+
# Note that opentelemetry doesn't play well together with uvicorn reloader
48+
# when signals are propagated, we disable it in dev image default CMD
49+
CMD ["uvicorn", "http_app:create_app", "--host", "0.0.0.0", "--port", "8000", "--factory", "--reload"]
4350

4451
# Installs requirements to run production http application
4552
FROM base_builder as http_builder
@@ -62,20 +69,17 @@ COPY --chown=nonroot:nonroot config.py .
6269
COPY --chown=nonroot:nonroot di_container.py .
6370
COPY --chown=nonroot:nonroot alembic.ini .
6471
COPY --chown=nonroot:nonroot Makefile .
65-
ENTRYPOINT ["poetry", "run"]
6672

6773
# Copy the http python package and requirements from relevant builder
6874
FROM base_app as http_app
6975
COPY --from=http_builder /poetryvenvs /poetryvenvs
7076
COPY --chown=nonroot:nonroot http_app ./http_app
71-
# opentelemetry-instrument will spawn a subprocess, therefore we use exec
72-
# to make sure the app runs on PID 1 and receives correctly system signals
73-
CMD opentelemetry-instrument uvicorn http_app:create_app --host 0.0.0.0 --port 8000 --factory
77+
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
78+
CMD ["opentelemetry-instrument", "uvicorn", "http_app:create_app", "--host", "0.0.0.0", "--port", "8000", "--factory"]
7479

7580
# Copy the grpc python package and requirements from relevant builder
7681
FROM base_app as grpc_app
7782
COPY --from=grpc_builder /poetryvenvs /poetryvenvs
7883
COPY --chown=nonroot:nonroot grpc_app ./grpc_app
79-
# opentelemetry-instrument will spawn a subprocess, therefore we use exec
80-
# to make sure the app runs on PID 1 and receives correctly system signals
81-
CMD exec opentelemetry-instrument python3 -m grpc_app
84+
# Run CMD using array syntax, so it's uses `exec` and runs as PID1
85+
CMD ["opentelemetry-instrument", "python3", "-m", "grpc_app"]

docker-compose.yaml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
version: '3.8'
22
services:
3-
# We don't use `make` or `poetry` for long running processes,
4-
# to make sure they run as pid 1 and receive SIGTERM signal
53
dev:
64
build:
75
dockerfile: Dockerfile
86
context: .
9-
target: http_app
7+
target: dev
108
ports:
119
- '8000:8000'
12-
command:
13-
- "uvicorn"
14-
- "http_app:create_app"
15-
- "--host"
16-
- "0.0.0.0"
17-
- "--port"
18-
- "8000"
19-
- "--factory"
20-
- "--reload"
2110
volumes:
2211
- '.:/app'
2312
http:
@@ -66,7 +55,7 @@ services:
6655
build:
6756
dockerfile: Dockerfile
6857
context: .
69-
target: test
58+
target: dev
7059
volumes:
7160
- '.:/app'
7261
command:
@@ -77,7 +66,7 @@ services:
7766
build:
7867
dockerfile: Dockerfile
7968
context: .
80-
target: test
69+
target: dev
8170
command:
8271
- "make"
8372
- "ci-test"

0 commit comments

Comments
 (0)