Skip to content

Commit 875b93c

Browse files
committed
tooling: Use buildkit frontend for building Docker images
The buildkit tooling is part of the standard Docker installation and can be activated by specifying DOCKER_BUILDKIT=1 in the environment. - Buildkit allows us to authenticate in a build temporarily without leaking authentication information in the Docker images. - Buildkit allows us to leverage ccache for all image builds, reducing compilation duration. - Buildkit allows us to mount directories from other Docker images, allowing us to build a VTD package from within the build process without needing to copy the sources into the image at any point. The only downside with the buildkit tooling is that it is not possible to docker exec on intermediate layers.
1 parent 570e05a commit 875b93c

10 files changed

+336
-311
lines changed

dist/docker/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.env
1+
setup.sh

dist/docker/Dockerfile.alpine

-60
This file was deleted.

dist/docker/Dockerfile.archlinux

+44-33
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
1+
# syntax = docker/dockerfile:1.2-labs
12
# Dockerfile.archlinux
23
#
34
# See Dockerfile.focal for documentation of each of the lines.
4-
ARG BUILD_FROM=archlinux:latest
5-
ARG DEPLOY_FROM=${BUILD_FROM}
6-
7-
FROM ${BUILD_FROM} AS build
5+
FROM archlinux:latest
86

97
# Install System Packages
108
COPY Makefile.setup /cloe/Makefile.setup
11-
RUN pacman -Syu --noconfirm --needed make && \
9+
RUN pacman -Syu --noconfirm --needed make ccache && \
1210
make -f /cloe/Makefile.setup \
1311
WITHOUT_DEV_DEPS=yes \
1412
PACMAN_ARGS="--noconfirm --needed" \
1513
install-system-deps \
1614
&& \
17-
locale-gen en_US.UTF-8 && \
15+
locale-gen && \
1816
pacman -Scc --noconfirm
1917

18+
ENV LANG=C.UTF-8
19+
ENV LC_ALL=C.UTF-8
20+
ENV CCACHE_DIR=/ccache
21+
ENV PATH=/usr/lib/ccache:$PATH
22+
2023
RUN pip3 install --upgrade pip && \
2124
make -f /cloe/Makefile.setup \
2225
PIP_INSTALL_ARGS="" \
2326
install-python-deps
2427

2528
# Install and Setup Conan
26-
ARG CONAN_REMOTE=https://conan.bintray.com
27-
ARG CONAN_REMOTE_VERIFY_SSL=true
28-
ARG CONAN_LOGIN_USERNAME
29-
ARG CONAN_PASSWORD
29+
ARG BUILD_TYPE=RelWithDebInfo
3030
RUN conan profile new --detect default && \
31-
conan profile update settings.compiler.libcxx=libstdc++11 default && \
32-
conan config set general.request_timeout=360 && \
33-
conan remote clean && \
34-
conan remote add default ${CONAN_REMOTE} ${CONAN_REMOTE_VERIFY_SSL}
31+
conan profile update settings.build_type=${BUILD_TYPE} default && \
32+
conan profile update settings.compiler.libcxx=libstdc++11 default
33+
34+
ENV CONAN_NON_INTERACTIVE=yes
3535

3636
# Build and Install Cloe
3737
WORKDIR /cloe
38-
COPY . /cloe
3938
ARG WITH_VTD=0
40-
ARG PACKAGE_TARGET=package-select
41-
RUN export CONAN_NON_INTERACTIVE=yes && \
42-
if [ ${CONAN_LOGIN_USERNAME} != "" ]; then \
43-
CONAN_LOGIN_USERNAME="${CONAN_LOGIN_USERNAME}" CONAN_PASSWORD="${CONAN_PASSWORD}" conan user --remote=default -p || exit 1; \
44-
fi && \
45-
make export-vendor export && \
39+
40+
# Download or build dependencies:
41+
COPY vendor /cloe/vendor
42+
COPY Makefile.package /cloe
43+
COPY Makefile.all /cloe
44+
ARG VENDOR_TARGET="export-vendor download-vendor"
45+
RUN --mount=type=cache,target=/ccache \
46+
--mount=type=bind,target=/cloe/vendor/vtd/vires,from=cloe/vtd-sources:2.2.0 \
47+
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
48+
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
49+
make -f Makefile.all WITH_VTD=${WITH_VTD} ${VENDOR_TARGET} && \
50+
# Clean up:
51+
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \
52+
conan remove \* -s -b -f && \
53+
conan user --clean
54+
55+
# Build Cloe.
56+
COPY . /cloe
57+
ARG PACKAGE_TARGET=package-auto
58+
RUN --mount=type=cache,target=/ccache \
59+
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
60+
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
4661
make WITH_VTD=${WITH_VTD} ${PACKAGE_TARGET} && \
47-
conan remove \* -b -f && \
62+
# Clean up:
63+
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \
64+
conan remove \* -s -b -f && \
4865
conan user --clean
4966

50-
ARG VI_LIC_SERVER
51-
RUN export LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 && \
52-
export VI_LIC_SERVER="${VI_LIC_SERVER}" && \
53-
make WITH_VTD=${WITH_VTD} smoketest && \
54-
make WITH_VTD=${WITH_VTD} INSTALL_DIR="/deploy" deploy
55-
56-
# Create Deploy Image
57-
FROM ${DEPLOY_FROM}
58-
COPY --from=build /deploy /usr/local/
59-
ENV LD_LIBRARY_PATH=/usr/local/lib
60-
ENTRYPOINT [ "cloe-engine" ]
67+
# Run smoketests.
68+
RUN --mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
69+
--network=default \
70+
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
71+
make WITH_VTD=${WITH_VTD} smoketest

dist/docker/Dockerfile.bionic

+47-34
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,75 @@
1+
# syntax = docker/dockerfile:1.2-labs
12
# Dockerfile.bionic
23
#
34
# See Dockerfile.focal for documentation of each of the lines.
4-
ARG BUILD_FROM=ubuntu:18.04
5-
ARG DEPLOY_FROM=${BUILD_FROM}
6-
7-
FROM ${BUILD_FROM} AS build
5+
FROM ubuntu:18.04
86

97
# Install System Packages
108
COPY Makefile.setup /cloe/Makefile.setup
11-
RUN apt-get update && \
12-
apt-get install -y make locales && \
9+
RUN --mount=type=cache,id=bionic-cache,target=/var/cache/apt \
10+
--mount=type=cache,id=bionic-lib,target=/var/lib/apt \
11+
apt-get update && \
12+
apt-get install -y make ccache locales libbsd0 && \
1313
make -f /cloe/Makefile.setup \
1414
WITHOUT_DEV_DEPS=yes \
1515
DEBIAN_FRONTEND=noninteractive \
1616
APT_ARGS="--no-install-recommends -y" \
1717
install-system-deps \
1818
&& \
19-
locale-gen en_US.UTF-8 && \
19+
locale-gen && \
2020
rm -rf /var/lib/apt/lists/*
2121

22+
ENV LANG=C.UTF-8
23+
ENV LC_ALL=C.UTF-8
24+
ENV CCACHE_DIR=/ccache
25+
ENV PATH=/usr/lib/ccache:$PATH
26+
2227
RUN pip3 install --upgrade pip && \
2328
make -f /cloe/Makefile.setup \
2429
PIP_INSTALL_ARGS="" \
2530
install-python-deps
2631

2732
# Install and Setup Conan
28-
ARG CONAN_REMOTE=https://conan.bintray.com
29-
ARG CONAN_REMOTE_VERIFY_SSL=true
30-
ARG CONAN_LOGIN_USERNAME
31-
ARG CONAN_PASSWORD
33+
ARG BUILD_TYPE=RelWithDebInfo
3234
RUN conan profile new --detect default && \
33-
conan profile update settings.compiler.libcxx=libstdc++11 default && \
34-
conan config set general.request_timeout=360 && \
35-
conan remote clean && \
36-
conan remote add default ${CONAN_REMOTE} ${CONAN_REMOTE_VERIFY_SSL}
35+
conan profile update settings.build_type=${BUILD_TYPE} default && \
36+
conan profile update settings.compiler.libcxx=libstdc++11 default
37+
38+
ENV CONAN_NON_INTERACTIVE=yes
3739

3840
# Build and Install Cloe
3941
WORKDIR /cloe
40-
COPY . /cloe
4142
ARG WITH_VTD=0
42-
ARG PACKAGE_TARGET=package-select
43-
RUN export CONAN_NON_INTERACTIVE=yes && \
44-
if [ ${CONAN_LOGIN_USERNAME} != "" ]; then \
45-
CONAN_LOGIN_USERNAME="${CONAN_LOGIN_USERNAME}" CONAN_PASSWORD="${CONAN_PASSWORD}" conan user --remote=default -p || exit 1; \
46-
fi && \
47-
make export-vendor export && \
43+
44+
# Download or build dependencies:
45+
COPY vendor /cloe/vendor
46+
COPY Makefile.package /cloe
47+
COPY Makefile.all /cloe
48+
ARG VENDOR_TARGET="export-vendor download-vendor"
49+
RUN --mount=type=cache,target=/ccache \
50+
--mount=type=bind,target=/cloe/vendor/vtd/vires,from=cloe/vtd-sources:2.2.0 \
51+
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
52+
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
53+
make -f Makefile.all WITH_VTD=${WITH_VTD} ${VENDOR_TARGET} && \
54+
# Clean up:
55+
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \
56+
conan remove \* -s -b -f && \
57+
conan user --clean
58+
59+
# Build Cloe.
60+
COPY . /cloe
61+
ARG PACKAGE_TARGET=package-auto
62+
RUN --mount=type=cache,target=/ccache \
63+
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
64+
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
4865
make WITH_VTD=${WITH_VTD} ${PACKAGE_TARGET} && \
49-
conan remove \* -b -f && \
66+
# Clean up:
67+
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \
68+
conan remove \* -s -b -f && \
5069
conan user --clean
5170

52-
ARG VI_LIC_SERVER
53-
RUN export LC_ALL=C.UTF-8 LANG=C.UTF-8 && \
54-
export VI_LIC_SERVER="${VI_LIC_SERVER}" && \
55-
make WITH_VTD=${WITH_VTD} smoketest && \
56-
make WITH_VTD=${WITH_VTD} INSTALL_DIR="/deploy" deploy
57-
58-
# Create Deploy Image
59-
FROM ${DEPLOY_FROM}
60-
COPY --from=build /deploy /usr/local/
61-
ENV LD_LIBRARY_PATH=/usr/local/lib
62-
ENTRYPOINT [ "cloe-engine" ]
71+
# Run smoketests.
72+
RUN --mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
73+
--network=default \
74+
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
75+
make WITH_VTD=${WITH_VTD} smoketest

0 commit comments

Comments
 (0)