|
| 1 | +--- |
| 2 | +name: Build bootable artifacts |
| 3 | + |
| 4 | +inputs: |
| 5 | + platform: |
| 6 | + description: The platform to build the image for (e.g., "x86_64", "arm64") |
| 7 | + required: true |
| 8 | + image: |
| 9 | + description: Full podman image reference, including hash (e.g., "registry.example.com/image@sha256") |
| 10 | + required: true |
| 11 | + image-name: |
| 12 | + description: Name of the image, will be used to name the artifact files (e.g., "my-image") |
| 13 | + required: true |
| 14 | + image-types: |
| 15 | + description: The types of bootable artifacts to build (e.g., "iso,raw") |
| 16 | + required: false |
| 17 | + default: "iso" |
| 18 | + update_is_signed: |
| 19 | + description: Whether the image is signed or not |
| 20 | + required: false |
| 21 | + update_origin_ref: |
| 22 | + description: Image reference to update from (e.g., "{image}:latest") |
| 23 | + required: true |
| 24 | + config-file: |
| 25 | + description: Path to the bootable artifacts configuration file |
| 26 | + required: true |
| 27 | + use-librepo: |
| 28 | + description: "Use librepo to download the image" |
| 29 | + required: false |
| 30 | + additional-args: |
| 31 | + description: "Additional arguments to pass to the bootc-image-builder" |
| 32 | + required: false |
| 33 | + REGISTRY: |
| 34 | + description: The container registry URL (e.g., "registry.example.com") |
| 35 | + required: true |
| 36 | + REGISTRY_USER: |
| 37 | + description: The username for the container registry login |
| 38 | + required: true |
| 39 | + REGISTRY_TOKEN: |
| 40 | + description: The token for authenticating with the container registry |
| 41 | + required: true |
| 42 | + |
| 43 | +outputs: |
| 44 | + output_directory: |
| 45 | + description: The directory where the built artifacts and checksums are stored |
| 46 | + value: ${{ steps.rename.outputs.output_directory }} |
| 47 | + artifact_basename: |
| 48 | + description: The base name of the artifacts |
| 49 | + value: ${{ steps.rename.outputs.artifact_basename }} |
| 50 | + |
| 51 | +runs: |
| 52 | + using: "composite" |
| 53 | + steps: |
| 54 | + - name: Login to Container Registry |
| 55 | + uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7 |
| 56 | + with: |
| 57 | + registry: ${{ inputs.REGISTRY }} |
| 58 | + username: ${{ inputs.REGISTRY_USER }} |
| 59 | + password: ${{ inputs.REGISTRY_TOKEN }} |
| 60 | + |
| 61 | + - name: Set up environment |
| 62 | + id: set-env |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + ARCH=${{ inputs.platform }} |
| 66 | + echo "CLEAN_ARCH=${ARCH//\//_}" >> "$GITHUB_ENV" |
| 67 | +
|
| 68 | + - name: Prepare bootable artifacts configuration |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + [ "${{ inputs.update_is_signed }}" = "true" ] && SIG="--enforce-container-sigpolicy" |
| 72 | +
|
| 73 | + sed -i 's#<UPDATE_IMAGE_REF>#${{ inputs.update_origin_ref }}#g' ${{ inputs.config-file }} |
| 74 | + sed -i "s#<IMAGE_SIGNED>#${SIG}#g" ${{ inputs.config-file }} |
| 75 | + cat ${{ inputs.config-file }} |
| 76 | +
|
| 77 | + [ "${{ inputs.use-librepo }}" = "true" ] && USE_LIBREPO="True" || USE_LIBREPO="False" |
| 78 | + ADDITIONAL_ARGS="--target-arch=${{ env.CLEAN_ARCH }} --use-librepo=${USE_LIBREPO} ${{ inputs.additional-args }}" |
| 79 | +
|
| 80 | + echo "ADDITIONAL_ARGS=${ADDITIONAL_ARGS}" >> "$GITHUB_ENV" |
| 81 | +
|
| 82 | + if [[ "${ADDITIONAL_ARGS}" == *"--installer-payload-ref"* ]]; then |
| 83 | + INSTALLER_PAYLOAD_REF=$(echo "${ADDITIONAL_ARGS}" | grep -oP '(?<=--installer-payload-ref[= ])\S+') |
| 84 | + sudo podman pull "${INSTALLER_PAYLOAD_REF}" |
| 85 | + fi |
| 86 | +
|
| 87 | + - name: Build bootable artifacts |
| 88 | + id: build |
| 89 | + uses: osbuild/bootc-image-builder-action@4503a3445240ffc85cccf8f57d7cab5634e351e2 |
| 90 | + with: |
| 91 | + config-file: ${{ inputs.config-file }} |
| 92 | + image: ${{ inputs.image }} |
| 93 | + additional-args: ${{ env.ADDITIONAL_ARGS }} |
| 94 | + types: ${{ inputs.image-types }} |
| 95 | + |
| 96 | + - name: Rename bootable artifacts |
| 97 | + id: rename |
| 98 | + env: |
| 99 | + OUTPUT_PATH: output-${{ env.CLEAN_ARCH }} |
| 100 | + shell: bash |
| 101 | + run: | |
| 102 | + set -x |
| 103 | + mkdir -p ${{ env.OUTPUT_PATH }} |
| 104 | + OUTPUT_DIRECTORY="$(realpath ${{ env.OUTPUT_PATH }})" |
| 105 | + ARTIFACT_BASENAME="${{ inputs.image-name }}-${{ env.CLEAN_ARCH }}" |
| 106 | +
|
| 107 | + echo '${{ steps.build.outputs.output-paths }}' | jq -c '.[]' | while read -r artifact; do |
| 108 | + ARTIFACT_PATH=$(echo "$artifact" | jq -r '.path') |
| 109 | + ARTIFACT_CHECKSUM=$(echo "$artifact" | jq -r '.checksum') |
| 110 | + ARTIFACT_EXTENSION=$(echo "$ARTIFACT_PATH" | awk -F. '{print $NF}') |
| 111 | +
|
| 112 | + ARTIFACT_NAME="${ARTIFACT_BASENAME}.${ARTIFACT_EXTENSION}" |
| 113 | + CHECKSUM_NAME="${ARTIFACT_NAME}-CHECKSUM" |
| 114 | +
|
| 115 | + cp "$ARTIFACT_PATH" "${OUTPUT_DIRECTORY}/${ARTIFACT_NAME}" |
| 116 | + echo "$ARTIFACT_CHECKSUM" > "${OUTPUT_DIRECTORY}/${CHECKSUM_NAME}" |
| 117 | + done |
| 118 | +
|
| 119 | + echo "output_directory=${OUTPUT_DIRECTORY}" >> "${GITHUB_OUTPUT}" |
| 120 | + echo "artifact_basename=${ARTIFACT_BASENAME}" >> "${GITHUB_OUTPUT}" |
0 commit comments