diff --git a/Makefile b/Makefile index a235271..89be40a 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ _IMAGE_REPO_ESCAPED = $(subst /,\/,$(IMAGE_REPO)) _IMAGE_REPO_DOUBLE_ESCAPED = $(subst \,\\\,$(_IMAGE_REPO_ESCAPED)) _VOLID = $(firstword $(subst -, ,$(IMAGE_NAME)))-$(ARCH)-$(IMAGE_TAG) _REPO_FILES = $(subst /etc/yum.repos.d,repos,$(REPOS)) -_LORAX_TEMPLATES = $(subst .in,,$(shell ls lorax_templates/*.tmpl.in)) +_LORAX_TEMPLATES = $(subst .in,,$(shell ls lorax_templates/*.tmpl.in)) $(foreach file,$(shell ls lorax_templates/scripts/post),lorax_templates/post_$(file).tmpl) +_TEMPLATE_VARS = ARCH VERSION IMAGE_REPO IMAGE_NAME IMAGE_TAG VARIANT WEB_UI REPOS _IMAGE_REPO_ESCAPED _IMAGE_REPO_DOUBLE_ESCAPED ifeq ($(VARIANT),Server) _LORAX_ARGS = --macboot --noupgrade @@ -38,8 +39,50 @@ build/deploy.iso: boot.iso container/$(IMAGE_NAME)-$(IMAGE_TAG) xorriso/input.t implantisomd5 build/deploy.iso # Step 1: Generate Lorax Templates +lorax_templates/post_%.tmpl: lorax_templates/scripts/post/% + # Support interactive-defaults.ks + $(eval _ISO_FILE = usr/share/anaconda/interactive-defaults.ks) + + header=0; \ + while read -r line; \ + do \ + if [[ $$line =~ ^\<\% ]]; \ + then \ + echo $$line >> lorax_templates/post_$*.tmpl; \ + echo >> lorax_templates/post_$*.tmpl; \ + else \ + if [[ $$header == 0 ]]; \ + then \ + echo "append $(_ISO_FILE) \"%post --erroronfail\"" >> lorax_templates/post_$*.tmpl; \ + header=1; \ + fi; \ + echo "append $(_ISO_FILE) \"$$line\"" >> lorax_templates/post_$*.tmpl; \ + fi; \ + done < lorax_templates/scripts/post/$* + echo "append $(_ISO_FILE) \"%end\"" >> lorax_templates/post_$*.tmpl + + # Support new Anaconda method + $(eval _ISO_FILE = usr/share/anaconda/post-scripts/configure_upgrades.ks) + + header=0; \ + while read -r line; \ + do \ + if [[ $$line =~ ^\<\% ]]; \ + then \ + echo >> lorax_templates/post_$*.tmpl; \ + else \ + if [[ $$header == 0 ]]; \ + then \ + echo "append $(_ISO_FILE) \"%post --erroronfail\"" >> lorax_templates/post_$*.tmpl; \ + header=1; \ + fi; \ + echo "append $(_ISO_FILE) \"$$line\"" >> lorax_templates/post_$*.tmpl; \ + fi; \ + done < lorax_templates/scripts/post/$* + echo "append $(_ISO_FILE) \"%end\"" >> lorax_templates/post_$*.tmpl + lorax_templates/%.tmpl: lorax_templates/%.tmpl.in - $(eval _VARS = IMAGE_NAME IMAGE_TAG _IMAGE_REPO_DOUBLE_ESCAPED) + $(eval _VARS = IMAGE_NAME IMAGE_TAG _IMAGE_REPO_DOUBLE_ESCAPED _IMAGE_REPO_ESCAPED) $(foreach var,$(_VARS),$(var)=$($(var))) envsubst '$(foreach var,$(_VARS),$$$(var))' < $(_BASE_DIR)/lorax_templates/$*.tmpl.in > $(_BASE_DIR)/lorax_templates/$*.tmpl @@ -58,13 +101,14 @@ boot.iso: $(_LORAX_TEMPLATES) $(_REPO_FILES) rm -Rf $(_BASE_DIR)/results || true rm /etc/rpm/macros.image-language-conf || true lorax -p $(IMAGE_NAME) -v $(VERSION) -r $(VERSION) -t $(VARIANT) \ - --isfinal --squashfs-only --buildarch=$(ARCH) --volid=$(_VOLID) \ - $(_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)) \ - --rootfs-size $(ROOTFS_SIZE) \ - $(_BASE_DIR)/results/ + --isfinal --squashfs-only --buildarch=$(ARCH) --volid=$(_VOLID) \ + $(_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)) \ + --rootfs-size $(ROOTFS_SIZE) \ + $(foreach var,$(_TEMPLATE_VARS),--add-template-var "$(shell echo $(var) | tr '[:upper:]' '[:lower:]')=$($(var))") \ + $(_BASE_DIR)/results/ mv $(_BASE_DIR)/results/images/boot.iso $(_BASE_DIR)/ # Step 4: Download container image diff --git a/action.yml b/action.yml index 8cedd8d..219cc6b 100644 --- a/action.yml +++ b/action.yml @@ -46,7 +46,7 @@ runs: # Check if running inside of the action repo if [[ -z "${{ github.action_ref }}" ]]; then if [[ "${{ github.ref_name }}" =~ (.*)/merge ]]; then tag=pr-${BASH_REMATCH[1]}; else tag=${{ github.ref_name }}; fi; fi if [[ -z "${tag}" ]]; then tag=${{ github.action_ref }}; fi - docker run --privileged --volume .:/github/workspace/ ghcr.io/jasonn3/build-container-installer:${tag} \ + docker run --privileged --volume ${{ github.workspace }}:/github/workspace/ ghcr.io/jasonn3/build-container-installer:${tag} \ ARCH=${{ inputs.arch }} \ IMAGE_NAME=${{ inputs.image_name }} \ IMAGE_REPO=${{ inputs.image_repo }} \ diff --git a/lorax_templates/configure_upgrades.tmpl.in b/lorax_templates/configure_upgrades.tmpl.in deleted file mode 100644 index eb75fa7..0000000 --- a/lorax_templates/configure_upgrades.tmpl.in +++ /dev/null @@ -1,8 +0,0 @@ -append usr/share/anaconda/interactive-defaults.ks "%post --erroronfail" -append usr/share/anaconda/interactive-defaults.ks "sed -i 's/container-image-reference=.*/container-image-reference=ostree-image-signed:docker:\/\/${_IMAGE_REPO_DOUBLE_ESCAPED}\/${IMAGE_NAME}:${IMAGE_TAG}/' /ostree/deploy/default/deploy/*.origin" -append usr/share/anaconda/interactive-defaults.ks "%end" - -append usr/share/anaconda/post-scripts/configure_upgrades.ks "%post --erroronfail" -append usr/share/anaconda/post-scripts/configure_upgrades.ks "sed -i 's/container-image-reference=.*/container-image-reference=ostree-image-signed:docker:\/\/${_IMAGE_REPO_DOUBLE_ESCAPED}\/${IMAGE_NAME}:${IMAGE_TAG}/' /ostree/deploy/default/deploy/*.origin" -append usr/share/anaconda/post-scripts/configure_upgrades.ks "%end" - diff --git a/lorax_templates/scripts/post/configure_upgrades b/lorax_templates/scripts/post/configure_upgrades new file mode 100644 index 0000000..5b56ef2 --- /dev/null +++ b/lorax_templates/scripts/post/configure_upgrades @@ -0,0 +1,7 @@ +<%page args="image_repo, _image_repo_double_escaped, image_name, image_tag"/> +if (which bootc &> /dev/null) +then + bootc switch ${image_repo}/${image_name}:${image_tag} +else + sed -i 's/container-image-reference=.*/container-image-reference=ostree-image-signed:docker:\/\/${_image_repo_double_escaped}\/${image_name}:${image_tag}/' /ostree/deploy/default/deploy/*.origin +fi