Skip to content

Commit 5424f72

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 stages to Dockerfile. - Moved package removal to production stage. - Added target dev to compose file.
1 parent ff2fd01 commit 5424f72

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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 djangoproject-www-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 djangoproject-www-base AS djangoproject-www-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 djangoproject-www-dev AS djangoproject-www-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: djangoproject-www-dev
67
args:
78
- REQ_FILE=requirements/tests.txt
89
entrypoint: ./docker-entrypoint.dev.sh

0 commit comments

Comments
 (0)