-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
216 lines (161 loc) · 5.2 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
ARG IMAGE_PATH=docker.io/rockdrilla
ARG DISTRO=debian
ARG SUITE=stable
ARG PYTHON_VERSION
ARG BUILD_HELPER_IMAGE=${DISTRO}-buildd-helper:${SUITE}
ARG BUILD_IMAGE=${DISTRO}-buildd:${SUITE}
ARG BASE_IMAGE=${DISTRO}:${SUITE}
ARG PYTHON_MIN_IMAGE=python-min:${PYTHON_VERSION}-${SUITE}
ARG PYTHON_IMAGE=python:${PYTHON_VERSION}-${SUITE}
# ---
FROM ${IMAGE_PATH}/${BUILD_HELPER_IMAGE} as build-shim
SHELL [ "/bin/sh", "-ec" ]
# these directories should be mounted as RW volumes
ARG DEB_SRC_BUILD_DIR
ARG _SRC_DIR
ARG _PKG_DIR
ARG DISTRO
ARG SUITE
ARG PYTHON_VERSION
ARG PYTHON_BASE_VERSION
COPY /package/.template/ /tmp/package/debian/
COPY /package/python/shim/ /tmp/package/debian/
# "ep.env" ensures that container limits and env are taken in account
RUN build_start=$(date -R) ; \
apt-update ; \
ep.env deb-src-export ${_SRC_DIR} /tmp/package/debian ; \
set +e ; \
ep.env deb-src-build ${_SRC_DIR}/k2-python-shim-*.dsc ${_PKG_DIR} ; \
result=$? ; \
set -e ; \
build_finish=$(date -R) ; \
cleanup ; \
echo "# build started at: ${build_start}" ; \
echo "# build finished at: ${build_finish}" ; \
echo "# build return code: ${result}" ; \
[ "${result}" = 0 ] || exit ${result}
# ---
FROM ${IMAGE_PATH}/${BUILD_HELPER_IMAGE} as build-dsc
SHELL [ "/bin/sh", "-ec" ]
# this directory should be mounted as RW volume
ARG _SRC_DIR
ARG DISTRO
ARG SUITE
ARG PYTHON_VERSION
ARG PYTHON_BASE_VERSION
ARG DEB_BUILD_OPTIONS
ARG DEB_BUILD_PROFILES
COPY /package/.template/ /tmp/package/debian/
COPY /package/python/template/ /tmp/package/debian/
COPY /package/python/${PYTHON_BASE_VERSION}/ /tmp/package/debian/
# "ep.env" ensures that container limits and env are taken in account
RUN apt-update ; \
ep.env deb-src-export ${_SRC_DIR} /tmp/package/debian ; \
cleanup ; \
# linkage with "build-pkg" layer
touch /dsc-mark
# ---
FROM ${IMAGE_PATH}/${BUILD_IMAGE} as build-pkg
SHELL [ "/bin/sh", "-ec" ]
# linkage with "build-dsc" layer
COPY --from=build-dsc /dsc-mark /tmp/
ARG CI
# these directories should be mounted as RW volumes
ARG DEB_SRC_BUILD_DIR
ARG _SRC_DIR
ARG _PKG_DIR
ARG DISTRO
ARG SUITE
ARG PYTHON_VERSION
ARG PYTHON_BASE_VERSION
ARG DEB_BUILD_OPTIONS
ARG DEB_BUILD_PROFILES
# CI/manual execution handler
ENV BUILDINFO_MASK="k2-python-${PYTHON_BASE_VERSION}_${PYTHON_VERSION}-*_*.buildinfo"
RUN [ -z "${CI}" ] || exit 0; \
if find ${_PKG_DIR}/ -maxdepth 1 -name "${BUILDINFO_MASK}" -type f -printf . -quit 2>/dev/null | grep -Fq . ; then \
# implicitly deletes /tmp/dsc-mark
cleanup ; \
exit 0 ; \
fi
# "ep.env" ensures that container limits and env are taken in account
RUN [ -e /tmp/dsc-mark ] || exit 0 ; \
apt-update ; \
build_start=$(date -R) ; \
set +e ; \
ep.env deb-src-build ${_SRC_DIR}/k2-python-${PYTHON_BASE_VERSION}_${PYTHON_VERSION}-*.dsc ${_PKG_DIR} ; \
result=$? ; \
set -e ; \
build_finish=$(date -R) ; \
cleanup ; \
echo "# build started at: ${build_start}" ; \
echo "# build finished at: ${build_finish}" ; \
echo "# build return code: ${result}" ; \
[ "${result}" = 0 ] || exit ${result}
# ---
FROM scratch as pkg
COPY --from=packages [ "*.deb", "/deb/" ]
# ---
FROM ${IMAGE_PATH}/${BASE_IMAGE} as minimal
SHELL [ "/bin/sh", "-ec" ]
ENV SITE_PACKAGES=/opt/python-${PYTHON_BASE_VERSION}/lib/python${PYTHON_BASE_VERSION}/site-packages
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
CMD [ "python" ]
COPY --from=packages [ \
"k2-python-${PYTHON_BASE_VERSION}_${PYTHON_VERSION}-*.deb", \
"k2-python-shim-${PYTHON_BASE_VERSION}_*.deb", \
"/tmp/" ]
RUN apt-install /tmp/*.deb ; \
cleanup ; \
# smoke/qa
set -xv ; \
python --version
# ---
FROM ${IMAGE_PATH}/${PYTHON_MIN_IMAGE} as regular
SHELL [ "/bin/sh", "-ec" ]
COPY --from=packages [ \
"k2-python-${PYTHON_BASE_VERSION}-full_${PYTHON_VERSION}-*.deb", \
"k2-python-shim-${PYTHON_BASE_VERSION}-full_*.deb", \
"/tmp/" ]
RUN apt-install /tmp/*.deb ; \
cleanup ; \
# smoke/qa
set -xv ; \
pip --version ; \
wheel version
# ---
FROM ${IMAGE_PATH}/${PYTHON_IMAGE} as dev
SHELL [ "/bin/sh", "-ec" ]
COPY --from=packages [ \
"k2-python-${PYTHON_BASE_VERSION}-dev_${PYTHON_VERSION}-*.deb", \
"k2-python-shim-${PYTHON_BASE_VERSION}-dev_*.deb", \
"/tmp/" ]
RUN apt-install /tmp/*.deb ; \
cleanup
# ---
FROM ${IMAGE_PATH}/${BASE_IMAGE} as minimal-ci
SHELL [ "/bin/sh", "-ec" ]
ENV SITE_PACKAGES=/opt/python-${PYTHON_BASE_VERSION}/lib/python${PYTHON_BASE_VERSION}/site-packages
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
CMD [ "python" ]
RUN apt-install k2-python-shim-${PYTHON_BASE_VERSION} ; \
cleanup ; \
# smoke/qa
set -xv ; \
python --version
# ---
FROM ${IMAGE_PATH}/${PYTHON_MIN_IMAGE} as regular-ci
SHELL [ "/bin/sh", "-ec" ]
RUN apt-install k2-python-shim-${PYTHON_BASE_VERSION}-full ; \
cleanup ; \
# smoke/qa
set -xv ; \
pip --version ; \
wheel version
# ---
FROM ${IMAGE_PATH}/${PYTHON_IMAGE} as dev-ci
SHELL [ "/bin/sh", "-ec" ]
RUN apt-install k2-python-shim-${PYTHON_BASE_VERSION}-dev ; \
cleanup