Makefile: Add target for building container

This is mostly useful in testing, and requires that `podman` is working
in the local system.
This commit is contained in:
Alex Palaistras 2022-08-26 15:10:02 +01:00
parent 6e9a9e5b1b
commit 70e6387139

View File

@ -9,10 +9,14 @@ HOST := $(if $(filter deploy-virtual,$(MAKECMDGOALS)),virtual,$(HOST))
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/fcos-build.???? 2>/dev/null || mktemp -d /var/tmp/fcos-build.XXXX && chmod 0755 /var/tmp/fcos-build.????)/
ADDRESS = $(shell ip -o route get 1 | awk '{for (i=1; i<=NF; i++) {if ($$i == "src") {print $$(i+1); exit}}}')
# 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)
# Build-time dependencies. # Build-time dependencies.
BUTANE ?= $(call find-cmd,butane) BUTANE ?= $(call find-cmd,butane)
PODMAN ?= $(call find-cmd,podman)
CURL ?= $(call find-cmd,curl) $(if $(VERBOSE),,--progress-bar) --fail CURL ?= $(call find-cmd,curl) $(if $(VERBOSE),,--progress-bar) --fail
GPG ?= $(call find-cmd,gpg) $(if $(VERBOSE),,-q) GPG ?= $(call find-cmd,gpg) $(if $(VERBOSE),,-q)
VIRSH ?= $(call find-cmd,virsh) --connect=qemu:///system $(if $(VERBOSE),,-q) VIRSH ?= $(call find-cmd,virsh) --connect=qemu:///system $(if $(VERBOSE),,-q)
@ -28,7 +32,7 @@ deploy: $(TMPDIR)deploy/host/$(HOST)/spec.ign
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="fcos-$(STREAM)-$(VERSION)-$(ARCH)" --os-variant=fedora34 \
--graphics=none --vcpus=2 --memory=2048 \ --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=10,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"
@ -56,6 +60,11 @@ help:
@awk -F ':|##' '/^##/ {c=$$2; getline; printf "$(BLUE)%16s$(RESET)%s\n", $$1, c}' $(MAKEFILE_LIST) @awk -F ':|##' '/^##/ {c=$$2; getline; printf "$(BLUE)%16s$(RESET)%s\n", $$1, c}' $(MAKEFILE_LIST)
@printf "\n" @printf "\n"
# Build container file locally using 'podman build'.
$(CONTAINERFILES):
@printf "Building container for '$(notdir $(@D))'...\n"
$Q cd "$(abspath $(@D))" && $(PODMAN) build .
# Copy host configuration in plain-text. Mainly used for development hosts. # Copy host configuration in plain-text. Mainly used for development hosts.
$(TMPDIR)deploy/$(HOST).env: $(ROOTDIR)host/$(HOST)/$(HOST).env $(TMPDIR)deploy/$(HOST).env: $(ROOTDIR)host/$(HOST)/$(HOST).env
$Q install -d $(@D) $Q install -d $(@D)
@ -103,7 +112,7 @@ $(TMPDIR)make.depend: $(shell find $(ROOTDIR) -name '*.bu' -type f 2>/dev/null)
$Q $(MAKE) -s -f $(firstword $(MAKEFILE_LIST)) help $Q $(MAKE) -s -f $(firstword $(MAKEFILE_LIST)) help
@printf "Invalid target '$@', stopping.\n"; exit 1 @printf "Invalid target '$@', stopping.\n"; exit 1
.PHONY: deploy deploy-virtual destroy-virtual clean purge help .PHONY: deploy deploy-virtual destroy-virtual clean purge help $(CONTAINERFILES)
# Conditional command echo control. # Conditional command echo control.
Q := $(if $(VERBOSE),,@) Q := $(if $(VERBOSE),,@)