AWS AMI copy to Regions, make Public #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: copy-ami | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| ami_id: | |
| description: "AMI ID to copy and make public" | |
| required: true | |
| default: '' | |
| make_public: | |
| description: "Copy AMI to all available AWS regions and make public" | |
| required: true | |
| type: boolean | |
| default: true | |
| notify_mattermost: | |
| description: "Send notification to Mattermost" | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| build-images: | |
| name: "Copy ${{ inputs.ami_id }} AMI to all available AWS regions and make public" | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/[email protected] | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ vars.AWS_REGION }} | |
| - name: Get AMI Name | |
| run: | | |
| AMI_NAME=$(aws ec2 describe-images --filters "Name=image-id,Values=${{ inputs.ami_id }}" --query 'Images[0].Name' --output text) | |
| if [[ "${AMI_NAME}" == "" || "${AMI_NAME}" == "None" ]]; then | |
| exit 1 | |
| else | |
| echo "[Debug] AMI Name: '${AMI_NAME}'" | |
| fi | |
| echo "AMI_NAME=${AMI_NAME}" >> $GITHUB_ENV | |
| - name: Print AMI summary | |
| uses: actions/github-script@v7 | |
| with: | |
| result-encoding: string | |
| script: | | |
| core.summary | |
| .addHeading('${{ env.AMI_NAME }}', '4') | |
| .addHeading('AMI ID: ${{ inputs.ami_id }}', '5') | |
| .addHeading('Public: ${{ inputs.make_public && '✅' || '❌'}}', '5') | |
| .write() | |
| - name: Copy an AMI to all available AWS regions and make it public | |
| if: inputs.make_public | |
| run: | | |
| # Lowercase AMI Name, replace spaces and dots with underscores | |
| wiki_data_file="${{ env.AMI_NAME }}" | |
| wiki_data_file="${wiki_data_file,,}" | |
| wiki_data_file="${wiki_data_file// /_}" | |
| wiki_data_file="${wiki_data_file//./_}" | |
| echo "wiki_data_file=${wiki_data_file}" >> $GITHUB_ENV | |
| pip3 install markdown_table | |
| tools/aws_ami_mirror.py \ | |
| --csv-output ${{ github.workspace }}/${wiki_data_file}.csv \ | |
| --md-output ${{ github.workspace }}/${wiki_data_file}.md \ | |
| --ami ${{ inputs.ami_id }} | |
| - uses: actions/upload-artifact@v4 | |
| name: Store Wiki's CSV and Markdown data as artifact | |
| if: inputs.make_public | |
| with: | |
| compression-level: 6 | |
| path: | | |
| almalinux*.csv | |
| almalinux*.md | |
| name: ${{ env.wiki_data_file }}_wiki_data | |
| - name: Send notification to Mattermost | |
| uses: mattermost/action-mattermost-notify@master | |
| if: inputs.notify_mattermost | |
| with: | |
| MATTERMOST_WEBHOOK_URL: ${{ secrets.MATTERMOST_WEBHOOK_URL }} | |
| MATTERMOST_CHANNEL: ${{ vars.MATTERMOST_CHANNEL }} | |
| MATTERMOST_USERNAME: ${{ github.triggering_actor }} | |
| TEXT: | | |
| **${{ env.AMI_NAME }}** AWS AMI, generated by the GitHub [Action](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| :almalinux: **AMI ID**: `${{ inputs.ami_id }}` | |
| Public: ${{ inputs.make_public && '✅' || '❌'}} |