2021-01-13 16:36:50 +00:00
|
|
|
# CoreOS options.
|
2022-10-13 17:59:57 +00:00
|
|
|
NAME := coreos-home-server
|
2021-01-13 16:36:50 +00:00
|
|
|
STREAM := stable
|
2022-10-13 17:59:57 +00:00
|
|
|
VERSION := 36.20220918.3.0
|
2021-01-13 16:36:50 +00:00
|
|
|
ARCH := x86_64
|
|
|
|
IMAGE_URI := https://builds.coreos.fedoraproject.org/prod/streams/
|
|
|
|
HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST))
|
|
|
|
|
|
|
|
# Default Makefile options.
|
|
|
|
VERBOSE :=
|
|
|
|
ROOTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
|
2022-10-13 17:59:57 +00:00
|
|
|
TMPDIR := $(shell ls -d /var/tmp/$(NAME).???? 2>/dev/null || mktemp -d /var/tmp/$(NAME).XXXX && chmod 0755 /var/tmp/$(NAME).????)/
|
2022-08-26 14:10:02 +00:00
|
|
|
|
|
|
|
# Target-specific variables.
|
|
|
|
ADDRESS = $(shell ip -o route get 1 | awk '{for (i=1; i<=NF; i++) {if ($$i == "src") {print $$(i+1); exit}}}')
|
|
|
|
CONTAINERFILES = $(wildcard service/*/Containerfile)
|
2021-01-13 16:36:50 +00:00
|
|
|
|
|
|
|
# Build-time dependencies.
|
2021-05-09 12:05:34 +00:00
|
|
|
BUTANE ?= $(call find-cmd,butane)
|
2022-08-26 14:10:02 +00:00
|
|
|
PODMAN ?= $(call find-cmd,podman)
|
2021-07-24 13:52:31 +00:00
|
|
|
CURL ?= $(call find-cmd,curl) $(if $(VERBOSE),,--progress-bar) --fail
|
2021-01-13 16:36:50 +00:00
|
|
|
GPG ?= $(call find-cmd,gpg) $(if $(VERBOSE),,-q)
|
|
|
|
VIRSH ?= $(call find-cmd,virsh) --connect=qemu:///system $(if $(VERBOSE),,-q)
|
|
|
|
VIRTINSTALL ?= $(call find-cmd,virt-install) --connect=qemu:///system
|
|
|
|
NC ?= $(call find-cmd,nc) -vv -r -l
|
|
|
|
|
2021-08-14 22:47:54 +00:00
|
|
|
## Builds and deploys Fedora CoreOS for HOST on ADDRESS.
|
2022-01-15 11:43:33 +00:00
|
|
|
deploy: $(TMPDIR)deploy/host/$(HOST)/spec.ign
|
2021-01-13 16:36:50 +00:00
|
|
|
@printf "Serving Ignition config '$<' over HTTP...\n"
|
2021-08-15 19:26:41 +00:00
|
|
|
@printf 'HTTP/1.0 200 OK\r\nContent-Length: %d\r\n\r\n%s\n' "$$(wc -c < $<)" "$$(cat $<)" | $(NC) -s $(ADDRESS) || exit 0
|
2021-01-13 16:36:50 +00:00
|
|
|
|
|
|
|
## Prepares and deploys CoreOS release for local, virtual environment.
|
2022-01-15 11:43:33 +00:00
|
|
|
deploy-virtual: $(TMPDIR)images/fedora-coreos-$(VERSION)-qemu.$(ARCH).qcow2.xz $(TMPDIR)deploy/host/$(HOST)/spec.ign
|
2021-01-13 16:36:50 +00:00
|
|
|
@printf "Preparing virtual environment...\n"
|
2022-10-13 17:59:57 +00:00
|
|
|
$Q $(VIRTINSTALL) --import --name=$(NAME) --os-variant=fedora36 \
|
2022-08-26 14:10:02 +00:00
|
|
|
--graphics=none --vcpus=2 --memory=2048 --cpu=host --virt-type=kvm \
|
2022-10-13 17:59:57 +00:00
|
|
|
--disk="size=20,backing_store=$(TMPDIR)images/fedora-coreos-$(VERSION)-qemu.$(ARCH).qcow2" \
|
2022-01-15 11:43:33 +00:00
|
|
|
--qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=$(TMPDIR)deploy/host/$(HOST)/spec.ign"
|
2021-01-13 16:36:50 +00:00
|
|
|
|
|
|
|
## Stop and remove virtual environment for CoreOS.
|
|
|
|
destroy-virtual:
|
2022-10-13 17:59:57 +00:00
|
|
|
$Q $(VIRSH) destroy $(NAME) || true
|
|
|
|
$Q $(VIRSH) undefine --remove-all-storage $(NAME) || true
|
2021-01-13 16:36:50 +00:00
|
|
|
|
2022-01-15 11:43:33 +00:00
|
|
|
## Remove deployment configuration files required for build.
|
2021-01-13 16:36:50 +00:00
|
|
|
clean:
|
2022-01-15 11:43:33 +00:00
|
|
|
@printf "Removing deployment configuration files...\n"
|
|
|
|
$Q rm -Rf $(TMPDIR)deploy
|
2021-06-27 17:36:15 +00:00
|
|
|
|
|
|
|
## Remove all temporary files required for build.
|
|
|
|
purge:
|
|
|
|
@printf "Cleaning all temporary files...\n"
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q rm -Rf $(TMPDIR)
|
|
|
|
|
|
|
|
## Show usage information for this Makefile.
|
|
|
|
help:
|
|
|
|
@printf "$(BOLD)$(UNDERLINE)CoreOS Home-Server Setup$(RESET)\n\n"
|
|
|
|
@printf "This Makefile contains tasks for processing auxiliary actions, such as\n"
|
|
|
|
@printf "building binaries, packages, or running tests against the test suite.\n\n"
|
|
|
|
@printf "$(UNDERLINE)Available Tasks$(RESET)\n\n"
|
|
|
|
@awk -F ':|##' '/^##/ {c=$$2; getline; printf "$(BLUE)%16s$(RESET)%s\n", $$1, c}' $(MAKEFILE_LIST)
|
|
|
|
@printf "\n"
|
|
|
|
|
2022-08-26 14:10:02 +00:00
|
|
|
# Build container file locally using 'podman build'.
|
|
|
|
$(CONTAINERFILES):
|
|
|
|
@printf "Building container for '$(notdir $(@D))'...\n"
|
|
|
|
$Q cd "$(abspath $(@D))" && $(PODMAN) build .
|
|
|
|
|
2021-01-13 16:36:50 +00:00
|
|
|
# Copy host configuration in plain-text. Mainly used for development hosts.
|
2022-01-15 11:43:33 +00:00
|
|
|
$(TMPDIR)deploy/$(HOST).env: $(ROOTDIR)host/$(HOST)/$(HOST).env
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q install -d $(@D)
|
|
|
|
$Q cp -f $< $@
|
|
|
|
|
|
|
|
# Copy encrypted host configuration. Used in production hosts.
|
2022-01-15 11:43:33 +00:00
|
|
|
$(TMPDIR)deploy/$(HOST).env.gpg: $(ROOTDIR)host/$(HOST)/$(HOST).env.gpg
|
2021-08-14 22:47:54 +00:00
|
|
|
@printf "Waiting to decrypt configuration for '$(HOST)'...\n"
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q install -d $(@D)
|
|
|
|
$Q $(GPG) -o $@ --decrypt $<
|
|
|
|
|
|
|
|
# Copy directory tree if any of the files within are newer than the target directory.
|
2022-01-15 11:43:33 +00:00
|
|
|
$(TMPDIR)deploy/%/: $(shell find $(ROOTDIR)$* -type f -newer $(TMPDIR)deploy/$* 2>/dev/null)
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q install -d $(dir $(@D))
|
2022-01-15 11:43:33 +00:00
|
|
|
$Q cp -Ru $(if $(VERBOSE),-v) $(ROOTDIR)$* $(dir $(@D))
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q touch $(@D)
|
|
|
|
|
|
|
|
# Copy specific file if source file is newer.
|
2022-01-15 11:43:33 +00:00
|
|
|
$(TMPDIR)deploy/%: $(ROOTDIR)%
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q install $(if $(VERBOSE),-v) -D $< $@
|
|
|
|
|
2021-05-09 12:05:34 +00:00
|
|
|
# Compile Ignition file from Butane configuration file.
|
2022-01-15 11:43:33 +00:00
|
|
|
$(TMPDIR)deploy/%.ign: $(ROOTDIR)%.bu
|
2021-01-13 16:36:50 +00:00
|
|
|
$Q install -d $(@D)
|
2022-01-15 11:43:33 +00:00
|
|
|
$Q $(BUTANE) --pretty --strict --files-dir $(TMPDIR)deploy -o $@ $<
|
2021-01-13 16:36:50 +00:00
|
|
|
|
|
|
|
# Download and, optionally, extract Fedora CoreOS installation image.
|
|
|
|
$(TMPDIR)images/fedora-coreos-$(VERSION)-%:
|
|
|
|
@printf "Downloading image file '$(@F)'...\n"
|
|
|
|
$Q install -d $(TMPDIR)images
|
|
|
|
$Q $(CURL) -o $@ $(IMAGE_URI)$(STREAM)/builds/$(VERSION)/$(ARCH)/$(@F)
|
|
|
|
$Q $(CURL) -o $@.sig $(IMAGE_URI)$(STREAM)/builds/$(VERSION)/$(ARCH)/$(@F).sig
|
|
|
|
$Q $(GPG) --verify $@.sig
|
|
|
|
$Q test $(suffix $(@F)) = .xz && xz --decompress $@ || true
|
|
|
|
$Q touch $@
|
|
|
|
|
2021-05-09 12:05:34 +00:00
|
|
|
# Generate Makefile dependencies from `local:` definitions in BUTANE files.
|
|
|
|
$(TMPDIR)make.depend: $(shell find $(ROOTDIR) -name '*.bu' -type f 2>/dev/null)
|
2021-01-13 16:36:50 +00:00
|
|
|
@printf "# Automatic prerequisites for Fedora CoreOS configuration." > $@
|
2022-01-15 11:43:33 +00:00
|
|
|
@printf "$(foreach i,$^,\n$(patsubst $(ROOTDIR)%.bu,$(TMPDIR)deploy/%.ign, \
|
|
|
|
$(i)): $(addprefix $(TMPDIR)deploy/, $(shell awk -F '[ ]+local:[ ]*' '/^[ ]+(-[ ]+)?local:/ {print $$2}' $(i))))" >> $@
|
2021-01-13 16:36:50 +00:00
|
|
|
|
2022-08-26 14:10:02 +00:00
|
|
|
.PHONY: deploy deploy-virtual destroy-virtual clean purge help $(CONTAINERFILES)
|
2021-01-13 16:36:50 +00:00
|
|
|
|
|
|
|
# Conditional command echo control.
|
|
|
|
Q := $(if $(VERBOSE),,@)
|
|
|
|
|
|
|
|
# Find and return full path to command by name, or throw error if none can be found in PATH.
|
|
|
|
# Example use: $(call find-cmd,ls)
|
|
|
|
find-cmd = $(or $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))),$(error "Command '$(1)' not found in PATH"))
|
|
|
|
|
|
|
|
# Shell colors, used in messages.
|
|
|
|
BOLD := \033[1m
|
|
|
|
UNDERLINE := \033[4m
|
|
|
|
BLUE := \033[36m
|
|
|
|
RESET := \033[0m
|
|
|
|
|
|
|
|
# Dependency includes.
|
|
|
|
include $(TMPDIR)make.depend
|