|
| 1 | +FROM ubuntu:22.04 as base |
| 2 | + |
| 3 | +### Stage 1 - add/remove packages ### |
| 4 | + |
| 5 | +# Ensure scripts are available for use in next command |
| 6 | +COPY ./container/root/scripts/* /scripts/ |
| 7 | +COPY ./container/root/usr/local/bin/* /usr/local/bin/ |
| 8 | + |
| 9 | +# - Symlink variant-specific scripts to default location |
| 10 | +# - Upgrade base security packages, then clean packaging leftover |
| 11 | +# - Add S6 for zombie reaping, boot-time coordination, signal transformation/distribution: @see https://github.com/just-containers/s6-overlay#known-issues-and-workarounds |
| 12 | +# - Add goss for local, serverspec-like testing |
| 13 | +RUN /bin/bash -e /scripts/ubuntu_apt_config.sh && \ |
| 14 | + /bin/bash -e /scripts/ubuntu_apt_cleanmode.sh && \ |
| 15 | + ln -s /scripts/clean_ubuntu.sh /clean.sh && \ |
| 16 | + ln -s /scripts/security_updates_ubuntu.sh /security_updates.sh && \ |
| 17 | + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \ |
| 18 | + /bin/bash -e /security_updates.sh && \ |
| 19 | + apt-get install -yqq \ |
| 20 | + curl \ |
| 21 | + gpg \ |
| 22 | + apt-transport-https \ |
| 23 | + && \ |
| 24 | + /bin/bash -e /scripts/install_s6.sh && \ |
| 25 | + /bin/bash -e /scripts/install_goss.sh && \ |
| 26 | + apt-get remove --purge -yq \ |
| 27 | + curl \ |
| 28 | + gpg \ |
| 29 | + && \ |
| 30 | + /bin/bash -e /clean.sh |
| 31 | + |
| 32 | +# Overlay the root filesystem from this repo |
| 33 | +COPY ./container/root / |
| 34 | + |
| 35 | + |
| 36 | +### Stage 2 --- collapse layers ### |
| 37 | + |
| 38 | +FROM scratch |
| 39 | +COPY --from=base / . |
| 40 | + |
| 41 | +# Use in multi-phase builds, when an init process requests for the container to gracefully exit, so that it may be committed |
| 42 | +# Used with alternative CMD (worker.sh), leverages supervisor to maintain long-running processes |
| 43 | +ENV SIGNAL_BUILD_STOP=99 \ |
| 44 | + S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \ |
| 45 | + S6_KILL_FINISH_MAXTIME=5000 \ |
| 46 | + S6_KILL_GRACETIME=3000 |
| 47 | + |
| 48 | +RUN goss -g goss.base.yaml validate |
| 49 | + |
| 50 | +# NOTE: intentionally NOT using s6 init as the entrypoint |
| 51 | +# This would prevent container debugging if any of those service crash |
| 52 | +CMD ["/bin/bash", "/run.sh"] |
0 commit comments