diff --git a/cookbooks/Makefile b/cookbooks/Makefile index cd75a41..8ab3c6c 100644 --- a/cookbooks/Makefile +++ b/cookbooks/Makefile @@ -4,6 +4,7 @@ SUBDIRS := $(dir $(SUBDIRS)) .PHONY: all help package clean dryrun fcos-vm clean-vm uninstall $(SUBDIRS) export I_KNOW_WHAT_I_AM_DOING ?= no +export PACKAGE_TARGET_DIR ?= $(realpath $(PWD)/../build) all: help help: @@ -18,6 +19,12 @@ help: dryrun: $(SUBDIRS) package: $(SUBDIRS) + @run() { echo $$*; "$$@"; }; \ + for dir in $(SUBDIRS); do \ + dir=$${dir%/}; \ + run cp $$dir/build/$$dir.ign $(PACKAGE_TARGET_DIR)/$$dir.ign; \ + run cp $$dir/build/$$dir.tar.gz $(PACKAGE_TARGET_DIR)/$$dir.tar.gz; \ + done clean: $(SUBDIRS) fcos-vm: $(SUBDIRS) diff --git a/scripts/common.mk b/scripts/common.mk index 8516935..863f9fb 100644 --- a/scripts/common.mk +++ b/scripts/common.mk @@ -364,6 +364,7 @@ build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-exam build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export TARGET_CHROOT := $(TARGET_CHROOT) build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export BUTANE_BLOCKLIST := $(BUTANE_BLOCKLIST) build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export SYSTEMD_MAIN_UNIT_NAMES := $(SYSTEMD_MAIN_UNIT_NAMES) +build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu: export SYSTEMD_TIMER_NAMES := $(SYSTEMD_TIMER_NAMES) build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu &: @if [ -z "$(TARGET_CHROOT)" ]; then \ echo "TARGET_CHROOT is not set!"; exit 1; \ @@ -391,13 +392,14 @@ build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-exam done; \ run make install-config; \ YQ_FILES="$$(if [ -f "overlay.bu" ]; then echo "- overlay.bu"; else echo "-"; fi)"; \ - echo "generate-butane-spec.sh $(TARGET_CHROOT) > build/$(PROJECT_NAME).bu"; \ - $(SCRIPTS_DIR)/generate-butane-spec.sh $(TARGET_CHROOT) $(BUTANE_BLOCKLIST) $(SYSTEMD_MAIN_UNIT_NAMES) $(SYSTEMD_TIMER_NAMES) | yq eval-all '. as $$item ireduce ({}; . *+ $$item)' $$YQ_FILES > build/$(PROJECT_NAME).bu; \ + echo "generate-butane-spec.sh build/$(PROJECT_NAME).bu"; \ + $(SCRIPTS_DIR)/generate-butane-spec.sh | yq eval-all '. as $$item ireduce ({}; . *+ $$item)' $$YQ_FILES > build/$(PROJECT_NAME).bu; \ + echo "generate-tarball.sh build/$(PROJECT_NAME).tar.gz"; \ $(SCRIPTS_DIR)/generate-tarball.sh build/$(PROJECT_NAME).tar.gz; \ (cat $(SCRIPTS_DIR)/butane.blocklist; echo; for file in $$(find "$$TARGET_CHROOT"); do echo "$${file#$$TARGET_CHROOT}"; done) | sort -u | grep -v -E '^$$' > "$(BUTANE_BLOCKLIST)"; \ run make install-examples; \ - echo "generate-butane-spec.sh $(TARGET_CHROOT) > build/$(PROJECT_NAME)-examples.bu"; \ - $(SCRIPTS_DIR)/generate-butane-spec.sh $(TARGET_CHROOT) $(BUTANE_BLOCKLIST) > build/$(PROJECT_NAME)-examples.bu; \ + echo "generate-butane-spec.sh build/$(PROJECT_NAME)-examples.bu"; \ + $(SCRIPTS_DIR)/generate-butane-spec.sh build/$(PROJECT_NAME)-examples.bu; \ (cat $(SCRIPTS_DIR)/butane.blocklist; echo; for file in $$(find "$$TARGET_CHROOT"); do echo "$${file#$$TARGET_CHROOT}"; done) | sort -u | grep -v -E '^$$' > "$(BUTANE_BLOCKLIST)"; \ fi .PHONY: build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu diff --git a/scripts/generate-butane-spec.sh b/scripts/generate-butane-spec.sh index 69f9a1e..c4a7844 100755 --- a/scripts/generate-butane-spec.sh +++ b/scripts/generate-butane-spec.sh @@ -6,24 +6,22 @@ # instance with all necessary quadlets and systemd units to run the # podman-quadlet-cookbook tests. # -# It takes the following parameters: -# - The target chroot directory where the quadlets and systemd units -# have been installed. -# - The path to a file containing a list of files and directories -# (one per line) to ignore (i.e., files and directories that are -# already part of the CoreOS default installation). -# - The list of systemd main unit names to enable. +# The tool takes its parameters from the environment variables defined in the Makefile: # -# It outputs the butane config file to stdout. +# - TARGET_CHROOT: the target chroot directory containing the files to be included in the tarball. +# - BUTANE_BLOCKLIST: the path to a file containing a list of files and directories (one per line) to ignore +# (i.e., files and directories that are already part of the CoreOS default installation +# or belonging to another package). +# - SYSTEMD_MAIN_UNIT_NAMES: the list of systemd main unit names to enable. +# +# The path to of the generated butane file is $1, or stdout if $1 is not provided. # set -Eeuo pipefail -TARGET_CHROOT="$1" -IGNORE_LIST_FILE="$2" -SYSTEMD_MAIN_UNIT_NAMES="${@:3}" +OUTPUT="${1:-/dev/stdout}" -cat <<"EOF" +cat > "$OUTPUT" <<"EOF" variant: fcos version: 1.4.0 storage: @@ -31,12 +29,12 @@ storage: EOF for file in $(find "$TARGET_CHROOT" \! -type d); do rel_path="${file#$TARGET_CHROOT}" - if grep -qxF "$rel_path" "$IGNORE_LIST_FILE"; then + if grep -qxF "$rel_path" "$BUTANE_BLOCKLIST"; then # Skip files & directories that are already part of the CoreOS default installation continue fi - cat <> "$OUTPUT" <> "$OUTPUT" done -cat <<"EOF" +cat >> "$OUTPUT" <<"EOF" directories: EOF for dir in $(find "$TARGET_CHROOT" -type d); do rel_path="${dir#$TARGET_CHROOT}" - if [ -z "$rel_path" ] || grep -qxF "$rel_path" "$IGNORE_LIST_FILE"; then + if [ -z "$rel_path" ] || grep -qxF "$rel_path" "$BUTANE_BLOCKLIST"; then # Skip files & directories that are already part of the CoreOS default installation continue fi - cat <> "$OUTPUT" <> "$OUTPUT" <<"EOF" systemd: units: EOF for unit in ${SYSTEMD_MAIN_UNIT_NAMES}; do -cat <> "$OUTPUT" <