|
| 1 | +name: Build Ubuntu 18 AMI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + paths: |
| 8 | + - '.github/workflows/ami-build-ubuntu-18.yml' |
| 9 | + - 'common.vars.pkr.hcl' |
| 10 | + |
| 11 | + workflow_run: |
| 12 | + workflows: [Release AMI] |
| 13 | + types: |
| 14 | + - completed |
| 15 | + |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + runs-on: [self-hosted, X64] |
| 21 | + timeout-minutes: 150 |
| 22 | + permissions: |
| 23 | + contents: write |
| 24 | + packages: write |
| 25 | + id-token: write |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout Repo |
| 29 | + uses: actions/checkout@v2 |
| 30 | + |
| 31 | + - name: Build AMI |
| 32 | + run: | |
| 33 | + GIT_SHA=${{github.sha}} |
| 34 | + packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=u18-${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common.vars.pkr.hcl" -var-file="legacy.vars.pkr.hcl" amazon-arm64.pkr.hcl |
| 35 | +
|
| 36 | + - name: Grab release version |
| 37 | + id: process_release_version |
| 38 | + run: | |
| 39 | + VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common.vars.pkr.hcl) |
| 40 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 41 | + |
| 42 | + - name: List files |
| 43 | + id: list_files |
| 44 | + run: | |
| 45 | + ls -la /tmp/ |
| 46 | +
|
| 47 | + - name: configure aws credentials - staging |
| 48 | + uses: aws-actions/configure-aws-credentials@v1 |
| 49 | + with: |
| 50 | + role-to-assume: ${{ secrets.DEV_AWS_ROLE }} |
| 51 | + aws-region: "us-east-1" |
| 52 | + |
| 53 | + - name: Upload pg binaries to s3 staging |
| 54 | + run: | |
| 55 | + aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/18.04.tar.gz |
| 56 | +
|
| 57 | + - name: configure aws credentials - prod |
| 58 | + uses: aws-actions/configure-aws-credentials@v1 |
| 59 | + with: |
| 60 | + role-to-assume: ${{ secrets.PROD_AWS_ROLE }} |
| 61 | + aws-region: "us-east-1" |
| 62 | + |
| 63 | + - name: Upload pg binaries to s3 prod |
| 64 | + run: | |
| 65 | + aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/18.04.tar.gz |
| 66 | +
|
| 67 | + - name: Deregister image |
| 68 | + if: ${{ always() }} |
| 69 | + continue-on-error: true |
| 70 | + run: | |
| 71 | + IMAGE_IDS=$(aws ec2 describe-images --filters "Name=name,Values=builder-supabase-postgres-u18-*" --query "Images[] .ImageId" --output text) |
| 72 | + for IMAGE_ID in $IMAGE_IDS; do |
| 73 | + SNAPSHOTS=$(aws ec2 describe-images --image-ids $IMAGE_ID --query "Images[*].BlockDeviceMappings[*].Ebs.SnapshotId" --output text) |
| 74 | +
|
| 75 | + echo "Deregistering image $IMAGE_ID" |
| 76 | + aws ec2 deregister-image --image-id $IMAGE_ID |
| 77 | +
|
| 78 | + for SNAPSHOT in $SNAPSHOTS; do |
| 79 | + echo "Deleting snapshot $SNAPSHOT" |
| 80 | + aws ec2 delete-snapshot --snapshot-id $SNAPSHOT |
| 81 | + done |
| 82 | + done |
| 83 | +
|
| 84 | + - name: Cleanup resources on build cancellation |
| 85 | + if: ${{ cancelled() }} |
| 86 | + run: | |
| 87 | + aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=u18-${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -I {} aws ec2 terminate-instances --instance-ids {} |
0 commit comments