|
| 1 | +name: Release AMI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + paths: |
| 8 | + - '.github/workflows/ami-release-nix.yml' |
| 9 | + - 'common-nix.vars.pkr.hcl' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + include: |
| 17 | + - runner: arm-runner |
| 18 | + arch: arm64 |
| 19 | + ubuntu_release: focal |
| 20 | + ubuntu_version: 20.04 |
| 21 | + mcpu: neoverse-n1 |
| 22 | + runs-on: ${{ matrix.runner }} |
| 23 | + timeout-minutes: 150 |
| 24 | + permissions: |
| 25 | + contents: write |
| 26 | + packages: write |
| 27 | + id-token: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout Repo |
| 31 | + uses: actions/checkout@v3 |
| 32 | + |
| 33 | + - name: Run checks if triggered manually |
| 34 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 35 | + # Update `ci.yaml` too if changing constraints. |
| 36 | + run: | |
| 37 | + SUFFIX=$(sed -E 's/postgres-version = "[0-9\.]+(.*)"/\1/g' common-nix.vars.pkr.hcl) |
| 38 | + if [[ -z $SUFFIX ]] ; then |
| 39 | + echo "Version must include non-numeric characters if built manually." |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + # - id: args |
| 44 | + # uses: mikefarah/yq@master |
| 45 | + # with: |
| 46 | + # cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml' |
| 47 | + # - run: docker context create builders |
| 48 | + # - uses: docker/setup-buildx-action@v3 |
| 49 | + # with: |
| 50 | + # endpoint: builders |
| 51 | + # - uses: docker/build-push-action@v5 |
| 52 | + # with: |
| 53 | + # build-args: | |
| 54 | + # ${{ steps.args.outputs.result }} |
| 55 | + # target: extensions |
| 56 | + # tags: supabase/postgres:extensions |
| 57 | + # platforms: linux/${{ matrix.arch }} |
| 58 | + # outputs: type=tar,dest=/tmp/extensions.tar |
| 59 | + # cache-from: type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }} |
| 60 | + # # No need to export extensions cache because latest depends on it |
| 61 | + |
| 62 | + # - name: Extract built packages |
| 63 | + # run: | |
| 64 | + # mkdir -p ansible/files/extensions |
| 65 | + # tar xvf /tmp/extensions.tar -C ansible/files/extensions --strip-components 1 |
| 66 | + # TODO remove this block as extensions are build in nix prior to this step |
| 67 | + |
| 68 | + - id: version |
| 69 | + run: echo "${{ steps.args.outputs.result }}" | grep "postgresql" >> "$GITHUB_OUTPUT" |
| 70 | + - name: Build Postgres deb |
| 71 | + uses: docker/build-push-action@v5 |
| 72 | + with: |
| 73 | + file: docker/Dockerfile |
| 74 | + target: pg-deb |
| 75 | + build-args: | |
| 76 | + ubuntu_release=${{ matrix.ubuntu_release }} |
| 77 | + ubuntu_release_no=${{ matrix.ubuntu_version }} |
| 78 | + postgresql_major=${{ steps.version.outputs.postgresql_major }} |
| 79 | + postgresql_release=${{ steps.version.outputs.postgresql_release }} |
| 80 | + CPPFLAGS=-mcpu=${{ matrix.mcpu }} |
| 81 | + tags: supabase/postgres:deb |
| 82 | + platforms: linux/${{ matrix.arch }} |
| 83 | + outputs: type=tar,dest=/tmp/pg-deb.tar |
| 84 | + cache-from: type=gha,scope=${{ github.ref_name }}-deb |
| 85 | + cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-deb |
| 86 | + # - name: Extract Postgres deb |
| 87 | + # run: | |
| 88 | + # mkdir -p ansible/files/postgres |
| 89 | + # tar xvf /tmp/pg-deb.tar -C ansible/files/postgres --strip-components 1 |
| 90 | + #TODO remove this block as deb is build in nix prior to this step |
| 91 | + |
| 92 | + - name: Build AMI stage 1 |
| 93 | + run: | |
| 94 | + packer init amazon-arm64-nix.pkr.hcl |
| 95 | + GIT_SHA=${{github.sha}} |
| 96 | + packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=" amazon-arm64-nix.pkr.hcl |
| 97 | +
|
| 98 | + - name: Build AMI stage 1 |
| 99 | + run: | |
| 100 | + packer init amazon-arm64-nix.pkr.hcl |
| 101 | + GIT_SHA=${{github.sha}} |
| 102 | + packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=" amazon-arm64-nix.pkr.hcl |
| 103 | + |
| 104 | + - name: Grab release version |
| 105 | + id: process_release_version |
| 106 | + run: | |
| 107 | + VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common-nix.vars.pkr.hcl) |
| 108 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 109 | +
|
| 110 | + - name: configure aws credentials - staging |
| 111 | + uses: aws-actions/configure-aws-credentials@v1 |
| 112 | + with: |
| 113 | + role-to-assume: ${{ secrets.DEV_AWS_ROLE }} |
| 114 | + aws-region: "us-east-1" |
| 115 | + |
| 116 | + - name: Upload software manifest to s3 staging |
| 117 | + run: | |
| 118 | + cd ansible |
| 119 | + ansible-playbook -i localhost \ |
| 120 | + -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \ |
| 121 | + -e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \ |
| 122 | + manifest-playbook.yml |
| 123 | +
|
| 124 | + # - name: Upload pg binaries to s3 staging |
| 125 | + # run: | |
| 126 | + # aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz |
| 127 | + # #TODO look to see if this only pg binaries and if so, remove this as it is covered by nix build |
| 128 | + # TODO deactivate this block to assure binaries from this file are not uploaded. This is covered by nix build |
| 129 | + - name: configure aws credentials - prod |
| 130 | + uses: aws-actions/configure-aws-credentials@v1 |
| 131 | + with: |
| 132 | + role-to-assume: ${{ secrets.PROD_AWS_ROLE }} |
| 133 | + aws-region: "us-east-1" |
| 134 | + |
| 135 | + - name: Upload software manifest to s3 prod |
| 136 | + run: | |
| 137 | + cd ansible |
| 138 | + ansible-playbook -i localhost \ |
| 139 | + -e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \ |
| 140 | + -e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \ |
| 141 | + manifest-playbook.yml |
| 142 | +
|
| 143 | + # - name: Upload pg binaries to s3 prod |
| 144 | + # run: | |
| 145 | + # aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz |
| 146 | + #TODO deactivate this block to assure binaries from this file are not uploaded. This is covered by nix build |
| 147 | + |
| 148 | + |
| 149 | + - name: Create release |
| 150 | + uses: softprops/action-gh-release@v1 |
| 151 | + with: |
| 152 | + name: ${{ steps.process_release_version.outputs.version }} |
| 153 | + tag_name: ${{ steps.process_release_version.outputs.version }} |
| 154 | + target_commitish: ${{github.sha}} |
| 155 | + |
| 156 | + - name: Slack Notification on Failure |
| 157 | + if: ${{ failure() }} |
| 158 | + uses: rtCamp/action-slack-notify@v2 |
| 159 | + env: |
| 160 | + SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }} |
| 161 | + SLACK_USERNAME: 'gha-failures-notifier' |
| 162 | + SLACK_COLOR: 'danger' |
| 163 | + SLACK_MESSAGE: 'Building Postgres AMI failed' |
| 164 | + SLACK_FOOTER: '' |
| 165 | + |
| 166 | + - name: Cleanup resources on build cancellation |
| 167 | + if: ${{ cancelled() }} |
| 168 | + run: | |
| 169 | + aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -n 1 -I {} aws ec2 terminate-instances --instance-ids {} |
0 commit comments