Skip to content

Commit c5b932e

Browse files
committed
feat: move stage 1 to nightly build
1 parent afea09d commit c5b932e

File tree

9 files changed

+108
-36
lines changed

9 files changed

+108
-36
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ jobs:
6161
# Ensure there's a newline at the end of the file
6262
echo "" >> common-nix.vars.pkr.hcl
6363
64-
- name: Build AMI stage 1
65-
env:
66-
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
67-
run: |
68-
GIT_SHA=${{ steps.get_sha.outputs.sha }}
69-
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
70-
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_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
71-
7264
- name: Build AMI stage 2
7365
env:
7466
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ jobs:
8989
# Ensure there's a newline at the end of the file
9090
echo "" >> common-nix.vars.pkr.hcl
9191
92-
- name: Build AMI stage 1
93-
env:
94-
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
95-
run: |
96-
GIT_SHA=${{github.sha}}
97-
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
98-
# why is postgresql_major defined here instead of where the _three_ other postgresql_* variables are defined?
99-
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" -var "region=us-east-1" -var 'ami_regions=["us-east-1"]' amazon-arm64-nix.pkr.hcl
100-
10192
- name: Build AMI stage 2
10293
env:
10394
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build Base Image Nightly
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * *' # 2 AM UTC daily
6+
workflow_dispatch:
7+
inputs:
8+
branch:
9+
description: 'Branch to build from'
10+
required: false
11+
default: 'develop'
12+
type: string
13+
14+
permissions:
15+
contents: read
16+
id-token: write
17+
18+
jobs:
19+
build-base-image:
20+
runs-on: blacksmith-4vcpu-ubuntu-2404-arm
21+
timeout-minutes: 150
22+
23+
steps:
24+
- name: Checkout Repo
25+
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
26+
with:
27+
ref: ${{ github.event.inputs.branch || 'develop' }}
28+
29+
- name: Configure AWS credentials
30+
uses: aws-actions/configure-aws-credentials@v4
31+
with:
32+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
33+
aws-region: "us-east-1"
34+
output-credentials: true
35+
role-duration-seconds: 7200
36+
37+
- name: Install nix
38+
uses: cachix/install-nix-action@v27
39+
with:
40+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
41+
extra_nix_config: |
42+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
43+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
44+
45+
- name: Set execution ID and timestamp
46+
run: |
47+
echo "EXECUTION_ID=${{ github.run_id }}-base-nightly" >> $GITHUB_ENV
48+
echo "BUILD_TIMESTAMP=$(date -u +%Y%m%d-%H%M%S)" >> $GITHUB_ENV
49+
50+
- name: Build base stage 1 AMI
51+
env:
52+
AWS_MAX_ATTEMPTS: 10
53+
AWS_RETRY_MODE: adaptive
54+
run: |
55+
GIT_SHA=${{ github.sha }}
56+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
57+
nix run github:supabase/postgres/${GIT_SHA}#packer -- build \
58+
-var "git-head-version=${GIT_SHA}" \
59+
-var "packer-execution-id=${EXECUTION_ID}" \
60+
-var-file="development-arm.vars.pkr.hcl" \
61+
-var "base-image-nightly=true" \
62+
-var "build-timestamp=${BUILD_TIMESTAMP}" \
63+
-var "region=us-east-1" \
64+
-var 'ami_regions=["us-east-1","ap-southeast-1"]' \
65+
amazon-arm64-nix.pkr.hcl
66+
67+
- name: Slack Notification on Failure
68+
if: ${{ failure() }}
69+
uses: rtCamp/action-slack-notify@v2
70+
env:
71+
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
72+
SLACK_USERNAME: 'gha-failures-notifier'
73+
SLACK_COLOR: 'danger'
74+
SLACK_MESSAGE: 'Building base image nightly failed'
75+
SLACK_FOOTER: ''
76+
77+
- name: Cleanup resources after build
78+
if: ${{ always() }}
79+
run: |
80+
aws ec2 --region us-east-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${EXECUTION_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --region us-east-1 --instance-ids
81+
82+
- name: Cleanup resources on build cancellation
83+
if: ${{ cancelled() }}
84+
run: |
85+
aws ec2 --region us-east-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${EXECUTION_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -r aws ec2 terminate-instances --region us-east-1 --instance-ids

.github/workflows/testinfra-ami-build.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ jobs:
108108
# Ensure there's a newline at the end of the file
109109
echo "" >> common-nix.vars.pkr.hcl
110110
111-
- name: Build AMI stage 1
112-
env:
113-
AWS_MAX_ATTEMPTS: 10
114-
AWS_RETRY_MODE: adaptive
115-
run: |
116-
GIT_SHA=${{github.sha}}
117-
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
118-
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${EXECUTION_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "ansible_arguments=-e postgresql_major=${POSTGRES_MAJOR_VERSION}" amazon-arm64-nix.pkr.hcl
119-
120111
- name: Build AMI stage 2
121112
env:
122113
AWS_MAX_ATTEMPTS: 10

amazon-arm64-nix.pkr.hcl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ variable "force-deregister" {
9292
default = false
9393
}
9494

95+
variable "base-image-nightly" {
96+
type = bool
97+
default = false
98+
description = "Build as version-agnostic base image for nightly"
99+
}
100+
101+
variable "build-timestamp" {
102+
type = string
103+
default = ""
104+
description = "Timestamp for nightly builds"
105+
}
106+
95107
packer {
96108
required_plugins {
97109
amazon = {
@@ -106,7 +118,7 @@ source "amazon-ebssurrogate" "source" {
106118
profile = "${var.profile}"
107119
#access_key = "${var.aws_access_key}"
108120
#ami_name = "${var.ami_name}-arm64-${formatdate("YYYY-MM-DD-hhmm", timestamp())}"
109-
ami_name = "${var.ami_name}-${var.postgres-version}-stage-1"
121+
ami_name = var.base-image-nightly ? "${var.ami_name}-base-stage-1-nightly" : "${var.ami_name}-${var.postgres-version}-stage-1"
110122
ami_virtualization_type = "hvm"
111123
ami_architecture = "arm64"
112124
ami_regions = "${var.ami_regions}"
@@ -170,8 +182,10 @@ source "amazon-ebssurrogate" "source" {
170182
tags = {
171183
creator = "packer"
172184
appType = "postgres"
173-
postgresVersion = "${var.postgres-version}-stage1"
185+
postgresVersion = var.base-image-nightly ? "base-nightly" : "${var.postgres-version}-stage1"
174186
sourceSha = "${var.git-head-version}"
187+
buildTimestamp = var.base-image-nightly ? "${var.build-timestamp}" : ""
188+
buildType = var.base-image-nightly ? "nightly" : "release"
175189
}
176190

177191
communicator = "ssh"

ansible/playbook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
- install-gotrue
4747
- install-supabase-internal
4848
when: debpkg_mode or nixpkg_mode
49-
49+
5050
- name: Install PostgREST
5151
import_tasks: tasks/setup-postgrest.yml
5252
tags:
5353
- install-postgrest
5454
- install-supabase-internal
55-
when: debpkg_mode or nixpkg_mode
55+
when: debpkg_mode or stage2_nix
5656

5757
- name: Install Envoy
5858
import_tasks: tasks/setup-envoy.yml

ansible/tasks/setup-postgrest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- name: PostgREST - add Postgres PPA main
1212
ansible.builtin.apt_repository:
1313
filename: 'postgresql-pgdg'
14-
repo: "deb http://apt.postgresql.org/pub/repos/apt/ noble-pgdg {{ postgresql_major }}"
14+
repo: "deb http://apt.postgresql.org/pub/repos/apt/ noble-pgdg main"
1515
state: 'present'
1616

1717
- name: PostgREST - install system dependencies
@@ -36,7 +36,7 @@
3636

3737
- name: PostgREST - remove Postgres PPA
3838
ansible.builtin.apt_repository:
39-
repo: "deb http://apt.postgresql.org/pub/repos/apt/ noble-pgdg {{ postgresql_major }}"
39+
repo: "deb http://apt.postgresql.org/pub/repos/apt/ noble-pgdg main"
4040
state: 'absent'
4141

4242
- name: postgis - ensure dependencies do not get autoremoved

ebssurrogate/scripts/surrogate-bootstrap-nix.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,10 @@ tee /etc/ansible/ansible.cfg <<EOF
303303
callbacks_enabled = timer, profile_tasks, profile_roles
304304
EOF
305305
# Run Ansible playbook
306-
#export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_DEBUG=True && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
306+
#export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_DEBUG=True && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
307307
export ANSIBLE_LOG_PATH=/tmp/ansible.log && export ANSIBLE_REMOTE_TEMP=/mnt/tmp
308308
ansible-playbook -c chroot -i '/mnt,' /tmp/ansible-playbook/ansible/playbook.yml \
309309
--extra-vars '{"nixpkg_mode": true, "debpkg_mode": false, "stage2_nix": false} ' \
310-
--extra-vars "psql_version=psql_${POSTGRES_MAJOR_VERSION}" \
311310
$ARGS
312311
}
313312

stage2-nix-psql.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ source "amazon-ebs" "ubuntu" {
6666
region = "${var.region}"
6767
source_ami_filter {
6868
filters = {
69-
name = "${var.ami_name}-${var.postgres-version}-stage-1"
69+
name = "${var.ami_name}-base-stage-1-nightly"
7070
root-device-type = "ebs"
7171
virtualization-type = "hvm"
7272
}
7373
most_recent = true
74-
owners = ["amazon", "self"]
74+
owners = ["self"]
7575
}
7676

7777
communicator = "ssh"

0 commit comments

Comments
 (0)