From 176b8d6b91b793f6d9700e8f2a45e950d81b9b6a 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 some unused stage fail 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 define only in stages they are used. This is required to support non-BuildKit builds, as they aren't inherited. --- Dockerfile | 37 +++++++++++++++++++++---------------- README.md | 8 ++++---- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index eec85a5..252b4da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,9 @@ -ARG BUILD_STAGE_VERSION=v0.2.0 +ARG BUILD_STAGE_VERSION=latest 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