|
| 1 | +# Build this project from source and write the updated content |
| 2 | +# (i.e. /usr/bin/rpm-ostree and related binaries) to a new derived container |
| 3 | +# image. See the `Justfile` for an example |
| 4 | +# |
| 5 | +# Use e.g. --build-arg=base=quay.io/centos-bootc/centos-bootc:stream10 to target |
| 6 | +# CentOS instead. |
| 7 | + |
| 8 | +ARG base=quay.io/fedora/fedora-bootc:42 |
| 9 | + |
| 10 | +# This first image captures a snapshot of the source code, |
| 11 | +# note all the exclusions in .dockerignore. |
| 12 | +FROM scratch as src |
| 13 | +COPY . /src |
| 14 | + |
| 15 | +# This is basically a no-op now, but we could make any other final tweaks we want |
| 16 | +# here. |
| 17 | +FROM $base as base |
| 18 | + |
| 19 | +# Fetch sccache |
| 20 | +FROM base as sccache |
| 21 | +ARG SCCACHE_VERSION=0.8.2 |
| 22 | +# Install sccache for compiler caching |
| 23 | +RUN <<EORUN |
| 24 | +set -xeuo pipefail |
| 25 | +target=$(arch)-unknown-linux-musl |
| 26 | +v=sccache-v${SCCACHE_VERSION}-${target} |
| 27 | +curl -fSsL "https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/${v}.tar.gz" \ |
| 28 | + | tar xz -C /usr/local/bin --strip-components=1 "${v}/sccache" |
| 29 | +chmod +x /usr/local/bin/sccache |
| 30 | +EORUN |
| 31 | + |
| 32 | +# This image installs build deps, pulls in our source code, and installs updated |
| 33 | +# rpm-ostree binaries in /out. The intention is that the target rootfs is extracted from /out |
| 34 | +# back into a final stage (without the build deps etc) below. |
| 35 | +FROM base as build |
| 36 | +# This installs our package dependencies, and we want to cache it independently of the rest. |
| 37 | +# Basically we don't want changing a .rs file to blow out the cache of packages. So we only |
| 38 | +# copy files necessary for dependency installation. |
| 39 | +COPY packaging /tmp/packaging |
| 40 | +COPY ci/installdeps.sh ci/libbuild.sh /tmp/ci/ |
| 41 | +RUN <<EORUN |
| 42 | +set -xeuo pipefail |
| 43 | +. /usr/lib/os-release |
| 44 | +case $ID in |
| 45 | + centos|rhel) dnf config-manager --set-enabled crb;; |
| 46 | + fedora) dnf -y install dnf-utils 'dnf5-command(builddep)';; |
| 47 | +esac |
| 48 | +# Handle version skew, upgrade core dependencies |
| 49 | +dnf -y distro-sync ostree{,-libs} libmodulemd |
| 50 | +# Install build requirements |
| 51 | +cd /tmp && ./ci/installdeps.sh |
| 52 | +rm /tmp/{packaging,ci} -rf |
| 53 | +EORUN |
| 54 | +COPY --from=sccache /usr/local/bin/* /usr/local/bin/ |
| 55 | +# Now copy the rest of the source |
| 56 | +COPY --from=src /src /src |
| 57 | +WORKDIR /src |
| 58 | +# See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/ |
| 59 | +# We aren't using the full recommendations there, just the simple bits. |
| 60 | +# First step, ensure we have the crates downloaded |
| 61 | +RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome cargo fetch |
| 62 | +# Then this all runs without networking |
| 63 | +RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome --mount=type=cache,target=/var/cache/sccache --network=none <<EORUN |
| 64 | +set -xeuo pipefail |
| 65 | +# Configure sccache for C/C++ and Rust compilation caching |
| 66 | +export SCCACHE_DIR=/var/cache/sccache |
| 67 | +export CC="sccache gcc" |
| 68 | +export CXX="sccache g++" |
| 69 | +export RUSTC_WRAPPER=sccache |
| 70 | +sccache --show-stats || true |
| 71 | +env NOCONFIGURE=1 ./autogen.sh |
| 72 | +./configure --prefix=/usr --libdir=/usr/lib64 --sysconfdir=/etc |
| 73 | +make -j $(nproc) |
| 74 | +make install DESTDIR=/out |
| 75 | +sccache --show-stats |
| 76 | +EORUN |
| 77 | + |
| 78 | +# This just does syntax checking and basic validation |
| 79 | +FROM build as validate |
| 80 | +RUN grep -vEe '^#' ci/packages-build-extra.txt | xargs dnf -y install |
| 81 | +RUN --mount=type=cache,target=/src/target --mount=type=cache,target=/var/roothome --mount=type=cache,target=/var/cache/sccache --network=none <<EORUN |
| 82 | +set -xeuo pipefail |
| 83 | +# Use sccache in validate stage too |
| 84 | +export SCCACHE_DIR=/var/cache/sccache |
| 85 | +export CC="sccache gcc" |
| 86 | +export CXX="sccache g++" |
| 87 | +export RUSTC_WRAPPER=sccache |
| 88 | +# Only gate on correctness and a few specific lints by default |
| 89 | +cargo clippy -- -A clippy::all -D clippy::correctness -D clippy::suspicious -D clippy::disallowed-methods -Dunused_imports -Ddead_code |
| 90 | +# Basic syntax checks |
| 91 | +make check-local |
| 92 | +EORUN |
| 93 | + |
| 94 | +# The final image that derives from the original base and adds the release binaries |
| 95 | +FROM base as final |
| 96 | +# Create a layer that is our new binaries |
| 97 | +COPY --from=build /out/ / |
| 98 | +# Only in this containerfile, inject a file which signifies |
| 99 | +# this comes from this development image. This can be used in |
| 100 | +# tests to know we're doing upstream CI. |
| 101 | +RUN touch /usr/lib/.rpm-ostree-dev-stamp |
| 102 | + |
| 103 | +# Integration test build |
| 104 | +FROM build as integration-build |
| 105 | +RUN <<EORUN |
| 106 | +set -xeuo pipefail |
| 107 | +grep -vEe '^#' ci/packages-build-extra.txt | xargs dnf -y install |
| 108 | +grep -vEe '^#' ci/integration-runtime.txt | xargs dnf -y install |
| 109 | +EORUN |
| 110 | +# Copy test scripts |
| 111 | +COPY ci/test-container.sh /out/usr/bin/rpm-ostree-test-container.sh |
| 112 | +# Copy test data if it exists |
| 113 | +COPY --from=src /src/tests /usr/share/rpm-ostree/tests |
| 114 | +RUN <<EORUN |
| 115 | +set -xeuo pipefail |
| 116 | +make -C tests/kolainst install DESTDIR=/out |
| 117 | +EORUN |
| 118 | + |
| 119 | +FROM final as integration |
| 120 | +COPY ci/ /run/ci/ |
| 121 | +RUN grep -vEe '^#' /run/ci/integration-runtime.txt | xargs dnf -y install |
| 122 | +COPY --from=integration-build /out/ / |
| 123 | +FROM final |
0 commit comments