|
| 1 | +name: Azure image to Gallery release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + |
| 7 | + url_type: |
| 8 | + description: 'The Image format' |
| 9 | + required: true |
| 10 | + default: 'RAW at AWS S3' |
| 11 | + type: choice |
| 12 | + options: |
| 13 | + - 'RAW at AWS S3' |
| 14 | + - 'VHD blob at Azure' |
| 15 | + |
| 16 | + image_url: |
| 17 | + description: "The Image URL" |
| 18 | + required: true |
| 19 | + default: '' |
| 20 | + |
| 21 | + dry-run-mode: |
| 22 | + description: "Dry-run mode" |
| 23 | + required: true |
| 24 | + type: boolean |
| 25 | + default: true |
| 26 | + |
| 27 | + public_gallery: |
| 28 | + description: "Release to public Gallery" |
| 29 | + required: true |
| 30 | + type: boolean |
| 31 | + default: false |
| 32 | + |
| 33 | + notify_mattermost: |
| 34 | + description: "Send notification to Mattermost" |
| 35 | + required: true |
| 36 | + type: boolean |
| 37 | + default: false |
| 38 | + |
| 39 | +permissions: |
| 40 | + id-token: write |
| 41 | + contents: read |
| 42 | + |
| 43 | +jobs: |
| 44 | + release-image-to-gallery: |
| 45 | + name: "Release ${{ inputs.image_url }} to Gallery" |
| 46 | + runs-on: ubuntu-24.04 |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + |
| 51 | + - name: Prepare environment |
| 52 | + run: | |
| 53 | + echo "IMAGE_FILE=$(basename ${{ inputs.image_url }})" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + sudo apt-get update |
| 56 | + sudo apt-get install -y curl qemu-utils |
| 57 | +
|
| 58 | + - name: Azure login |
| 59 | + uses: azure/login@v2 |
| 60 | + with: |
| 61 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 62 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 63 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 64 | + |
| 65 | + - name: Download the image .raw file |
| 66 | + if: ${{ inputs.url_type == 'RAW at AWS S3' }} |
| 67 | + run: | |
| 68 | + # Download to the /mnt directory as it has ~70Gb of disk space |
| 69 | + sudo chmod o+wx /mnt |
| 70 | + curl -s ${{ inputs.image_url }} -o /mnt/${{ env.IMAGE_FILE }} |
| 71 | + test -e /mnt/${{ env.IMAGE_FILE }} |
| 72 | +
|
| 73 | + - name: Read the image info |
| 74 | + run: | |
| 75 | + # Capture version, timestamp and architecture |
| 76 | + case '${{ inputs.url_type }}' in |
| 77 | + RAW*) |
| 78 | + regex='-([0-9]+\.?[0-9]*)-([0-9]{8,9}(\.[0-9])?).*\.(x86_64|aarch64)' |
| 79 | + if [[ ${{ env.IMAGE_FILE }} =~ $regex ]]; then |
| 80 | + release_version="${BASH_REMATCH[1]}" |
| 81 | + timestamp="${BASH_REMATCH[2]}" |
| 82 | + arch="${BASH_REMATCH[4]}" |
| 83 | + else |
| 84 | + echo "[Error] Could not parse '${{ env.IMAGE_FILE }}' file name!" |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | + ;; |
| 88 | +
|
| 89 | + VHD*) |
| 90 | + regex_azure='-([0-9]+\.?[0-9]*)-([0-9]{8,9}(\.[0-9])?).*\.(x86_64|aarch64|arm64)' |
| 91 | + regex_simple='almalinux-([0-9]+\.[0-9]+)-(x86_64|aarch64|arm64)\.([0-9]{8})' |
| 92 | +
|
| 93 | + # Modern .vhd files like AlmaLinux-10-Azure-10.0-20250529.0-64k.aarch64.vhd |
| 94 | + if [[ ${{ env.IMAGE_FILE }} =~ $regex_azure ]]; then |
| 95 | + release_version="${BASH_REMATCH[1]}" |
| 96 | + timestamp="${BASH_REMATCH[2]}" |
| 97 | + arch="${BASH_REMATCH[4]}" |
| 98 | +
|
| 99 | + # Legacy .vhd files like almalinux-9.6-arm64.20250522-01.vhd |
| 100 | + elif [[ ${{ env.IMAGE_FILE }} =~ $regex_simple ]]; then |
| 101 | + release_version="${BASH_REMATCH[1]}" |
| 102 | + arch="${BASH_REMATCH[2]}" |
| 103 | + timestamp="${BASH_REMATCH[3]}" |
| 104 | +
|
| 105 | + else |
| 106 | + echo "[Error] Could not parse '${{ env.IMAGE_FILE }}' file name!" |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + ;; |
| 110 | + esac |
| 111 | +
|
| 112 | + # AlmaLinux release string |
| 113 | + case $release_version in |
| 114 | + 10) release_string="AlmaLinux Kitten OS $release_version $arch" ;; |
| 115 | + *) release_string="AlmaLinux OS $release_version $arch" ;; |
| 116 | + esac |
| 117 | +
|
| 118 | + # Azure Gallery image type |
| 119 | + case $arch in |
| 120 | + x86_64) image_type="default" ;; |
| 121 | + aarch64|arm64) |
| 122 | + image_type="arm64" |
| 123 | + [[ ${{ env.IMAGE_FILE }} == *-64k* ]] && image_type="arm64-64k" |
| 124 | + ;; |
| 125 | + *) echo "[Error] Unknown architecture: $arch" ; exit 1 ;; |
| 126 | + esac |
| 127 | +
|
| 128 | + echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV |
| 129 | + echo "TIMESTAMP=$timestamp" >> $GITHUB_ENV |
| 130 | + echo "RELEASE_STRING=$release_string" >> $GITHUB_ENV |
| 131 | + echo "IMAGE_TYPE=$image_type" >> $GITHUB_ENV |
| 132 | +
|
| 133 | + - name: Release the image to a Gallery |
| 134 | + id: release |
| 135 | + run: | |
| 136 | + # copy azure_uploader.sh to /mnt and run it there |
| 137 | + sudo chmod o+wx /mnt |
| 138 | + cp -a tools/azure_uploader.sh /mnt/ |
| 139 | + chmod +x /mnt/azure_uploader.sh |
| 140 | + cd /mnt |
| 141 | +
|
| 142 | + # Prepare the options for the azure_uploader.sh script |
| 143 | + release_options='-d ${{ env.RELEASE_VERSION }} -t ${{ env.IMAGE_TYPE }}' |
| 144 | +
|
| 145 | + # Use -i option if .raw image url, or -u option if .vhd blob url is provided |
| 146 | + case '${{ inputs.url_type }}' in |
| 147 | + RAW*) |
| 148 | + release_options+=' -i ${{ env.IMAGE_FILE }}' |
| 149 | + ;; |
| 150 | + VHD*) |
| 151 | + release_options+=' -u ${{ inputs.image_url }}' |
| 152 | + ;; |
| 153 | + esac |
| 154 | +
|
| 155 | + # If dry-run-mode is false, then pass the -f option to upload to the Gallery |
| 156 | + [[ ${{ inputs.dry-run-mode }} == false ]] && \ |
| 157 | + release_options+=' -f' |
| 158 | +
|
| 159 | + # If public_gallery is true, then upload to 'almalinux' public Gallery |
| 160 | + [[ ${{ inputs.public_gallery }} == true ]] && \ |
| 161 | + release_options+=' -g almalinux' |
| 162 | +
|
| 163 | + ./azure_uploader.sh ${release_options} \ |
| 164 | + |& tee ./azure_uploader.log |
| 165 | +
|
| 166 | + - name: Prepare summary |
| 167 | + if: ${{ inputs.dry-run-mode == false }} |
| 168 | + run: | |
| 169 | + # Read the log file to get the relevant information |
| 170 | + test -f /mnt/azure_uploader.log |
| 171 | +
|
| 172 | + # Read uploaded image blob URL |
| 173 | + case '${{ inputs.url_type }}' in |
| 174 | + RAW*) |
| 175 | + { |
| 176 | + echo 'IMAGE_URI_SUMMARY<<EOF' |
| 177 | + cat /mnt/azure_uploader.log | grep 'Image URI:' |
| 178 | + echo EOF |
| 179 | + } >> "$GITHUB_ENV" |
| 180 | + ;; |
| 181 | + VHD*) |
| 182 | + echo "IMAGE_URI_SUMMARY=Image URI: ${{ inputs.image_url }}" >> "$GITHUB_ENV" |
| 183 | + ;; |
| 184 | + esac |
| 185 | +
|
| 186 | + # Image definition version |
| 187 | + { |
| 188 | + echo 'IMAGE_INFO_SUMMARY<<EOF' |
| 189 | + cat /mnt/azure_uploader.log | grep 'Created almalinux' | sed 's/Created/- Created/g' |
| 190 | + echo EOF |
| 191 | + } >> "$GITHUB_ENV" |
| 192 | +
|
| 193 | + - name: Print job summary |
| 194 | + run: | |
| 195 | + { |
| 196 | + echo "**${{ env.RELEASE_STRING }}** \`${{ env.TIMESTAMP }}\`:" |
| 197 | + echo "- Image file: ${{ env.IMAGE_FILE }}" |
| 198 | + [[ ${{ inputs.dry-run-mode }} == 'false' ]] \ |
| 199 | + && echo "- ${{ env.IMAGE_URI_SUMMARY }}" || true |
| 200 | + [[ ${{ inputs.dry-run-mode }} == 'false' ]] \ |
| 201 | + && echo "${{ env.IMAGE_INFO_SUMMARY }}" || true |
| 202 | + echo "- Released to Gallery: ${{ inputs.dry-run-mode && '❌' || '✅' }}" |
| 203 | + echo "- The Gallery is public: ${{ inputs.public_gallery && '✅' || '❌' }}" |
| 204 | + } >> "$GITHUB_STEP_SUMMARY" |
| 205 | +
|
| 206 | + - name: Send notification to Mattermost |
| 207 | + uses: mattermost/action-mattermost-notify@master |
| 208 | + if: inputs.notify_mattermost |
| 209 | + with: |
| 210 | + MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK_URL }} |
| 211 | + MATTERMOST_CHANNEL: ${{ vars.MATTERMOST_CHANNEL }} |
| 212 | + MATTERMOST_USERNAME: ${{ github.triggering_actor }} |
| 213 | + TEXT: | |
| 214 | + :almalinux: **${{ env.RELEASE_STRING }}** `${{ env.TIMESTAMP }}` Azure image, by the GitHub [Action](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 215 | + - Image file: `${{ env.IMAGE_FILE }}` |
| 216 | + - ${{ inputs.dry-run-mode == 'false' && env.IMAGE_URI_SUMMARY || '' }} |
| 217 | + ${{ inputs.dry-run-mode == 'false' && env.IMAGE_INFO_SUMMARY || '' }} |
| 218 | + - Released to Gallery: ${{ inputs.dry-run-mode && '❌' || '✅'}} |
| 219 | + - The Gallery is public: ${{ inputs.public_gallery && '✅' || '❌'}} |
0 commit comments