-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce size of docker image by adding building stage
- Loading branch information
Showing
1 changed file
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
FROM python:3.12-alpine | ||
# Stage 1: Build stage | ||
FROM python:3.12-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt ./ | ||
|
||
|
||
RUN apk add gcc musl-dev mariadb-connector-c-dev libpq-dev | ||
COPY requirements.txt . | ||
|
||
RUN apk add --no-cache --virtual .build-deps gcc musl-dev mariadb-connector-c-dev libpq-dev | ||
|
||
RUN pip install --no-cache-dir --upgrade pip && \ | ||
pip install --no-cache-dir gunicorn && \ | ||
pip install --no-cache-dir -r requirements.txt | ||
|
||
# Stage 2: Final stage | ||
FROM python:3.12-alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
COPY --from=builder /usr/local/bin/gunicorn /usr/local/bin/gunicorn | ||
COPY --from=builder /app /app | ||
|
||
RUN apk add --no-cache mariadb-connector-c libpq | ||
|
||
COPY . . | ||
CMD python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --bind=0.0.0.0:8000 --timeout 300 --workers=3 --threads=3 --max-requests 5 --max-requests-jitter 2 pim.wsgi:application | ||
EXPOSE 8000/tcp | ||
|
||
CMD ["sh", "-c", "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn --bind=0.0.0.0:8000 --timeout 300 --workers=3 --threads=3 --max-requests 5 --max-requests-jitter 2 pim.wsgi:application"] | ||
|
||
EXPOSE 8000/tcp |