From d067a9ab3b78257fd237fbc5f632d402530660c2 Mon Sep 17 00:00:00 2001 From: Jakub Oskera Date: Thu, 2 Jun 2022 13:53:29 +0200 Subject: [PATCH] chore: tune dockerfile --- .dockerignore | 34 ++++++++++++---------------------- Dockerfile | 31 ++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/.dockerignore b/.dockerignore index 16945d5..aa72037 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,22 +1,12 @@ -__pycache__ -*.pyc -*.pyo -*.pyd -.Python -env -pip-log.txt -pip-delete-this-directory.txt -.tox -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.log -.git -.gitignore -Dockerfile -.mypy_cache -.pytest_cache -.hypothesis +# ignore all files except listed below +* +.* + +# we need these files inside a container +!app/ +!migrations/ +!main.py +!entrypoint.sh +!requirements/ +!requirements.txt +!settings.py diff --git a/Dockerfile b/Dockerfile index bfd27ab..252fcad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM dev-pks-harbor.cz.moravia-it.com/mirror/library/python:3.9.10-alpine3.15 +FROM python:3.9.10-alpine3.15 ARG CREATED ARG VERSION @@ -17,25 +17,34 @@ LABEL \ org.opencontainers.image.base.digest="sha256:e80214a705236091ee3821a7e512e80bd3337b50a95392a36b9a40b8fc0ea183" \ org.opencontainers.image.base.name="docker.io/library/python:3.9.10-alpine3.15" +RUN addgroup -S guestbook && adduser -S guestbook -G guestbook + +USER guestbook + WORKDIR /app -# First, copy the requirements.txt only as it helps with caching # Details: https://pythonspeed.com/articles/docker-caching-model/ -COPY requirements.txt . -RUN python3 -m pip install -r requirements.txt +COPY requirements/ ./requirements +COPY requirements.txt entrypoint.sh ./ -COPY entrypoint.sh . -RUN chmod +x entrypoint.sh +USER root -COPY app ./app -COPY migrations ./migrations -COPY main.py . +RUN python3 -m pip install -r requirements.txt --no-cache-dir -ENV FLASK_APP=main.py +RUN \ + apk update && \ + apk add postgresql-libs && \ + apk add --virtual .build-deps gcc musl-dev postgresql-dev && \ + apk --purge del .build-deps -RUN useradd -m guestbook USER guestbook +COPY --chown=guestbook:guestbook . . + +RUN chmod +x entrypoint.sh + +ENV FLASK_APP=main.py + EXPOSE 5000 ENTRYPOINT [ "./entrypoint.sh" ]