Skip to content

Commit d4f8800

Browse files
committed
Implemented Docker multi-stage build
This solves the first part of #1817, where tox fails to install test dependencies due to missing packages. - Added target inputs to GitHub workflows. - Added stages to Dockerfile. - Moved package removal to production stage. - Added target dev to compose file.
1 parent 75f3fde commit d4f8800

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

.github/workflows/docker-publish.yml

+1
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ jobs:
4444
push: true
4545
tags: ${{ steps.meta.outputs.tags }}
4646
labels: ${{ steps.meta.outputs.labels }}
47+
target: django-web-prod

.github/workflows/docker-test-build.yml

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ jobs:
3535
push: false
3636
build-args: |
3737
REQ_FILE=requirements/${{ matrix.req_file }}
38+
target: django-web-dev

Dockerfile

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pull official base image
2-
FROM python:3.12-slim-bookworm
2+
FROM python:3.12-slim-bookworm AS django-web-base
33

44
# set work directory
55
WORKDIR /usr/src/app
@@ -33,13 +33,10 @@ RUN apt-get update \
3333
libc6-dev \
3434
libpq-dev \
3535
zlib1g-dev \
36-
&& python3 -m pip install --no-cache-dir -r ${REQ_FILE} \
37-
&& apt-get purge --assume-yes --auto-remove \
38-
gcc \
39-
libc6-dev \
40-
libpq-dev \
41-
zlib1g-dev \
42-
&& rm -rf /var/lib/apt/lists/*
36+
&& python3 -m pip install --no-cache-dir -r ${REQ_FILE}
37+
38+
39+
FROM django-web-base AS django-web-dev
4340

4441
# install node dependencies
4542
COPY ./package.json ./package.json
@@ -48,5 +45,15 @@ RUN npm install
4845
# copy project
4946
COPY . .
5047

48+
49+
FROM django-web-dev AS django-web-prod
50+
51+
RUN apt-get purge --assume-yes --auto-remove \
52+
gcc \
53+
libc6-dev \
54+
libpq-dev \
55+
zlib1g-dev \
56+
&& rm -rf /var/lib/apt/lists/*
57+
5158
# ENTRYPOINT is specified only in the local docker-compose.yml to avoid
5259
# accidentally running it in deployed environments.

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
build:
44
context: ./
55
dockerfile: Dockerfile
6+
target: django-web-dev
67
args:
78
- REQ_FILE=requirements/tests.txt
89
entrypoint: ./docker-entrypoint.dev.sh

0 commit comments

Comments
 (0)