Skip to content

Commit

Permalink
ioc: reorder stages to improve portability.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
henriquesimoes committed Aug 11, 2023
1 parent d9ededc commit 176b8d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
37 changes: 21 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 176b8d6

Please sign in to comment.