From 4559e780a48451ba0adcce7a5fa47ac7ece77260 Mon Sep 17 00:00:00 2001 From: "Henrique F. Simoes" Date: Fri, 11 Aug 2023 15:48:04 -0300 Subject: [PATCH] ioc: reorder stages to improve portability. Docker without BuildKit and Podman fail when an unused stage fails before the defined target. As static build stage from the IOC image is known to possibly fail, we now define all static build stages last. Arguments have now been defined only in stages they are used. This is required to support non-BuildKit builds, as they aren't inherited. --- Dockerfile | 35 ++++++++++++++++++++--------------- README.md | 8 ++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Dockerfile b/Dockerfile index eec85a5..59b571f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,7 @@ ARG DEBIAN_VERSION=11.7 FROM ghcr.io/cnpem/lnls-debian-11-epics-7:${BUILD_STAGE_VERSION} AS build-stage -ARG JOBS=1 ARG REPONAME -ARG RUNDIR ARG BUILD_PACKAGES RUN if [ -n "$BUILD_PACKAGES" ]; then apt update && apt install $BUILD_PACKAGES; fi @@ -17,21 +15,8 @@ COPY . . RUN cp /opt/epics/RELEASE configure/RELEASE -FROM build-stage AS static-build - -RUN echo STATIC_BUILD=YES >> configure/CONFIG_SITE.local - -RUN make distclean && make -j ${JOBS} && make clean && make -C ${RUNDIR} - - -FROM build-stage AS dynamic-build - -RUN make distclean && make -j ${JOBS} && make clean && make -C ${RUNDIR} - - FROM debian:${DEBIAN_VERSION}-slim as base -ARG REPONAME ARG RUNDIR ARG ENTRYPOINT=/bin/bash ARG RUNTIME_PACKAGES @@ -53,11 +38,31 @@ RUN ln -s ${ENTRYPOINT} ./entrypoint ENTRYPOINT ["./entrypoint"] +FROM build-stage AS dynamic-build + +ARG JOBS=1 +ARG RUNDIR + +RUN make distclean && make -j ${JOBS} && make clean && make -C ${RUNDIR} + + FROM base AS dynamic-link COPY --from=dynamic-build /opt /opt +FROM build-stage AS static-build + +ARG JOBS=1 +ARG RUNDIR + +RUN echo STATIC_BUILD=YES >> configure/CONFIG_SITE.local + +RUN make distclean && make -j ${JOBS} && make clean && make -C ${RUNDIR} + + FROM base AS static-link +ARG REPONAME + COPY --from=static-build /opt/${REPONAME} /opt/${REPONAME} diff --git a/README.md b/README.md index 0564f5d..9410751 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,10 @@ you **need** to link them dynamically, you must define the build target as dependencies will also be copied. Some Docker versions don't use -[BuildKit](https://docs.docker.com/build/buildkit/) by default, and it is -necessary to enable it, for instance, by exporting `DOCKER_BUILDKIT=1` when -building the IOC image, because the classic builder goes through all stages -even when they are not needed or are known to fail. +[BuildKit](https://docs.docker.com/build/buildkit/) by default, and it can be +more efficient to enable it, for instance, by exporting `DOCKER_BUILDKIT=1` +when building the IOC image, because the classic builder goes through all +stages even when they are not needed. Additional build and runtime packages to be installed can be listed in `args`, under the `BUILD_PACKAGES` and `RUNTIME_PACKAGES` keys, respectively. It is not