From 48abe1c3db45ba21d3ba7707f59111201ab366e4 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Thu, 13 Oct 2022 18:59:57 +0100 Subject: [PATCH] Improve virtual environment Virtual environments now re-use names, to prevent accumulation of older environments when updating versions. --- .gitignore | 6 ++-- Makefile | 18 +++++------ host/base/service/coreos-home-server-update | 33 ++++++++++++--------- host/base/{container.bu => spec.bu} | 0 host/base/systemd/container-build@.service | 1 - host/virtual/spec.bu | 4 +-- 6 files changed, 31 insertions(+), 31 deletions(-) rename host/base/{container.bu => spec.bu} (100%) diff --git a/.gitignore b/.gitignore index baef430..ffb57a0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,9 @@ .tmp/ # Ignore custom hosts. -host/ -!host/base -!host/virtual +host/* +!host/base/ +!host/virtual/ # Ignore files in private directory. private/ diff --git a/Makefile b/Makefile index 3c962eb..3f5add8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # CoreOS options. +NAME := coreos-home-server STREAM := stable -VERSION := 36.20220820.3.0 +VERSION := 36.20220918.3.0 ARCH := x86_64 IMAGE_URI := https://builds.coreos.fedoraproject.org/prod/streams/ HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST)) @@ -8,7 +9,7 @@ HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST)) # Default Makefile options. VERBOSE := ROOTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) -TMPDIR := $(shell ls -d /var/tmp/fcos-build.???? 2>/dev/null || mktemp -d /var/tmp/fcos-build.XXXX && chmod 0755 /var/tmp/fcos-build.????)/ +TMPDIR := $(shell ls -d /var/tmp/$(NAME).???? 2>/dev/null || mktemp -d /var/tmp/$(NAME).XXXX && chmod 0755 /var/tmp/$(NAME).????)/ # Target-specific variables. ADDRESS = $(shell ip -o route get 1 | awk '{for (i=1; i<=NF; i++) {if ($$i == "src") {print $$(i+1); exit}}}') @@ -31,15 +32,15 @@ deploy: $(TMPDIR)deploy/host/$(HOST)/spec.ign ## Prepares and deploys CoreOS release for local, virtual environment. deploy-virtual: $(TMPDIR)images/fedora-coreos-$(VERSION)-qemu.$(ARCH).qcow2.xz $(TMPDIR)deploy/host/$(HOST)/spec.ign @printf "Preparing virtual environment...\n" - $Q $(VIRTINSTALL) --import --name="fcos-$(STREAM)-$(VERSION)-$(ARCH)" --os-variant=fedora34 \ + $Q $(VIRTINSTALL) --import --name=$(NAME) --os-variant=fedora36 \ --graphics=none --vcpus=2 --memory=2048 --cpu=host --virt-type=kvm \ - --disk="size=10,backing_store=$(TMPDIR)images/fedora-coreos-$(VERSION)-qemu.$(ARCH).qcow2" \ + --disk="size=20,backing_store=$(TMPDIR)images/fedora-coreos-$(VERSION)-qemu.$(ARCH).qcow2" \ --qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=$(TMPDIR)deploy/host/$(HOST)/spec.ign" ## Stop and remove virtual environment for CoreOS. destroy-virtual: - $Q $(VIRSH) destroy fcos-$(STREAM)-$(VERSION)-$(ARCH) || true - $Q $(VIRSH) undefine --remove-all-storage fcos-$(STREAM)-$(VERSION)-$(ARCH) || true + $Q $(VIRSH) destroy $(NAME) || true + $Q $(VIRSH) undefine --remove-all-storage $(NAME) || true ## Remove deployment configuration files required for build. clean: @@ -107,11 +108,6 @@ $(TMPDIR)make.depend: $(shell find $(ROOTDIR) -name '*.bu' -type f 2>/dev/null) @printf "$(foreach i,$^,\n$(patsubst $(ROOTDIR)%.bu,$(TMPDIR)deploy/%.ign, \ $(i)): $(addprefix $(TMPDIR)deploy/, $(shell awk -F '[ ]+local:[ ]*' '/^[ ]+(-[ ]+)?local:/ {print $$2}' $(i))))" >> $@ -# Show help if empty or invalid target has been given. -.DEFAULT: - $Q $(MAKE) -s -f $(firstword $(MAKEFILE_LIST)) help - @printf "Invalid target '$@', stopping.\n"; exit 1 - .PHONY: deploy deploy-virtual destroy-virtual clean purge help $(CONTAINERFILES) # Conditional command echo control. diff --git a/host/base/service/coreos-home-server-update b/host/base/service/coreos-home-server-update index d47038d..9c47425 100755 --- a/host/base/service/coreos-home-server-update +++ b/host/base/service/coreos-home-server-update @@ -71,19 +71,24 @@ function sync-systemd-services() { if test -n "$buffer"; then return 0; else return 1; fi } -# Synchronize all existing CoreOS home-server configuration. -for hostdir in "$HOST_CONFIG_PATH"/*; do - if test ! -d "$hostdir"; then - continue +# Entrypoint for script. Process all services present in host configuration against remote state. +function main() { + # Synchronize all existing CoreOS home-server configuration. + for hostdir in "$HOST_CONFIG_PATH"/*; do + if test ! -d "$hostdir"; then + continue + fi + + printf "Synchronizing host configuration for '%s'... " "$hostdir" + sync-coreos-config "$hostdir" + done + + # Synchronize systemd services from local CoreOS home-server configuration. + printf "Synchronizing systemd service files... " + if sync-systemd-services; then + printf "Reloading systemd daemon after service updates...\n" + systemctl daemon-reload fi +} - printf "Synchronizing host configuration for '%s'... " "$hostdir" - sync-coreos-config "$hostdir" -done - -# Synchronize systemd services from local CoreOS home-server configuration. -printf "Synchronizing systemd service files... " -if sync-systemd-services; then - printf "Reloading systemd daemon after service updates...\n" - systemctl daemon-reload -fi +main "$@" diff --git a/host/base/container.bu b/host/base/spec.bu similarity index 100% rename from host/base/container.bu rename to host/base/spec.bu diff --git a/host/base/systemd/container-build@.service b/host/base/systemd/container-build@.service index 93c7819..98f53a4 100644 --- a/host/base/systemd/container-build@.service +++ b/host/base/systemd/container-build@.service @@ -7,7 +7,6 @@ ConditionPathExists=%E/coreos-home-server/%i/Containerfile [Service] Type=oneshot SyslogIdentifier=%N -Environment=PODMAN_BUILD_OPTIONS= ExecStart=/bin/podman build $PODMAN_BUILD_OPTIONS --file %E/coreos-home-server/%i/Containerfile --tag localhost/%i:latest %E/coreos-home-server/%i [Install] diff --git a/host/virtual/spec.bu b/host/virtual/spec.bu index d05b1cf..4ad8fee 100644 --- a/host/virtual/spec.bu +++ b/host/virtual/spec.bu @@ -3,7 +3,7 @@ version: 1.3.0 ignition: config: merge: - - local: host/base/container.ign + - local: host/base/spec.ign - local: host/base/logging.ign - local: service/redis/spec.ign - local: service/mariadb/spec.ign @@ -133,7 +133,7 @@ systemd: [Service] ExecStartPre=/bin/podman volume create letsencrypt ExecStart= - ExecStart=/bin/sh -c "V=$(podman volume mount letsencrypt) && cp -Rv /etc/ssl/private/certificates $V" + ExecStart=/bin/sh -c "V=$(podman volume mount letsencrypt) && cp -Rv /etc/ssl/private/certificates $V && chown -R 10000:10000 $V" ExecStartPost=/bin/podman volume unmount letsencrypt storage: