8
8
paths :
9
9
- ' .github/workflows/ami-release-nix.yml'
10
10
- ' common-nix.vars.pkr.hcl'
11
+ - ' ansible/vars.yml'
11
12
workflow_dispatch :
12
13
13
14
jobs :
15
+ prepare :
16
+ runs-on : ubuntu-latest
17
+ outputs :
18
+ postgres_versions : ${{ steps.set-versions.outputs.postgres_versions }}
19
+ steps :
20
+ - name : Checkout Repo
21
+ uses : actions/checkout@v3
22
+
23
+ - uses : DeterminateSystems/nix-installer-action@main
24
+
25
+ - name : Set PostgreSQL versions
26
+ id : set-versions
27
+ run : |
28
+ VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml | nix run nixpkgs#jq -- -R -s -c 'split("\n")[:-1]')
29
+ echo "postgres_versions=$VERSIONS" >> $GITHUB_OUTPUT
30
+
14
31
build :
32
+ needs : prepare
15
33
strategy :
16
34
matrix :
35
+ postgres_version : ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
17
36
include :
18
37
- runner : arm-runner
19
38
arch : arm64
@@ -31,42 +50,55 @@ jobs:
31
50
- name : Checkout Repo
32
51
uses : actions/checkout@v3
33
52
53
+ - uses : DeterminateSystems/nix-installer-action@main
54
+
34
55
- name : Run checks if triggered manually
35
56
if : ${{ github.event_name == 'workflow_dispatch' }}
36
- # Update `ci.yaml` too if changing constraints.
37
57
run : |
38
- SUFFIX=$(sed -E 's/postgres-version = " [0-9\.]+(.*)" /\1/g' common-nix.vars.pkr.hcl )
58
+ SUFFIX=$(sudo nix run nixpkgs#yq -- ".postgres_release[\"postgres${{ matrix.postgres_version }}\"]" ansible/vars.yml | sed -E 's/[0-9\.]+(.*)$ /\1/' )
39
59
if [[ -z $SUFFIX ]] ; then
40
60
echo "Version must include non-numeric characters if built manually."
41
61
exit 1
42
62
fi
43
63
44
- # extensions are build in nix prior to this step
45
- # so we can just use the binaries from the nix store
46
- # for postgres, extensions and wrappers
64
+ - name : Set PostgreSQL version environment variable
65
+ run : echo "POSTGRES_MAJOR_VERSION=${{ matrix.postgres_version }}" >> $GITHUB_ENV
66
+
67
+ - name : Generate common-nix.vars.pkr.hcl
68
+ run : |
69
+ PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
70
+ PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
71
+ echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
72
+ # Ensure there's a newline at the end of the file
73
+ echo "" >> common-nix.vars.pkr.hcl
47
74
48
75
- name : Build AMI stage 1
76
+ env :
77
+ POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
49
78
run : |
50
79
packer init amazon-arm64-nix.pkr.hcl
51
80
GIT_SHA=${{github.sha}}
52
- 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
81
+ 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=-e postgresql_major=${POSTGRES_MAJOR_VERSION} " amazon-arm64-nix.pkr.hcl
53
82
54
83
- name : Build AMI stage 2
84
+ env :
85
+ POSTGRES_MAJOR_VERSION : ${{ env.POSTGRES_MAJOR_VERSION }}
55
86
run : |
56
87
packer init stage2-nix-psql.pkr.hcl
57
88
GIT_SHA=${{github.sha}}
58
- packer build -var "git_sha=${GIT_SHA}" -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
89
+ POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
90
+ packer build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var "postgres_major_version=${POSTGRES_MAJOR_VERSION}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl
59
91
60
92
- name : Grab release version
61
93
id : process_release_version
62
94
run : |
63
- VERSION=$(sed -e 's/postgres-version = "\(.*\)"/\1/g' common-nix.vars.pkr.hcl )
64
- echo "version=$VERSION" >> " $GITHUB_OUTPUT"
95
+ VERSION=$(cat common-nix.vars.pkr.hcl | sed -e 's/postgres-version = "\(.*\)"/\1/g')
96
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
65
97
66
98
- name : Create nix flake revision tarball
67
99
run : |
68
100
GIT_SHA=${{github.sha}}
69
- MAJOR_VERSION=$(echo "$ {{ steps.process_release_version.outputs.version }}" | cut -d. -f1)
101
+ MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
70
102
71
103
mkdir -p "/tmp/pg_upgrade_bin/${MAJOR_VERSION}"
72
104
echo "$GIT_SHA" >> "/tmp/pg_upgrade_bin/${MAJOR_VERSION}/nix_flake_version"
@@ -84,17 +116,13 @@ jobs:
84
116
ansible-playbook -i localhost \
85
117
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
86
118
-e "internal_artifacts_bucket=${{ secrets.ARTIFACTS_BUCKET }}" \
119
+ -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
87
120
manifest-playbook.yml
88
121
89
122
- name : Upload nix flake revision to s3 staging
90
123
run : |
91
124
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
92
125
93
- # Our self hosted github runner already has permissions to publish images
94
- # but they're limited to only that;
95
- # so if we want s3 access we'll need to config credentials with the below steps
96
- # (which overwrites existing perms) after the ami build
97
-
98
126
- name : configure aws credentials - prod
99
127
uses : aws-actions/configure-aws-credentials@v4
100
128
with :
@@ -107,6 +135,7 @@ jobs:
107
135
ansible-playbook -i localhost \
108
136
-e "ami_release_version=${{ steps.process_release_version.outputs.version }}" \
109
137
-e "internal_artifacts_bucket=${{ secrets.PROD_ARTIFACTS_BUCKET }}" \
138
+ -e "postgres_major_version=${{ env.POSTGRES_MAJOR_VERSION }}" \
110
139
manifest-playbook.yml
111
140
112
141
- name : Upload nix flake revision to s3 prod
@@ -130,12 +159,12 @@ jobs:
130
159
SLACK_MESSAGE : ' Building Postgres AMI failed'
131
160
SLACK_FOOTER : ' '
132
161
133
- - name : Cleanup resources on build cancellation
162
+ - name : Cleanup resources after build
134
163
if : ${{ always() }}
135
164
run : |
136
- 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 {}
165
+ aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids
137
166
138
167
- name : Cleanup resources on build cancellation
139
168
if : ${{ cancelled() }}
140
169
run : |
141
- 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 {}
170
+ aws ec2 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --instance-ids
0 commit comments