1
0
mirror of https://github.com/containers/bootc.git synced 2026-02-05 06:45:13 +01:00
Files
bootc/Makefile

131 lines
6.2 KiB
Makefile
Raw Normal View History

# Understanding Makefile vs Justfile:
#
# This file should primarily *only* involve
# invoking tools which *do not* have side effects outside
# of the current working directory. In particular, this file MUST NOT:
# - Spawn podman or virtualization tools
# - Invoke `sudo`
#
# Stated positively, the code invoked from here is only expected to
# operate as part of "a build" that results in a bootc binary
# plus data files. The two key operations are `make`
# and `make install`. As this is Rust, the generated binaries are in
# the current directory under `target/` by default. Some rules may place
# other generated files there.
#
# We expect code run from here is (or can be) inside a container with low
# privileges - running as a nonzero UID even.
#
# Understanding Makefile vs xtask.rs: Basically use xtask.rs if what
# you're doing would turn into a mess of bash code, whether inline here
# or externally in e.g. ./ci/somebashmess.sh etc.
#
# In particular, the Justfile contains rules for things like integration
# tests which might spawn VMs, etc.
prefix ?= /usr
# Enable rhsm if we detect the build environment is RHEL-like.
# We may in the future also want to include Fedora+derivatives as
# the code is really tiny.
# (Note we should also make installation of the units conditional on the rhsm feature)
CARGO_FEATURES_DEFAULT ?= $(shell . /usr/lib/os-release; if echo "$$ID_LIKE" |grep -qF rhel; then echo rhsm; fi)
# You can set this to override all cargo features, including the defaults
CARGO_FEATURES ?= $(CARGO_FEATURES_DEFAULT)
# Build all binaries
.PHONY: bin
bin: manpages
cargo build --release --features "$(CARGO_FEATURES)" --bins
# Note this cargo build is run without features (such as rhsm)
.PHONY: manpages
manpages:
cargo run --release --package xtask -- manpages
STORAGE_RELATIVE_PATH ?= $(shell realpath -m -s --relative-to="$(prefix)/lib/bootc/storage" /sysroot/ostree/bootc/storage)
install:
install -D -m 0755 -t $(DESTDIR)$(prefix)/bin target/release/bootc
cli: add `system-reinstall-bootc` binary # Background The current usage instructions for bootc involve a long podman invocation. # Issue It's hard to remember and type the long podman invocation, making the usage of bootc difficult for users. See https://issues.redhat.com/browse/BIFROST-610 and https://issues.redhat.com/browse/BIFROST-611 (Epic https://issues.redhat.com/browse/BIFROST-594) # Solution We want to make the usage of bootc easier by providing a new Fedora/RHEL subpackage that includes a new binary `system-reinstall-bootc`. This binary will simplify the usage of bootc by providing a simple command line interface (configured either through CLI flags or a configuration file) with an interactive prompt that allows users to reinstall the current system using bootc. The commandline will handle helping the user choose SSH keys / users, warn the user about the destructive nature of the operation, and eventually report issues they might run into in the various clouds (e.g. missing cloud agent on the target image) # Implementation Added new system-reinstall-bootc crate that outputs the new system-reinstall-bootc binary. This new crate depends on the existing utils crate. Refactored the tracing initialization from the bootc binary into the utils crate so that it can be reused by the new crate. The new CLI can either be configured through commandline flags or through a configuration file in a path set by the environment variable `BOOTC_REINSTALL_CONFIG`. The configuration file is a YAML file. # Limitations Only root SSH keys are supported. The multi user selection TUI is implemented, but if you choose anything other than root you will get an error. # TODO Missing docs, missing functionality. Everything is in alpha stage. User choice / SSH keys / prompt disabling should also eventually be supported to be configured through commandline arguments or the configuration file. Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
2025-01-25 14:20:22 +01:00
install -D -m 0755 -t $(DESTDIR)$(prefix)/bin target/release/system-reinstall-bootc
install -d -m 0755 $(DESTDIR)$(prefix)/lib/bootc/bound-images.d
install -d -m 0755 $(DESTDIR)$(prefix)/lib/bootc/kargs.d
ln -s "$(STORAGE_RELATIVE_PATH)" "$(DESTDIR)$(prefix)/lib/bootc/storage"
install -D -m 0755 crates/cli/bootc-generator-stub $(DESTDIR)$(prefix)/lib/systemd/system-generators/bootc-systemd-generator
install -d $(DESTDIR)$(prefix)/lib/bootc/install
install -D -m 0644 -t $(DESTDIR)$(prefix)/share/man/man5 target/man/*.5; \
install -D -m 0644 -t $(DESTDIR)$(prefix)/share/man/man8 target/man/*.8; \
install -D -m 0644 -t $(DESTDIR)/$(prefix)/lib/systemd/system systemd/*.service systemd/*.timer systemd/*.path systemd/*.target
install -D -m 0644 -t $(DESTDIR)/$(prefix)/share/doc/bootc/baseimage/base/usr/lib/ostree/ baseimage/base/usr/lib/ostree/prepare-root.conf
install -d -m 755 $(DESTDIR)/$(prefix)/share/doc/bootc/baseimage/base/sysroot
cp -PfT baseimage/base/ostree $(DESTDIR)/$(prefix)/share/doc/bootc/baseimage/base/ostree
# Ensure we've cleaned out any possibly older files
rm -vrf $(DESTDIR)$(prefix)/share/doc/bootc/baseimage/dracut
rm -vrf $(DESTDIR)$(prefix)/share/doc/bootc/baseimage/systemd
# Copy dracut and systemd config files
cp -Prf baseimage/dracut $(DESTDIR)$(prefix)/share/doc/bootc/baseimage/dracut
cp -Prf baseimage/systemd $(DESTDIR)$(prefix)/share/doc/bootc/baseimage/systemd
# Install fedora-bootc-destructive-cleanup in fedora derivatives
ID=$$(. /usr/lib/os-release && echo $$ID); \
ID_LIKE=$$(. /usr/lib/os-release && echo $$ID_LIKE); \
if [ "$$ID" = "fedora" ] || [[ "$$ID_LIKE" == *"fedora"* ]]; then \
install -D -m 0755 -t $(DESTDIR)/$(prefix)/lib/bootc contrib/scripts/fedora-bootc-destructive-cleanup; \
fi
install -D -m 0644 -t $(DESTDIR)/usr/lib/systemd/system crates/initramfs/*.service
install -D -m 0755 target/release/bootc-initramfs-setup $(DESTDIR)/usr/lib/bootc/initramfs-setup
install -D -m 0755 -t $(DESTDIR)/usr/lib/dracut/modules.d/51bootc crates/initramfs/dracut/module-setup.sh
# Run this to also take over the functionality of `ostree container` for example.
# Only needed for OS/distros that have callers invoking `ostree container` and not bootc.
install-ostree-hooks:
install -d $(DESTDIR)$(prefix)/libexec/libostree/ext
for x in ostree-container ostree-ima-sign ostree-provisional-repair; do \
ln -sf ../../../bin/bootc $(DESTDIR)$(prefix)/libexec/libostree/ext/$$x; \
done
# Install the main binary, the ostree hooks, and the integration test suite.
install-all: install install-ostree-hooks
install -D -m 0755 target/release/tests-integration $(DESTDIR)$(prefix)/bin/bootc-integration-tests
build-unit-tests:
cargo t --no-run
# We separate the build of the unit tests from actually running them in some cases
install-unit-tests: build-unit-tests
cargo t --no-run --frozen
install -D -m 0755 -t $(DESTDIR)/usr/lib/bootc/units/ $$(cargo t --no-run --message-format=json | jq -r 'select(.profile.test == true and .executable != null) | .executable')
install -d -m 0755 /usr/bin/
echo -e '#!/bin/bash\nset -xeuo pipefail\nfor f in /usr/lib/bootc/units/*; do echo $$f && $$f; done' > $(DESTDIR)/usr/bin/bootc-units && chmod a+x $(DESTDIR)/usr/bin/bootc-units
test-bin-archive: all
$(MAKE) install-all DESTDIR=tmp-install && $(TAR_REPRODUCIBLE) --zstd -C tmp-install -cf target/bootc.tar.zst . && rm tmp-install -rf
build: Tweak `make validate-rust` This took me some thinking and experimenting. Basically we want: - Hard deny some warnings (this is covered by the Cargo.toml workspace.lints.rust) - Gate merging to main in CI on an exact set of warnings we want to forbid, but *without* also using a blanket -Dwarning deny policy because that could break our build when the compiler revs. - A corollary to the previous: allow developing locally without killing the build just because you have an unused import or some dead code (for example). So we don't want to add `dead_code = deny` into the Cargo.toml. - Be able to easily reproduce locally what CI is gating on in an efficient way. We already had `make validate-rust` which was intending to navigate this, but what was missing was the "deny extended set of warnings" so we got code committed to git main which hit `unused_imports`. Clippy upstream docs recommend the `RUSTFLAGS = -Dwarnings` approach in e.g. https://doc.rust-lang.org/clippy/continuous_integration/github_actions.html but again I think this is a problem because it can break with updated Rust/clippy versions (unless you pin on those, but that becomes a pain in and of itself). The problem also with doing `RUSTFLAGS = -Dwarnings` *locally* is it blows out the cargo cache. So here's the solution I came to: We run `cargo clippy -A clippy:all`, and then deny some specific clippy lints *and* the core Rust warnings we want (`unused_imports` type things) at this stage. The advantage is this doesn't blow out the main Cargo cache, and I can easily reproduce locally exactly what CI would gate on. Also while we're here, add `make fix-rust` which is a handy way to use the existing `clippy --fix` to locally fix things like unused imports as well as other machine-applicable things that are in e.g. `clippy::suspicious`. Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-01 12:51:56 -05:00
# This gates CI by default. Note that for clippy, we gate on
# only the clippy correctness and suspicious lints, plus a select
# set of default rustc warnings.
# We intentionally don't gate on this for local builds in cargo.toml
# because it impedes iteration speed.
CLIPPY_CONFIG = -A clippy::all -D clippy::correctness -D clippy::suspicious -D clippy::disallowed-methods -Dunused_imports -Ddead_code
validate:
cargo fmt -- --check -l
cargo test --no-run
(cd crates/ostree-ext && cargo check --no-default-features)
(cd crates/lib && cargo check --no-default-features)
build: Tweak `make validate-rust` This took me some thinking and experimenting. Basically we want: - Hard deny some warnings (this is covered by the Cargo.toml workspace.lints.rust) - Gate merging to main in CI on an exact set of warnings we want to forbid, but *without* also using a blanket -Dwarning deny policy because that could break our build when the compiler revs. - A corollary to the previous: allow developing locally without killing the build just because you have an unused import or some dead code (for example). So we don't want to add `dead_code = deny` into the Cargo.toml. - Be able to easily reproduce locally what CI is gating on in an efficient way. We already had `make validate-rust` which was intending to navigate this, but what was missing was the "deny extended set of warnings" so we got code committed to git main which hit `unused_imports`. Clippy upstream docs recommend the `RUSTFLAGS = -Dwarnings` approach in e.g. https://doc.rust-lang.org/clippy/continuous_integration/github_actions.html but again I think this is a problem because it can break with updated Rust/clippy versions (unless you pin on those, but that becomes a pain in and of itself). The problem also with doing `RUSTFLAGS = -Dwarnings` *locally* is it blows out the cargo cache. So here's the solution I came to: We run `cargo clippy -A clippy:all`, and then deny some specific clippy lints *and* the core Rust warnings we want (`unused_imports` type things) at this stage. The advantage is this doesn't blow out the main Cargo cache, and I can easily reproduce locally exactly what CI would gate on. Also while we're here, add `make fix-rust` which is a handy way to use the existing `clippy --fix` to locally fix things like unused imports as well as other machine-applicable things that are in e.g. `clippy::suspicious`. Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-01 12:51:56 -05:00
cargo clippy -- $(CLIPPY_CONFIG)
env RUSTDOCFLAGS='-D warnings' cargo doc --lib
.PHONY: validate
build: Tweak `make validate-rust` This took me some thinking and experimenting. Basically we want: - Hard deny some warnings (this is covered by the Cargo.toml workspace.lints.rust) - Gate merging to main in CI on an exact set of warnings we want to forbid, but *without* also using a blanket -Dwarning deny policy because that could break our build when the compiler revs. - A corollary to the previous: allow developing locally without killing the build just because you have an unused import or some dead code (for example). So we don't want to add `dead_code = deny` into the Cargo.toml. - Be able to easily reproduce locally what CI is gating on in an efficient way. We already had `make validate-rust` which was intending to navigate this, but what was missing was the "deny extended set of warnings" so we got code committed to git main which hit `unused_imports`. Clippy upstream docs recommend the `RUSTFLAGS = -Dwarnings` approach in e.g. https://doc.rust-lang.org/clippy/continuous_integration/github_actions.html but again I think this is a problem because it can break with updated Rust/clippy versions (unless you pin on those, but that becomes a pain in and of itself). The problem also with doing `RUSTFLAGS = -Dwarnings` *locally* is it blows out the cargo cache. So here's the solution I came to: We run `cargo clippy -A clippy:all`, and then deny some specific clippy lints *and* the core Rust warnings we want (`unused_imports` type things) at this stage. The advantage is this doesn't blow out the main Cargo cache, and I can easily reproduce locally exactly what CI would gate on. Also while we're here, add `make fix-rust` which is a handy way to use the existing `clippy --fix` to locally fix things like unused imports as well as other machine-applicable things that are in e.g. `clippy::suspicious`. Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-01 12:51:56 -05:00
fix-rust:
cargo clippy --fix --allow-dirty -- $(CLIPPY_CONFIG)
.PHONY: fix-rust
update-generated:
cargo xtask update-generated
.PHONY: update-generated
vendor:
cargo xtask $@
.PHONY: vendor
package-rpm:
cargo xtask $@
.PHONY: package-rpm