From b5c953d8d3e3e752470fd749cb2a58e821e63dcd Mon Sep 17 00:00:00 2001 From: Jason N <33561705+JasonN3@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:17:21 -0400 Subject: [PATCH] Automatically determine Flatpak dependencies (#86) Co-authored-by: Noel Miller --- .github/workflows/build_container.yml | 5 ++-- .github/workflows/build_iso.yml | 16 +++++++++++ .gitignore | 2 +- Makefile | 15 ++++++++-- action.yml | 41 +++++++++++++++++++++++++++ flatpak_refs/Firefox | 4 --- flatpak_refs/VLC | 1 - lorax_templates/flatpak_link.tmpl | 5 ++++ xorriso/gen_input.sh.in | 11 +++++++ 9 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 lorax_templates/flatpak_link.tmpl diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml index a34509d..23966d1 100644 --- a/.github/workflows/build_container.yml +++ b/.github/workflows/build_container.yml @@ -12,9 +12,8 @@ jobs: build-container: if: > github.event_name == 'push' || - github.event_name == 'issue_comment' || - ( github.event_name == 'pull_request' && - contains(github.event.pull_request.labels.*.name, 'auto-test') ) + github.event_name == 'issue_comment' || + github.event_name == 'workflow_dispatch' name: Build Container Image env: JOB_NAME: Build Container Image diff --git a/.github/workflows/build_iso.yml b/.github/workflows/build_iso.yml index ea714b9..572cdbf 100644 --- a/.github/workflows/build_iso.yml +++ b/.github/workflows/build_iso.yml @@ -81,6 +81,22 @@ jobs: sha: ${{ env.sha }} targetUrl: ${{ steps.jobs.outputs.html_url }} + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + # this might remove tools that are actually needed, + # if set to "true" but frees about 6 GB + tool-cache: false + + # all of these default to true, but feel free to set to + # "false" if necessary for your workflow + android: true + dotnet: true + haskell: true + large-packages: true + docker-images: true + swap-storage: true + - name: Lowercase Registry id: registry_case uses: ASzc/change-string-case-action@v6 diff --git a/.gitignore b/.gitignore index dde3499..f116d91 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ /lorax.conf /output /*.log - +/cache \ No newline at end of file diff --git a/Makefile b/Makefile index acf2d0d..b596037 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ FLATPAK_REMOTE_NAME = flathub FLATPAK_REMOTE_URL = https://flathub.org/repo/flathub.flatpakrepo FLATPAK_REMOTE_REFS = FLATPAK_REMOTE_REFS_DIR = +FLATPAK_DIR = # Secure boot ENROLLMENT_PASSWORD = SECURE_BOOT_KEY_URL = @@ -121,6 +122,13 @@ _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)) @@ -132,9 +140,10 @@ _FLATPAK_REPO_URL = $(shell curl -L $(FLATPAK_REMOTE_URL) | grep -i '^URL=' | cu _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_REMOTE_NAME FLATPAK_REMOTE_REFS FLATPAK_REMOTE_URL _FLATPAK_REPO_GPG _FLATPAK_REPO_URL - +_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) @@ -200,7 +209,7 @@ container/$(IMAGE_NAME)-$(IMAGE_TAG): xorriso/%.sh: xorriso/%.sh.in sed -i 's/quiet/quiet $(EXTRA_BOOT_PARAMS)/g' results/boot/grub2/grub.cfg sed -i 's/quiet/quiet $(EXTRA_BOOT_PARAMS)/g' results/EFI/BOOT/grub.cfg - $(eval _VARS = IMAGE_NAME IMAGE_TAG ARCH VERSION) + $(eval _VARS = FLATPAK_DIR IMAGE_NAME IMAGE_TAG ARCH VERSION) $(foreach var,$(_VARS),$(var)=$($(var))) envsubst '$(foreach var,$(_VARS),$$$(var))' < $(_BASE_DIR)/xorriso/$*.sh.in > $(_BASE_DIR)/xorriso/$*.sh # Step 6: Generate xorriso input diff --git a/action.yml b/action.yml index 55944f7..c856f54 100644 --- a/action.yml +++ b/action.yml @@ -24,6 +24,10 @@ inputs: description: Whether to enable caching for skopeo required: false default: "false" + enable_flatpak_dependencies: + description: Whether to enable automatically determining Flatpak dependencies + required: false + default: "true" enrollment_password: description: Used for supporting secure boot (requires secure_boot_key_url to be defined) required: false @@ -130,6 +134,42 @@ runs: mkdir /cache/dnf_new || true mkdir /cache/skopeo || true + - name: Determine Flatpak dependencies + if: inputs.enable_flatpak_dependencies == 'true' + id: flatpak_dependencies + shell: bash + run: | + image="${{ inputs.image_repo }}/${{ inputs.image_name }}:${{ inputs.image_tag }}" + # Make temp space + FLATPAK_DIR=$(basename $(mktemp -d -p ${{ github.workspace }} flatpak.XXX)) + # Get list of refs from directory + sudo mkdir /github || true + sudo ln -s ${{ github.workspace }} /github/workspace + DIR_REFS=$(cat ${{ inputs.flatpak_remote_refs_dir }}/* | tr '\n' ' ' ) + # Generate install script + cat << EOF > ${{ github.workspace }}/${FLATPAK_DIR}/script.sh + cat /flatpak_dir/script.sh + mkdir -p /flatpak/flatpak /flatpak/triggers + mkdir /var/tmp || true + chmod -R 1777 /var/tmp + flatpak config --system --set languages "*" + flatpak remote-add --system ${{ inputs.flatpak_remote_name }} ${{ inputs.flatpak_remote_url }} + flatpak install --system -y ${{ inputs.flatpak_remote_refs }} ${DIR_REFS} + ostree init --repo=/flatpak_dir/repo --mode=archive-z2 + for i in \$(ostree refs --repo=\${FLATPAK_SYSTEM_DIR}/repo | grep '^deploy/' | sed 's/^deploy\///g') + do + echo "Copying \${i}..." + ostree --repo=/flatpak_dir/repo pull-local \${FLATPAK_SYSTEM_DIR}/repo \$(ostree --repo=\${FLATPAK_SYSTEM_DIR}/repo rev-parse ${{ inputs.flatpak_remote_name }}/\${i}) + mkdir -p \$(dirname /flatpak_dir/repo/refs/heads/\${i}) + ostree --repo=\${FLATPAK_SYSTEM_DIR}/repo rev-parse ${{ inputs.flatpak_remote_name }}/\${i} > /flatpak_dir/repo/refs/heads/\${i} + done + flatpak build-update-repo /flatpak_dir/repo + ostree refs --repo=/flatpak_dir/repo + EOF + docker run --rm --privileged --entrypoint bash -e FLATPAK_SYSTEM_DIR=/flatpak/flatpak -e FLATPAK_TRIGGERSDIR=/flatpak/triggers --volume ${{ github.workspace }}/${FLATPAK_DIR}:/flatpak_dir ${image} /flatpak_dir/script.sh + echo "flatpak_dir=${FLATPAK_DIR}" >> $GITHUB_OUTPUT + docker rmi ${image} + - name: Run docker image env: ACTION_REPO: ${{ github.action_repository }} @@ -183,6 +223,7 @@ runs: FLATPAK_REMOTE_NAME="${{ inputs.flatpak_remote_name }}" \ ${vars} \ FLATPAK_REMOTE_URL="${{ inputs.flatpak_remote_url }}" \ + FLATPAK_DIR="${{ steps.flatpak_dependencies.outputs.flatpak_dir && format('/github/workspace/{0}', steps.flatpak_dependencies.outputs.flatpak_dir) || '' }}" \ IMAGE_NAME="${{ inputs.image_name }}" \ IMAGE_REPO="${{ inputs.image_repo }}" \ IMAGE_TAG="${{ inputs.image_tag || inputs.version }}" \ diff --git a/flatpak_refs/Firefox b/flatpak_refs/Firefox index fdc2b93..6bc6e1d 100644 --- a/flatpak_refs/Firefox +++ b/flatpak_refs/Firefox @@ -1,5 +1 @@ app/org.mozilla.firefox/x86_64/stable - -runtime/org.mozilla.firefox.Locale/x86_64/stable -runtime/org.freedesktop.Platform/x86_64/23.08 -runtime/org.freedesktop.Platform.Locale/x86_64/23.08 \ No newline at end of file diff --git a/flatpak_refs/VLC b/flatpak_refs/VLC index 6e4a3fd..496d8d6 100644 --- a/flatpak_refs/VLC +++ b/flatpak_refs/VLC @@ -1,2 +1 @@ app/org.videolan.VLC/x86_64/stable -runtime/org.kde.Platform/x86_64/5.15-23.08 \ No newline at end of file diff --git a/lorax_templates/flatpak_link.tmpl b/lorax_templates/flatpak_link.tmpl new file mode 100644 index 0000000..a38341b --- /dev/null +++ b/lorax_templates/flatpak_link.tmpl @@ -0,0 +1,5 @@ +<%page args="flatpak_dir"/> + +%if flatpak_dir != "": +symlink /run/install/repo/flatpak /flatpak +%endif \ No newline at end of file diff --git a/xorriso/gen_input.sh.in b/xorriso/gen_input.sh.in index f2f678c..0a993bc 100644 --- a/xorriso/gen_input.sh.in +++ b/xorriso/gen_input.sh.in @@ -10,6 +10,17 @@ echo "-chmod 0444 boot/grub2/grub.cfg" echo "-map $(pwd)/results/EFI/BOOT/grub.cfg EFI/BOOT/grub.cfg" echo "-chmod 0444 EFI/BOOT/grub.cfg" +if [[ -n "${FLATPAK_DIR}" ]] +then + pushd ${FLATPAK_DIR} > /dev/null + for file in $(find *) + do + echo "-map $(pwd)/${file} flatpak/${file}" + echo "-chmod 0444 flatpak/${file}" + done + popd > /dev/null +fi + if [ -f $(pwd)/sb_pubkey.der ] then echo "-map $(pwd)/sb_pubkey.der sb_pubkey.der"