Improve virtual environment

Virtual environments now re-use names, to prevent accumulation of older
environments when updating versions.
This commit is contained in:
Alex Palaistras 2022-10-13 18:59:57 +01:00
parent de9e2083e4
commit 48abe1c3db
6 changed files with 31 additions and 31 deletions

6
.gitignore vendored
View File

@ -4,9 +4,9 @@
.tmp/ .tmp/
# Ignore custom hosts. # Ignore custom hosts.
host/ host/*
!host/base !host/base/
!host/virtual !host/virtual/
# Ignore files in private directory. # Ignore files in private directory.
private/ private/

View File

@ -1,6 +1,7 @@
# CoreOS options. # CoreOS options.
NAME := coreos-home-server
STREAM := stable STREAM := stable
VERSION := 36.20220820.3.0 VERSION := 36.20220918.3.0
ARCH := x86_64 ARCH := x86_64
IMAGE_URI := https://builds.coreos.fedoraproject.org/prod/streams/ IMAGE_URI := https://builds.coreos.fedoraproject.org/prod/streams/
HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST)) HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST))
@ -8,7 +9,7 @@ HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST))
# Default Makefile options. # Default Makefile options.
VERBOSE := VERBOSE :=
ROOTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) 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. # Target-specific variables.
ADDRESS = $(shell ip -o route get 1 | awk '{for (i=1; i<=NF; i++) {if ($$i == "src") {print $$(i+1); exit}}}') 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. ## 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 deploy-virtual: $(TMPDIR)images/fedora-coreos-$(VERSION)-qemu.$(ARCH).qcow2.xz $(TMPDIR)deploy/host/$(HOST)/spec.ign
@printf "Preparing virtual environment...\n" @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 \ --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" --qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=$(TMPDIR)deploy/host/$(HOST)/spec.ign"
## Stop and remove virtual environment for CoreOS. ## Stop and remove virtual environment for CoreOS.
destroy-virtual: destroy-virtual:
$Q $(VIRSH) destroy fcos-$(STREAM)-$(VERSION)-$(ARCH) || true $Q $(VIRSH) destroy $(NAME) || true
$Q $(VIRSH) undefine --remove-all-storage fcos-$(STREAM)-$(VERSION)-$(ARCH) || true $Q $(VIRSH) undefine --remove-all-storage $(NAME) || true
## Remove deployment configuration files required for build. ## Remove deployment configuration files required for build.
clean: 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, \ @printf "$(foreach i,$^,\n$(patsubst $(ROOTDIR)%.bu,$(TMPDIR)deploy/%.ign, \
$(i)): $(addprefix $(TMPDIR)deploy/, $(shell awk -F '[ ]+local:[ ]*' '/^[ ]+(-[ ]+)?local:/ {print $$2}' $(i))))" >> $@ $(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) .PHONY: deploy deploy-virtual destroy-virtual clean purge help $(CONTAINERFILES)
# Conditional command echo control. # Conditional command echo control.

View File

@ -71,19 +71,24 @@ function sync-systemd-services() {
if test -n "$buffer"; then return 0; else return 1; fi if test -n "$buffer"; then return 0; else return 1; fi
} }
# Synchronize all existing CoreOS home-server configuration. # Entrypoint for script. Process all services present in host configuration against remote state.
for hostdir in "$HOST_CONFIG_PATH"/*; do function main() {
if test ! -d "$hostdir"; then # Synchronize all existing CoreOS home-server configuration.
continue 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 fi
}
printf "Synchronizing host configuration for '%s'... " "$hostdir" main "$@"
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

View File

@ -7,7 +7,6 @@ ConditionPathExists=%E/coreos-home-server/%i/Containerfile
[Service] [Service]
Type=oneshot Type=oneshot
SyslogIdentifier=%N 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 ExecStart=/bin/podman build $PODMAN_BUILD_OPTIONS --file %E/coreos-home-server/%i/Containerfile --tag localhost/%i:latest %E/coreos-home-server/%i
[Install] [Install]

View File

@ -3,7 +3,7 @@ version: 1.3.0
ignition: ignition:
config: config:
merge: merge:
- local: host/base/container.ign - local: host/base/spec.ign
- local: host/base/logging.ign - local: host/base/logging.ign
- local: service/redis/spec.ign - local: service/redis/spec.ign
- local: service/mariadb/spec.ign - local: service/mariadb/spec.ign
@ -133,7 +133,7 @@ systemd:
[Service] [Service]
ExecStartPre=/bin/podman volume create letsencrypt ExecStartPre=/bin/podman volume create letsencrypt
ExecStart= 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 ExecStartPost=/bin/podman volume unmount letsencrypt
storage: storage: