Nicolas Massé 1 month ago
parent
commit
ab7096daf3
  1. 7
      cookbooks/Makefile
  2. 10
      scripts/common.mk
  3. 38
      scripts/generate-butane-spec.sh

7
cookbooks/Makefile

@ -4,6 +4,7 @@ SUBDIRS := $(dir $(SUBDIRS))
.PHONY: all help package clean dryrun fcos-vm clean-vm uninstall $(SUBDIRS) .PHONY: all help package clean dryrun fcos-vm clean-vm uninstall $(SUBDIRS)
export I_KNOW_WHAT_I_AM_DOING ?= no export I_KNOW_WHAT_I_AM_DOING ?= no
export PACKAGE_TARGET_DIR ?= $(realpath $(PWD)/../build)
all: help all: help
help: help:
@ -18,6 +19,12 @@ help:
dryrun: $(SUBDIRS) dryrun: $(SUBDIRS)
package: $(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) clean: $(SUBDIRS)
fcos-vm: $(SUBDIRS) fcos-vm: $(SUBDIRS)

10
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 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 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_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 &: build/$(PROJECT_NAME).tar.gz build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu &:
@if [ -z "$(TARGET_CHROOT)" ]; then \ @if [ -z "$(TARGET_CHROOT)" ]; then \
echo "TARGET_CHROOT is not set!"; exit 1; \ 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; \ done; \
run make install-config; \ run make install-config; \
YQ_FILES="$$(if [ -f "overlay.bu" ]; then echo "- overlay.bu"; else echo "-"; fi)"; \ YQ_FILES="$$(if [ -f "overlay.bu" ]; then echo "- overlay.bu"; else echo "-"; fi)"; \
echo "generate-butane-spec.sh $(TARGET_CHROOT) > build/$(PROJECT_NAME).bu"; \ echo "generate-butane-spec.sh 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; \ $(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; \ $(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)"; \ (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; \ run make install-examples; \
echo "generate-butane-spec.sh $(TARGET_CHROOT) > build/$(PROJECT_NAME)-examples.bu"; \ echo "generate-butane-spec.sh build/$(PROJECT_NAME)-examples.bu"; \
$(SCRIPTS_DIR)/generate-butane-spec.sh $(TARGET_CHROOT) $(BUTANE_BLOCKLIST) > 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)"; \ (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 fi
.PHONY: build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu .PHONY: build/$(PROJECT_NAME).bu build/$(PROJECT_NAME)-examples.bu

38
scripts/generate-butane-spec.sh

@ -6,24 +6,22 @@
# instance with all necessary quadlets and systemd units to run the # instance with all necessary quadlets and systemd units to run the
# podman-quadlet-cookbook tests. # podman-quadlet-cookbook tests.
# #
# It takes the following parameters: # The tool takes its parameters from the environment variables defined in the Makefile:
# - 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.
# #
# 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 set -Eeuo pipefail
TARGET_CHROOT="$1" OUTPUT="${1:-/dev/stdout}"
IGNORE_LIST_FILE="$2"
SYSTEMD_MAIN_UNIT_NAMES="${@:3}"
cat <<"EOF" cat > "$OUTPUT" <<"EOF"
variant: fcos variant: fcos
version: 1.4.0 version: 1.4.0
storage: storage:
@ -31,12 +29,12 @@ storage:
EOF EOF
for file in $(find "$TARGET_CHROOT" \! -type d); do for file in $(find "$TARGET_CHROOT" \! -type d); do
rel_path="${file#$TARGET_CHROOT}" 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 # Skip files & directories that are already part of the CoreOS default installation
continue continue
fi fi
cat <<EOF cat >> "$OUTPUT" <<EOF
- path: "${rel_path}" - path: "${rel_path}"
mode: 0$(stat -c '%a' "$file") mode: 0$(stat -c '%a' "$file")
user: user:
@ -46,19 +44,19 @@ for file in $(find "$TARGET_CHROOT" \! -type d); do
contents: contents:
inline: | inline: |
EOF EOF
sed 's/^/ /; $s/$/\n/' "$file" sed 's/^/ /; $s/$/\n/' "$file" >> "$OUTPUT"
done done
cat <<"EOF" cat >> "$OUTPUT" <<"EOF"
directories: directories:
EOF EOF
for dir in $(find "$TARGET_CHROOT" -type d); do for dir in $(find "$TARGET_CHROOT" -type d); do
rel_path="${dir#$TARGET_CHROOT}" 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 # Skip files & directories that are already part of the CoreOS default installation
continue continue
fi fi
cat <<EOF cat >> "$OUTPUT" <<EOF
- path: "${rel_path}" - path: "${rel_path}"
mode: 0$(stat -c '%a' "$dir") mode: 0$(stat -c '%a' "$dir")
user: user:
@ -68,12 +66,12 @@ for dir in $(find "$TARGET_CHROOT" -type d); do
EOF EOF
done done
cat <<"EOF" cat >> "$OUTPUT" <<"EOF"
systemd: systemd:
units: units:
EOF EOF
for unit in ${SYSTEMD_MAIN_UNIT_NAMES}; do for unit in ${SYSTEMD_MAIN_UNIT_NAMES}; do
cat <<EOF cat >> "$OUTPUT" <<EOF
- name: "$unit" - name: "$unit"
enabled: true enabled: true
mask: false mask: false

Loading…
Cancel
Save