1
0
Fork 0
mirror of https://github.com/JasonN3/build-container-installer.git synced 2025-12-25 10:57:55 +01:00
build-container-installer/Makefile
2024-03-27 11:39:03 -04:00

160 lines
5.8 KiB
Makefile

# Configuration vars
## Formatting = UPPERCASE
# General
export ADDITIONAL_TEMPLATES =
export ARCH = x86_64
export EXTRA_BOOT_PARAMS =
export IMAGE_NAME = base
export IMAGE_REPO = quay.io/fedora-ostree-desktops
export IMAGE_TAG = $(VERSION)
REPOS = $(subst :,\:,$(wildcard /etc/yum.repos.d/*.repo))
export ROOTFS_SIZE = 4
export VARIANT = Server
export VERSION = 39
export WEB_UI = false
# Flatpak
export FLATPAK_REMOTE_NAME = flathub
export FLATPAK_REMOTE_URL = https://flathub.org/repo/flathub.flatpakrepo
export FLATPAK_REMOTE_REFS =
export FLATPAK_REMOTE_REFS_DIR =
export FLATPAK_DIR =
# Secure boot
export ENROLLMENT_PASSWORD =
export SECURE_BOOT_KEY_URL =
export ISO_NAME = $(_BASE_DIR)/build/deploy.iso
###################
# Hidden vars
SHELL = /bin/sh
# Cache
export DNF_CACHE =
export PACKAGE_MANAGER = dnf
# Functions
## Formatting = lowercase
# Get a list of templates for the feature
# $1 = feature
define get_templates
$(wildcard lorax_templates/$(1)_*.tmpl)
$(foreach file,$(notdir $(wildcard lorax_templates/scripts/post/$(1)_*)),lorax_templates/post_$(file).tmpl)
endef
# Generated/internal vars
## Formatting = _UPPERCASE
export _BASE_DIR = $(shell pwd)
_IMAGE_REPO_ESCAPED = $(subst /,\/,$(IMAGE_REPO))
_IMAGE_REPO_DOUBLE_ESCAPED = $(subst \,\\\,$(_IMAGE_REPO_ESCAPED))
_LORAX_ARGS =
_LORAX_TEMPLATES = $(call get_templates,install)
_REPO_FILES = $(subst /etc/yum.repos.d,repos,$(REPOS))
_TEMP_DIR = $(shell mktemp -d)
_TEMPLATE_VARS = ARCH _BASE_DIR IMAGE_NAME IMAGE_REPO _IMAGE_REPO_DOUBLE_ESCAPED _IMAGE_REPO_ESCAPED IMAGE_TAG REPOS _RHEL VARIANT VERSION WEB_UI
_VOLID = $(firstword $(subst -, ,$(IMAGE_NAME)))-$(ARCH)-$(IMAGE_TAG)
ifeq ($(findstring redhat.repo,$(REPOS)),redhat.repo)
_RHEL = true
else
_RHEL = false
endif
ifeq ($(_RHEL),true)
_LORAX_ARGS += --nomacboot --noupgrade
else ifeq ($(VARIANT),Server)
_LORAX_ARGS += --macboot --noupgrade
else
_LORAX_ARGS += --nomacboot
endif
ifeq ($(WEB_UI),true)
_LORAX_ARGS += -i anaconda-webui
endif
ifneq ($(DNF_CACHE),)
_LORAX_ARGS += --cachedir $(DNF_CACHE)
_LORAX_TEMPLATES += $(call get_templates,cache)
_TEMPLATE_VARS += DNF_CACHE
endif
ifneq ($(FLATPAK_DIR),)
_FLATPAK_REPO_GPG = $(shell curl -L $(FLATPAK_REMOTE_URL) | grep -i '^GPGKey=' | cut -d= -f2)
_FLATPAK_REPO_URL = $(shell curl -L $(FLATPAK_REMOTE_URL) | grep -i '^URL=' | cut -d= -f2)
_LORAX_ARGS += -i flatpak-libs
_LORAX_TEMPLATES += $(call get_templates,flatpak)
_TEMPLATE_VARS += FLATPAK_DIR FLATPAK_REMOTE_NAME FLATPAK_REMOTE_REFS FLATPAK_REMOTE_URL _FLATPAK_REPO_GPG _FLATPAK_REPO_URL
else
ifneq ($(FLATPAK_REMOTE_REFS_DIR),)
COLLECTED_REFS = $(foreach file,$(shell ls $(FLATPAK_REMOTE_REFS_DIR)/*),$(shell cat $(file)))
FLATPAK_REMOTE_REFS += $(sort $(COLLECTED_REFS))
endif
ifneq ($(FLATPAK_REMOTE_REFS),)
_FLATPAK_REPO_GPG = $(shell curl -L $(FLATPAK_REMOTE_URL) | grep -i '^GPGKey=' | cut -d= -f2)
_FLATPAK_REPO_URL = $(shell curl -L $(FLATPAK_REMOTE_URL) | grep -i '^URL=' | cut -d= -f2)
_LORAX_ARGS += -i flatpak-libs
_LORAX_TEMPLATES += $(call get_templates,flatpak) \
external/fedora-lorax-templates/ostree-based-installer/lorax-embed-flatpaks.tmpl
_TEMPLATE_VARS += FLATPAK_DIR FLATPAK_REMOTE_NAME FLATPAK_REMOTE_REFS FLATPAK_REMOTE_URL _FLATPAK_REPO_GPG _FLATPAK_REPO_URL
endif
endif
ifneq ($(SECURE_BOOT_KEY_URL),)
_LORAX_TEMPLATES += $(call get_templates,secureboot)
_TEMPLATE_VARS += ENROLLMENT_PASSWORD
endif
_SUBDIRS = container external flatpak_refs lorax_templates repos xorriso
# Step 7: Build end ISO
## Default action
build/deploy.iso: results/images/boot.iso container/$(IMAGE_NAME)-$(IMAGE_TAG) xorriso/input.txt
mkdir $(_BASE_DIR)/build || true
xorriso -dialog on < $(_BASE_DIR)/xorriso/input.txt
implantisomd5 $(ISO_NAME)
# Step 3: Build boot.iso using Lorax
results/images/boot.iso: external/lorax/branch-$(VERSION) $(filter lorax_templates/%,$(_LORAX_TEMPLATES)) $(_REPO_FILES)
$(if $(wildcard results), rm -Rf results)
mv /etc/rpm/macros.image-language-conf $(_TEMP_DIR)/macros.image-language-conf || true
# Download the secure boot key
$(if $(SECURE_BOOT_KEY_URL), curl --fail -L -o $(_BASE_DIR)/sb_pubkey.der $(SECURE_BOOT_KEY_URL))
lorax -p $(IMAGE_NAME) -v $(VERSION) -r $(VERSION) -t $(VARIANT) \
--isfinal --squashfs-only --buildarch=$(ARCH) --volid=$(_VOLID) --sharedir $(_BASE_DIR)/external/lorax/share/templates.d/99-generic \
$(_LORAX_ARGS) \
$(foreach file,$(_REPO_FILES),--repo $(_BASE_DIR)/$(file)) \
$(foreach file,$(_LORAX_TEMPLATES),--add-template $(_BASE_DIR)/$(file)) \
$(foreach file,$(ADDITIONAL_TEMPLATES),--add-template $(file)) \
$(foreach file,$(_FLATPAK_TEMPLATES),--add-template $(file)) \
$(foreach file,$(_EXTERNAL_TEMPLATES),--add-template $(_BASE_DIR)/external/$(file)) \
--rootfs-size $(ROOTFS_SIZE) \
$(foreach var,$(_TEMPLATE_VARS),--add-template-var "$(shell echo $(var) | tr '[:upper:]' '[:lower:]')=$($(var))") \
$(_BASE_DIR)/results/
mv -f $(_TEMP_DIR)/macros.image-language-conf /etc/rpm/macros.image-language-conf || true
FILES_TO_CLEAN = $(wildcard build debugdata pkglists results original-pkgsizes.txt final-pkgsizes.txt lorax.conf *.iso *log)
.PHONY: clean
clean:
rm -Rf $(FILES_TO_CLEAN)
$(foreach DIR,$(_SUBDIRS),$(MAKE) -w -C $(DIR) clean;)
.PHONY: install-deps
install-deps:
$(if $(findstring apt,$(PACKAGE_MANAGER)),$(PACKAGE_MANAGER) update)
$(PACKAGE_MANAGER) install -y lorax xorriso coreutils gettext
$(foreach DIR,$(_SUBDIRS),$(MAKE) -w -C $(DIR) install-deps;)
.PHONY: $(_SUBDIRS) test $(wildcard test/*) $(wildcard test/*/*)
test $(addsuffix /*,$(_SUBDIRS) test):
$(eval DIR=$(firstword $(subst /, ,$@)))
$(if $(filter-out $(DIR),$@), $(eval TARGET=$(subst $(DIR)/,,$@)),$(eval TARGET=))
$(MAKE) -w -C $(DIR) $(TARGET)
.DEFAULT:
$(eval DIR=$(firstword $(subst /, ,$@)))
$(if $(filter-out $(DIR),$@), $(eval TARGET=$(subst $(DIR)/,,$@)),$(eval TARGET=))
$(MAKE) -w -C $(DIR) $(TARGET)