-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathDockerfile
119 lines (89 loc) · 4.02 KB
/
Dockerfile
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
###############################################################################
# STAGE 1 - build-image
###############################################################################
FROM quay.io/app-sre/qontract-reconcile-builder:0.7.0 AS build-image
COPY --from=ghcr.io/astral-sh/uv:0.5.7@sha256:23272999edd22e78195509ea3fe380e7632ab39a4c69a340bedaba7555abe20a /uv /bin/uv
WORKDIR /work
COPY pyproject.toml uv.lock README.md ./
COPY helm helm
COPY tools tools
COPY reconcile reconcile
ENV \
# compile bytecode for faster startup
UV_COMPILE_BYTECODE="true" \
# disable uv cache. it doesn't make sense in a container
UV_NO_CACHE=true
# Install dependencies and qontract-reconcile
RUN UV_DYNAMIC_VERSIONING_BYPASS="0.0.0" uv sync --frozen --no-group dev --python /usr/bin/python3
###############################################################################
# STAGE 2 - dev-image
###############################################################################
FROM quay.io/app-sre/qontract-reconcile-base:0.14.0 AS dev-image
COPY --from=ghcr.io/astral-sh/uv:0.5.7@sha256:23272999edd22e78195509ea3fe380e7632ab39a4c69a340bedaba7555abe20a /uv /bin/uv
ARG CONTAINER_UID=1000
RUN useradd --uid ${CONTAINER_UID} reconcile && \
chown -R reconcile /.terraform.d
WORKDIR /work
COPY --from=build-image --chown=reconcile:root /work/ ./
RUN UV_DYNAMIC_VERSIONING_BYPASS="0.0.0" uv sync --frozen --no-cache --group debugger --no-group dev
# Move .venv out of the workdir so it can't be overwritten by volume mount
RUN mv .venv /venv
USER reconcile
VOLUME ["/work", "/config"]
# Set the PATH to include the virtualenv
ENV PATH="/venv/bin:${PATH}"
ENTRYPOINT ["/work/dev/run.sh"]
###############################################################################
# STAGE 3 - prod-image
###############################################################################
FROM quay.io/app-sre/qontract-reconcile-base:0.14.0 AS prod-image
ARG quay_expiration=never
LABEL quay.expires-after=${quay_expiration}
# Tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
# Keep the image up to date
RUN microdnf upgrade -y && microdnf clean all
WORKDIR /work
# the integration-manager needs the helm charts
RUN ln -s /work/helm /helm
COPY --from=build-image /work ./
# Set the PATH to include the virtualenv
ENV PATH="/work/.venv/bin:${PATH}"
ENTRYPOINT ["/tini", "--"]
CMD ["run-integration"]
###############################################################################
# STAGE 4 - fips-prod-image
###############################################################################
FROM prod-image AS fips-prod-image
ENV OC_VERSION=4.16.2
# oc versions sometimes have issues with FIPS enabled systems requiring us to use specific
# versions in these environments so in this case we extract an older version of oc and kubectl
COPY --chown=0:0 --from=quay.io/app-sre/qontract-reconcile-oc:0.3.1 \
/work/${OC_VERSION}/ /usr/local/bin/
###############################################################################
# STAGE 5 - unittest image
###############################################################################
FROM prod-image AS test-image
COPY --from=ghcr.io/astral-sh/uv:0.5.7@sha256:23272999edd22e78195509ea3fe380e7632ab39a4c69a340bedaba7555abe20a /uv /bin/uv
RUN microdnf install -y make
# Tests need the .git directory to run
# podman does not support --mount=type=bind
# TODO: use --mount=source=.git,target=.git,type=bind in both RUN commands below
COPY .git .git
# Install test dependencies
RUN uv sync --frozen --no-cache --group dev
# Run tests
COPY Makefile .
RUN make all-tests
###############################################################################
# STAGE 6 - PyPI publish package
###############################################################################
FROM test-image AS pypi
ARG TWINE_USERNAME
ARG TWINE_PASSWORD
# TODO: use --mount=source=.git,target=.git,type=bind
# podman does not support --mount=type=bind
# qontract-reconcile version depends on git tags!
RUN make pypi