Skip to content

Commit

Permalink
chore: tune dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jakuboskera committed Jun 2, 2022
1 parent c6eca4a commit d067a9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
34 changes: 12 additions & 22 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
31 changes: 20 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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" ]

0 comments on commit d067a9a

Please sign in to comment.