-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ 🐳 Use multi-stage docker builds: split tests
This is the improvement to the Dockerfile to split tests and runtime. See details on the README updated with instructions.
- Loading branch information
1 parent
6ae50bd
commit 7ae6f3c
Showing
3 changed files
with
138 additions
and
71 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,21 +1,45 @@ | ||
FROM python:3.8.16-alpine3.17 | ||
FROM python:3.8.16-alpine3.17 AS builder | ||
|
||
# The requirements to build SqlAlchemy includes compiling from source-code, at least in Alpine | ||
# It does require GCC to compile also the MySQL client from sources. | ||
# https://stackoverflow.com/questions/59554493/unable-to-fire-a-docker-build-for-django-and-mysql/59554601#59554601 | ||
# https://stackoverflow.com/questions/8878676/compile-error-g-error-trying-to-exec-cc1plus-execvp-no-such-file-or-dir | ||
RUN apk add musl-dev python3-dev mariadb-dev gcc build-base bash | ||
|
||
WORKDIR /viasat/minitwit | ||
|
||
COPY requirements*.txt . | ||
COPY requirements.txt . | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
ENV FLASK_APP=minitwit.py | ||
ENV LC_ALL=en_US.utf-8 | ||
ENV LANG=en_US.utf-8 | ||
|
||
COPY . /viasat/minitwit | ||
COPY ./static /viasat/minitwit/static | ||
COPY ./templates /viasat/minitwit/templates | ||
|
||
COPY *.py /viasat/minitwit | ||
COPY *.sql /viasat/minitwit | ||
|
||
#### | ||
#### tester image that installs the dev dependencies and executes the test cases during build | ||
#### and during a container execution! The build will fail if any test case fails. | ||
#### The test image is good for inspection of test environments and ca be used in CI/CD envs. | ||
#### | ||
FROM builder AS tester | ||
|
||
COPY requirements-dev.txt . | ||
RUN pip install -r requirements-dev.txt | ||
|
||
# Note that we are executing the tests here because we don't want to build | ||
# A runtime image before the tests are executed successfully! | ||
RUN pytest test_minitwit.py | ||
CMD ["pytest", "test_minitwit.py"] | ||
|
||
### | ||
### runtime environment containing only the runtime dependencies. | ||
### | ||
FROM builder AS runtime | ||
|
||
# All the other resources are there, so let's add the run-app as it's part of the runtime | ||
COPY run-app . | ||
|
||
ENTRYPOINT ["bash", "/viasat/minitwit/run-app"] |
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
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