Skip to content

Commit 76f6606

Browse files
committed
feat: tying up loose ends on the creation and deployment to staging
of the 2 stage ami
1 parent feadaad commit 76f6606

File tree

2 files changed

+65
-30
lines changed

2 files changed

+65
-30
lines changed

.github/workflows/ami-release-nix.yml

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,28 @@ jobs:
6767

6868
- id: version
6969
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
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
8686
# - name: Extract Postgres deb
8787
# run: |
8888
# mkdir -p ansible/files/postgres
8989
# tar xvf /tmp/pg-deb.tar -C ansible/files/postgres --strip-components 1
9090
#TODO remove this block as deb is build in nix prior to this step
9191

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
10392

10493
- name: Grab release version
10594
id: process_release_version
@@ -108,7 +97,7 @@ jobs:
10897
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
10998
11099
- name: configure aws credentials - staging
111-
uses: aws-actions/configure-aws-credentials@v1
100+
uses: aws-actions/configure-aws-credentials@v4
112101
with:
113102
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
114103
aws-region: "us-east-1"
@@ -127,7 +116,7 @@ jobs:
127116
# #TODO look to see if this only pg binaries and if so, remove this as it is covered by nix build
128117
# TODO deactivate this block to assure binaries from this file are not uploaded. This is covered by nix build
129118
- name: configure aws credentials - prod
130-
uses: aws-actions/configure-aws-credentials@v1
119+
uses: aws-actions/configure-aws-credentials@v4
131120
with:
132121
role-to-assume: ${{ secrets.PROD_AWS_ROLE }}
133122
aws-region: "us-east-1"
@@ -140,6 +129,32 @@ jobs:
140129
-e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
141130
manifest-playbook.yml
142131
132+
- name: Build AMI stage 1
133+
run: |
134+
packer init amazon-arm64-nix.pkr.hcl
135+
GIT_SHA=${{github.sha}}
136+
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
137+
138+
- name: Set Environment Variables
139+
id: set-env-vars
140+
run: |
141+
POSTGRES_VERSION=$(grep -oP '(?<=postgres-version = ").*(?=")' common-nix.vars.pkr.hcl)
142+
echo "::set-output name=postgres-version::$POSTGRES_VERSION"
143+
144+
- name: Get AMI Owner
145+
id: get-ami-owner
146+
run: |
147+
POSTGRES_VERSION="${{ steps.set-env-vars.outputs.postgres-version }}"
148+
AMI_NAME="supabase-postgres-$POSTGRES_VERSION-stage-1"
149+
OWNER=$(aws ec2 describe-images --filters "Name=name,Values=$AMI_NAME" "Name=state,Values=available" --query 'Images[].OwnerId' --output text)
150+
echo "::set-output name=ami-owner::$OWNER"
151+
152+
- name: Build AMI stage 2
153+
run: |
154+
packer init stage2-nix-psql.pkr.hcl
155+
GIT_SHA=${{github.sha}}
156+
packer build -var "ami-owner-id=${OWNER}" -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" stage2-nix-psql.pkr.hcl
157+
143158
# - name: Upload pg binaries to s3 prod
144159
# run: |
145160
# 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

stage2-nix-psql.pkr.hcl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ variable "postgres-version" {
2727
default = ""
2828
}
2929

30+
variable "git-head-version" {
31+
type = string
32+
default = "unknown"
33+
}
34+
35+
variable "packer-execution-id" {
36+
type = string
37+
default = "unknown"
38+
}
39+
40+
variable "force-deregister" {
41+
type = bool
42+
default = false
43+
}
44+
45+
variable "ami-owner-id" {
46+
type = string
47+
default = ""
48+
}
49+
3050
packer {
3151
required_plugins {
3252
amazon = {
@@ -47,7 +67,7 @@ source "amazon-ebs" "ubuntu" {
4767
virtualization-type = "hvm"
4868
}
4969
most_recent = true
50-
owners = ["194568623217"]
70+
owners = ["${var.ami-owner-id}"]
5171
}
5272
ssh_username = "ubuntu"
5373
ena_support = true

0 commit comments

Comments
 (0)