|
5 | 5 | # You can also generate an image with cloud-init and other dependencies
|
6 | 6 | # with `--build-arg=tmt` which is intended for use particularly via
|
7 | 7 | # https://tmt.readthedocs.io/en/stable/
|
| 8 | + |
8 | 9 | ARG base=quay.io/centos-bootc/centos-bootc:stream9
|
9 |
| -FROM $base as build |
10 |
| -# Keep this stuff before the `COPY . /build` below to ensure that the packages |
11 |
| -# are cached, i.e. we don't invalidate the package install stage by editing the source. |
| 10 | + |
| 11 | +FROM scratch as context |
| 12 | +# We only need this stuff in the initial context |
| 13 | +COPY hack /hack |
12 | 14 | COPY contrib /contrib
|
13 |
| -COPY hack/build.sh /build.sh |
14 |
| -RUN /build.sh && rm -v /build.sh |
| 15 | + |
| 16 | +FROM $base as build |
| 17 | +# This installs our package dependencies, and we want to cache it independently of the rest. |
| 18 | +# Basically we don't want changing a .rs file to blow out the cache of packages. |
| 19 | +RUN --mount=type=bind,from=context,target=/run/context /run/context/hack/build.sh |
| 20 | +# Now copy the rest of the source |
15 | 21 | COPY . /build
|
16 | 22 | WORKDIR /build
|
17 |
| -RUN mkdir -p /build/target/dev-rootfs # This can hold arbitrary extra content |
18 | 23 | # See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/
|
19 | 24 | # We aren't using the full recommendations there, just the simple bits.
|
20 |
| -RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome make test-bin-archive && mkdir -p /out && cp target/bootc.tar.zst /out |
| 25 | +RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome \ |
| 26 | + make && make install-all DESTDIR=/out |
21 | 27 |
|
22 | 28 | FROM $base
|
23 | 29 | # We support e.g. adding cloud-init
|
24 | 30 | ARG variant=
|
25 |
| -COPY hack/provision-derived.sh /tmp |
26 |
| -RUN /tmp/provision-derived.sh "$variant" && rm -f /tmp/*.sh |
| 31 | +# First, create a layer that is our new binaries. |
| 32 | +COPY --from=build /out/ / |
| 33 | +# And this layer has additional stuff for testing, such as nushell etc. |
| 34 | +RUN --mount=type=bind,from=context,target=/run/context <<EORUN |
| 35 | +set -xeuo pipefail |
| 36 | +/run/context/hack/provision-derived.sh "$variant" |
| 37 | +# Add some testing kargs into our dev builds |
| 38 | +cp -a /run/context/hack/test-kargs /usr/lib/bootc/kargs.d/ |
27 | 39 | # Also copy in some default install configs we use for testing
|
28 |
| -COPY hack/install-test-configs/* /usr/lib/bootc/install/ |
29 |
| -# And some test kargs |
30 |
| -COPY hack/test-kargs /usr/lib/bootc/kargs.d/ |
31 |
| -# Inject our built code |
32 |
| -COPY --from=build /out/bootc.tar.zst /tmp |
33 |
| -RUN tar -C / --zstd -xvf /tmp/bootc.tar.zst && rm -vrf /tmp/* |
34 |
| -# Also copy over arbitrary bits from the target root |
35 |
| -COPY --from=build /build/target/dev-rootfs/ / |
36 |
| -# Test our own linting |
37 |
| -RUN bootc container lint --fatal-warnings |
| 40 | +cp -a /run/context/hack/install-test-configs/* /usr/lib/bootc/install/ |
| 41 | +# Finally only in this containerfile, inject a file which signifies |
| 42 | +# this comes from this development image. |
| 43 | +touch /usr/lib/.bootc-dev-stamp |
| 44 | +# Finally, test our own linting |
| 45 | +bootc container lint --fatal-warnings |
| 46 | +EORUN |
0 commit comments