-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from max-pfeiffer/feature/docker_image_upgrade
Feature/docker image upgrade
- Loading branch information
Showing
11 changed files
with
709 additions
and
757 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
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,5 +1,6 @@ | ||
.idea | ||
.venv | ||
|
||
.coverage | ||
.pytest_cache | ||
__pycache__/ | ||
coverage_report.xml |
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,13 +1,13 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-ast | ||
- id: check-merge-conflict | ||
- id: detect-private-key | ||
- id: check-added-large-files | ||
- repo: https://github.com/psf/black | ||
rev: 22.8.0 | ||
rev: 23.11.0 | ||
hooks: | ||
- id: black | ||
language_version: python3.9 |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,17 +5,20 @@ description = "A Cookiecutter template for spinning up a micro service" | |
authors = ["Max Pfeiffer <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "3.9.*" | ||
python = "3.11.*" | ||
|
||
[tool.poetry.dev-dependencies] | ||
cookiecutter = "2.1.1" | ||
pytest = "7.1.3" | ||
pytest-cookies = "0.6.1" | ||
black = "22.8.0" | ||
pre-commit = "2.17.0" | ||
docker = "6.0.0" | ||
httpx = "0.23.0" | ||
black = "23.12.0" | ||
cookiecutter = "2.5.0" | ||
coverage = "7.3.3" | ||
docker = "7.0.0" | ||
furl = "2.1.3" | ||
httpx = "0.25.2" | ||
pytest = "7.4.3" | ||
pre-commit = "3.6.0" | ||
pytest-cookies = "0.7.0" | ||
pytest-cov = "4.1.0" | ||
toml = "0.10.2" | ||
|
||
# https://docs.pytest.org/en/latest/reference/customize.html | ||
[tool.pytest.ini_options] | ||
|
@@ -25,7 +28,7 @@ testpaths = [ | |
|
||
[tool.black] | ||
line-length = 80 | ||
target-version = ['py39'] | ||
target-version = ['py311'] | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
|
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
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,13 +1,13 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.1.0 | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-ast | ||
- id: check-merge-conflict | ||
- id: detect-private-key | ||
- id: check-added-large-files | ||
- repo: https://github.com/psf/black | ||
rev: 22.3.0 | ||
rev: 23.11.0 | ||
hooks: | ||
- id: black | ||
language_version: python3.9 |
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,90 +1,12 @@ | ||
# Be aware that you need to specify these arguments before the first FROM | ||
# see: https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact | ||
ARG OFFICIAL_PYTHON_IMAGE=python:3.9.14-slim-bullseye | ||
ARG APPLICATION_SERVER_PORT=80 | ||
FROM pfeiffermax/uvicorn-poetry:2.1.0-python3.9.14-slim-bullseye as production-dependencies-build-stage | ||
FROM pfeiffermax/uvicorn-poetry:3.2.0-python3.11.6-slim-bookworm | ||
|
||
# install [tool.poetry.dependencies] | ||
# this will install virtual environment into /.venv because of POETRY_VIRTUALENVS_IN_PROJECT=true | ||
# see: https://python-poetry.org/docs/configuration/#virtualenvsin-project | ||
COPY ./poetry.lock ./pyproject.toml /application_root/ | ||
COPY --chown=python_application:python_application ./poetry.lock ./pyproject.toml /application_root/ | ||
RUN poetry install --no-interaction --no-root --without dev | ||
|
||
FROM ${OFFICIAL_PYTHON_IMAGE} as production-image | ||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONPATH=/application_root | ||
|
||
WORKDIR /application_root | ||
|
||
COPY --from=production-dependencies-build-stage /application_root/.venv /application_root/.venv | ||
COPY --from=production-dependencies-build-stage /application_server/start_uvicorn.sh /application_server/start_uvicorn.sh | ||
|
||
# Copy application files | ||
COPY /app /application_root/app/ | ||
|
||
# Activate entrypoint for running the uvicorn application server | ||
CMD ["/application_server/start_uvicorn.sh"] | ||
|
||
# Document the exposed port which was configured in start_uvicorn.sh | ||
# https://docs.docker.com/engine/reference/builder/#expose | ||
EXPOSE ${APPLICATION_SERVER_PORT} | ||
|
||
FROM production-dependencies-build-stage as dev-dependencies-build-stage | ||
|
||
# install [tool.poetry.dev-dependencies] | ||
RUN poetry install --no-interaction --no-root | ||
|
||
FROM ${OFFICIAL_PYTHON_IMAGE} as development-image | ||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONPATH=/application_root \ | ||
UVICORN_RELOAD=1 \ | ||
UVICORN_LOG_LEVEL=debug | ||
|
||
WORKDIR /application_root | ||
|
||
COPY --from=dev-dependencies-build-stage /application_root/.venv /application_root/.venv | ||
COPY --from=dev-dependencies-build-stage /application_server/start_uvicorn.sh /application_server/ | ||
|
||
COPY . /application_root/ | ||
|
||
# Activate entrypoint for running the uvicorn application server | ||
CMD ["/application_server/start_uvicorn.sh"] | ||
|
||
# Document the exposed port which was configured in start_uvicorn.sh | ||
# https://docs.docker.com/engine/reference/builder/#expose | ||
EXPOSE ${APPLICATION_SERVER_PORT} | ||
|
||
FROM ${OFFICIAL_PYTHON_IMAGE} as test-base-image | ||
|
||
COPY --from=dev-dependencies-build-stage /application_root/.venv /application_root/.venv | ||
|
||
COPY /app /application_root/app/ | ||
COPY /tests /application_root/tests/ | ||
|
||
|
||
# image for running pep8 checks | ||
FROM test-base-image as black-test-image | ||
|
||
WORKDIR /application_root | ||
|
||
COPY --from=dev-dependencies-build-stage /entrypoints/black_entrypoint.sh /entrypoints/ | ||
|
||
ENTRYPOINT /entrypoints/black_entrypoint.sh $0 $@ | ||
|
||
CMD ["--target-version py39", "--check", " --line-length 80", "."] | ||
|
||
# image for running unit tests | ||
FROM test-base-image as test-image | ||
|
||
WORKDIR /application_root | ||
|
||
COPY --from=dev-dependencies-build-stage /entrypoints/pytest_entrypoint.sh /entrypoints/ | ||
|
||
ENTRYPOINT /entrypoints/pytest_entrypoint.sh $0 $@ | ||
|
||
# You need to use pytest-cov as pytest plugin. Makes life very simple. | ||
# tests directory is configured in pyproject.toml | ||
# https://github.com/pytest-dev/pytest-cov | ||
CMD ["--cov=app", "--cov-report=xml:/test_coverage_reports/test_coverage.xml"] | ||
COPY --chown=python_application:python_application /app /application_root/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