-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
79 lines (66 loc) · 3.36 KB
/
Copy pathDockerfile
File metadata and controls
79 lines (66 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Container Python API, Kafka, Lambda consumer, via Terraform + CloudFormation
# github.com/sqlxpert/docker-python-openapi-kafka-terraform-cloudformation-aws
# GPLv3, Copyright Paul Marcelin
# Defaults required:
# https://docs.docker.com/reference/build-checks/invalid-default-arg-in-from
ARG BASE_AMAZONLINUX_REGISTRY_DOMAIN='public.ecr.aws'
ARG BASE_AMAZONLINUX_REGISTRY_PATH="${BASE_AMAZONLINUX_REGISTRY_DOMAIN}/amazonlinux/"
ARG BASE_AMAZONLINUX_TAG='2023.10.20260216.1'
ARG BASE_AMAZONLINUX_DIGEST='sha256:dfa14233aa5e9f951074312290a1d217272cd1a04babdf1f87a68ea27d6eeac6'
FROM "${BASE_AMAZONLINUX_REGISTRY_PATH}amazonlinux:${BASE_AMAZONLINUX_TAG}@${BASE_AMAZONLINUX_DIGEST}"
ARG BASE_AMAZONLINUX_REGISTRY_PATH
ARG BASE_AMAZONLINUX_TAG
ARG BASE_AMAZONLINUX_DIGEST
LABEL org.opencontainers.image.base.name="${BASE_AMAZONLINUX_REGISTRY_PATH}amazonlinux:${BASE_AMAZONLINUX_TAG}"
LABEL org.opencontainers.image.base.digest="${BASE_AMAZONLINUX_DIGEST}"
LABEL org.opencontainers.image.documentation="https://github.com/sqlxpert/docker-python-openapi-kafka-terraform-cloudformation-aws"
LABEL org.opencontainers.image.title="Hello world API"
LABEL org.opencontainers.image.description="Uses Python 3.13, OpenAPI 3.0, Connexion, Uvicorn workers, Gunicorn"
LABEL org.opencontainers.image.authors="Paul Marcelin"
LABEL org.opencontainers.image.vendor="Paul Marcelin"
LABEL org.opencontainers.image.licenses="GPL-3.0-only"
LABEL org.opencontainers.image.source="https://github.com/sqlxpert/docker-python-openapi-kafka-terraform-cloudformation-aws/blob/main/Dockerfile"
SHELL ["/usr/bin/bash", "-c"]
RUN \
--mount=type=cache,target=/var/cache/dnf,sharing=locked \
--mount=type=cache,target=/var/lib/dnf,sharing=locked \
dnf install \
--assumeyes \
--setopt=install_weak_deps=False \
--nodocs \
python3.13 \
coreutils-single \
util-linux \
shadow-utils \
&& useradd --shell /usr/bin/bash --home /hello_api --user-group --uid 1011 hello_api \
&& dnf remove \
--assumeyes \
--setopt=clean_requirements_on_remove=True \
shadow-utils
# shadow-utils provides useradd
# coreutils-single (present in Amazon Linux by default, but noted here as a
# dependency) provides cat and util-linux provides script for ECS Exec logging
# Operating system package versions are omitted, thanks to
# https://docs.aws.amazon.com/linux/al2023/ug/deterministic-upgrades.html
USER hello_api
WORKDIR /hello_api
ENV VIRTUAL_ENV="/hello_api/python_venv"
RUN python3.13 -m venv "${VIRTUAL_ENV}"
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
###############################################################################
# Local file references ( --mount=type=bind,source= , COPY , ADD )
#
# Also add files to .dockerignore ; mine ignores files not explicitly listed.
RUN \
--mount=type=bind,source=requirements.txt,target=/tmp/requirements.txt \
--mount=type=cache,target=.cache/pip,uid=1011,gid=1011 \
pip install --upgrade pip==26.0.1 \
&& pip install --requirement /tmp/requirements.txt \
&& pip uninstall --yes pip
COPY \
hello_api.openapi.yaml \
hello_api.py \
./
###############################################################################
EXPOSE 8000/tcp
CMD ["gunicorn", "--log-level", "error", "--error-logfile", "-", "--access-logfile", "-", "--worker-class", "uvicorn.workers.UvicornWorker", "--worker-tmp-dir", "/dev/shm", "--workers", "2", "--bind", "0.0.0.0:8000", "hello_api:hello_api_app"]