Skip to content

Commit a5ecfe5

Browse files
authored
Merge pull request #1358 from cgwalters/buildsys-rework
build-sys: Rework to have toplevel Dockerfile + Justfile
2 parents d05d490 + fc057e6 commit a5ecfe5

File tree

8 files changed

+104
-55
lines changed

8 files changed

+104
-55
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ target
77
docs/
88
# TMT interprets these, not the container build
99
plans/
10-
# Avoid changes to this blowing out all layer caches
10+
# These only affect flow outside of the container
11+
Dockerfile
12+
Justfile
1113
hack/Containerfile

.github/workflows/ci.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ jobs:
5252
echo 'deb [trusted=yes] https://ftp.debian.org/debian/ testing main' | sudo tee /etc/apt/sources.list.d/testing.list
5353
sudo apt update
5454
sudo apt install -y crun/testing podman/testing skopeo/testing
55+
- name: Installdeps
56+
run: sudo apt update && sudo apt install just
5557
- uses: actions/checkout@v4
56-
- name: Build container (fedora)
57-
run: sudo podman build --build-arg=base=quay.io/fedora/fedora-bootc:41 -t localhost/bootc -f hack/Containerfile .
58-
- name: Container integration
59-
run: sudo podman run --rm localhost/bootc bootc-integration-tests container
58+
- name: Build and run container integration tests
59+
run: sudo just run-container-integration
6060
cargo-deny:
6161
runs-on: ubuntu-latest
6262
steps:
@@ -84,15 +84,16 @@ jobs:
8484
- name: Enable fsverity for /
8585
run: sudo tune2fs -O verity $(findmnt -vno SOURCE /)
8686
- name: Install utils
87-
run: sudo apt -y install fsverity
87+
run: sudo apt -y install fsverity just
8888
- name: Integration tests
8989
run: |
9090
set -xeu
9191
# Build images to test; TODO investigate doing single container builds
9292
# via GHA and pushing to a temporary registry to share among workflows?
93-
sudo podman build -t localhost/bootc -f hack/Containerfile .
93+
sudo just build-integration-test-image
9494
sudo podman build -t localhost/bootc-fsverity -f ci/Containerfile.install-fsverity
9595
96+
# TODO move into a container, and then have this tool run other containers
9697
export CARGO_INCREMENTAL=0 # because we aren't caching the test runner bits
9798
cargo build --release -p tests-integration
9899
@@ -104,9 +105,9 @@ jobs:
104105
sudo podman run --privileged --pid=host -v /:/run/host -v $(pwd):/src:ro -v /var/tmp:/var/tmp \
105106
-v /run/dbus:/run/dbus -v /run/systemd:/run/systemd localhost/bootc /src/ostree-ext/ci/priv-integration.sh
106107
# Nondestructive but privileged tests
107-
sudo bootc-integration-tests host-privileged localhost/bootc
108+
sudo bootc-integration-tests host-privileged localhost/bootc-integration
108109
# Install tests
109-
sudo bootc-integration-tests install-alongside localhost/bootc
110+
sudo bootc-integration-tests install-alongside localhost/bootc-integration
110111
111112
# system-reinstall-bootc tests
112113
cargo build --release -p system-reinstall-bootc
@@ -116,7 +117,7 @@ jobs:
116117
117118
sudo install -m 0755 target/release/system-reinstall-bootc /usr/bin/system-reinstall-bootc
118119
# These tests may mutate the system live so we can't run in parallel
119-
sudo bootc-integration-tests system-reinstall localhost/bootc --test-threads=1
120+
sudo bootc-integration-tests system-reinstall localhost/bootc-integration --test-threads=1
120121
121122
# And the fsverity case
122123
sudo podman run --privileged --pid=host localhost/bootc-fsverity bootc install to-existing-root --stateroot=other \

Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Build this project from source and drop the updated content on to
2+
# a bootc container image. By default we use CentOS Stream 9 as a base;
3+
# use e.g. --build-arg=base=quay.io/fedora/fedora-bootc:41 to target
4+
# Fedora instead.
5+
6+
ARG base=quay.io/centos-bootc/centos-bootc:stream9
7+
8+
FROM scratch as src
9+
COPY . /src
10+
11+
# This image installs build deps, pulls in our source code, and installs updated
12+
# bootc binaries in /out. The intention is that the target rootfs is extracted from /out
13+
# back into a final stae (without the build deps etc) below.
14+
FROM $base as build
15+
# This installs our package dependencies, and we want to cache it independently of the rest.
16+
# Basically we don't want changing a .rs file to blow out the cache of packages. So we only
17+
# copy files necessary
18+
COPY contrib/packaging/bootc.spec /tmp/bootc.spec
19+
RUN <<EORUN
20+
set -xeuo pipefail
21+
. /usr/lib/os-release
22+
case $ID in
23+
centos|rhel) dnf config-manager --set-enabled crb;;
24+
fedora) dnf -y install dnf-utils 'dnf5-command(builddep)';;
25+
esac
26+
dnf -y builddep /tmp/bootc.spec
27+
# Extra dependencies
28+
dnf -y install git-core
29+
EORUN
30+
# Now copy the rest of the source
31+
COPY --from=src /src /src
32+
WORKDIR /src
33+
# See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/
34+
# We aren't using the full recommendations there, just the simple bits.
35+
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome \
36+
make && make install-all DESTDIR=/out
37+
38+
# This "build" just runs our unit tests
39+
FROM build as units
40+
ARG unitargs
41+
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome \
42+
cargo test --locked $unitargs
43+
44+
# The final image that derives from the original base and adds the release binaries
45+
FROM $base
46+
# First, create a layer that is our new binaries.
47+
COPY --from=build /out/ /
48+
RUN <<EORUN
49+
set -xeuo pipefail
50+
# Only in this containerfile, inject a file which signifies
51+
# this comes from this development image. This can be used in
52+
# tests to know we're doing upstream CI.
53+
touch /usr/lib/.bootc-dev-stamp
54+
# And test our own linting
55+
bootc container lint --fatal-warnings
56+
EORUN

Justfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Build the container image from current sources
2+
build *ARGS:
3+
podman build --jobs=4 -t localhost/bootc {{ARGS}} .
4+
5+
# This container image has additional testing content and utilities
6+
build-integration-test-image *ARGS: build
7+
podman build --jobs=4 -t localhost/bootc-integration -f hack/Containerfile {{ARGS}} .
8+
9+
# Run container integration tests
10+
run-container-integration: build-integration-test-image
11+
podman run --rm localhost/bootc-integration bootc-integration-tests container
12+
13+
unittest *ARGS:
14+
podman build --jobs=4 --target units -t localhost/bootc-units --build-arg=unitargs={{ARGS}} .

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TAR_REPRODUCIBLE = tar --mtime="@${SOURCE_DATE_EPOCH}" --sort=name --owner=0 --g
66

77
all:
88
cargo build --release
9-
9+
1010
install:
1111
install -D -m 0755 -t $(DESTDIR)$(prefix)/bin target/release/bootc
1212
install -D -m 0755 -t $(DESTDIR)$(prefix)/bin target/release/system-reinstall-bootc

hack/Containerfile

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
1-
# Build bootc from the current git into a c9s-bootc container image.
2-
# Use e.g. --build-arg=base=quay.io/fedora/fedora-bootc:41 to target
3-
# Fedora instead.
4-
#
5-
# You can also generate an image with cloud-init and other dependencies
6-
# with `--build-arg=tmt` which is intended for use particularly via
7-
# https://tmt.readthedocs.io/en/stable/
8-
9-
ARG base=quay.io/centos-bootc/centos-bootc:stream9
1+
# This injects some extra testing stuff into our image
102

113
FROM scratch as context
124
# We only need this stuff in the initial context
135
COPY hack /hack
146
COPY contrib /contrib
157

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
21-
COPY . /build
22-
WORKDIR /build
23-
# See https://www.reddit.com/r/rust/comments/126xeyx/exploring_the_problem_of_faster_cargo_docker/
24-
# We aren't using the full recommendations there, just the simple bits.
25-
RUN --mount=type=cache,target=/build/target --mount=type=cache,target=/var/roothome \
26-
make && make install-all DESTDIR=/out
27-
28-
FROM $base
8+
FROM localhost/bootc
299
# We support e.g. adding cloud-init
3010
ARG variant=
31-
# First, create a layer that is our new binaries.
32-
COPY --from=build /out/ /
3311
# And this layer has additional stuff for testing, such as nushell etc.
3412
RUN --mount=type=bind,from=context,target=/run/context <<EORUN
3513
set -xeuo pipefail
@@ -38,9 +16,6 @@ set -xeuo pipefail
3816
install -D -t /usr/lib/bootc/kargs.d /run/context/hack/test-kargs/*
3917
# Also copy in some default install configs we use for testing
4018
install -D -t /usr/lib/bootc/install/ /run/context/hack/install-test-configs/*
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
4419
# Finally, test our own linting
4520
bootc container lint --fatal-warnings
4621
EORUN

hack/build.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

tmt/tests/bootc-install-provision.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/bash
22
set -exuo pipefail
33

4+
# This script basically builds bootc from source using the provided base image,
5+
# then runs the target tests. We need to do this because at the moment
6+
# packit/tmt/testing-farm effectively only support RPMs, not container images.
7+
# https://issues.redhat.com/browse/TFT-2751
8+
49
BOOTC_TEMPDIR=$(mktemp -d)
510
trap 'rm -rf -- "$BOOTC_TEMPDIR"' EXIT
611

@@ -102,11 +107,22 @@ $(cat "$COMMON_CONTAINERFILE")
102107
REALEOF
103108
else
104109
BOOTC_CI_CONTAINERFILE="${BOOTC_TEMPDIR}/bootc_ci_containerfile"
105-
tee "$BOOTC_CI_CONTAINERFILE" > /dev/null << BOOTCCIEOF
110+
# TODO use the default Dockerfile here instead of a copy of it
111+
tee "$BOOTC_CI_CONTAINERFILE" > /dev/null <<BOOTCCIEOF
106112
FROM $TIER1_IMAGE_URL as build
107113
108114
WORKDIR /code
109-
RUN hack/build.sh
115+
RUN <<EORUN
116+
set -xeuo pipefail
117+
. /usr/lib/os-release
118+
case $ID in
119+
centos|rhel) dnf config-manager --set-enabled crb;;
120+
fedora) dnf -y install dnf-utils 'dnf5-command(builddep)';;
121+
esac
122+
dnf -y builddep contrib/packaging/bootc.spec
123+
# Extra dependencies
124+
dnf -y install git-core
125+
EORUN
110126
111127
RUN mkdir -p /build/target/dev-rootfs
112128
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
@@ -116,17 +132,13 @@ FROM $TIER1_IMAGE_URL
116132
# Inject our built code
117133
COPY --from=build /out/bootc.tar.zst /tmp
118134
RUN tar -C / --zstd -xvf /tmp/bootc.tar.zst && rm -vrf /tmp/*
119-
# Also copy over arbitrary bits from the target root
120-
COPY --from=build /build/target/dev-rootfs/ /
121-
122135
BOOTCCIEOF
123136
cat >"$CONTAINERFILE" <<REALEOF
124137
$(cat "$BOOTC_CI_CONTAINERFILE")
125138
$(cat "$COMMON_CONTAINERFILE")
126139
REALEOF
127140
fi
128141

129-
130142
if [[ -d "/var/ARTIFACTS" ]]; then
131143
# In Testing Farm, TMT work dir /var/ARTIFACTS should be reserved
132144
echo "COPY ARTIFACTS /var/ARTIFACTS" >> "$CONTAINERFILE"

0 commit comments

Comments
 (0)