Skip to content

Commit da69a37

Browse files
authored
feat: source specific version of packer and build with specific go (#1735)
* feat: source specific version of packer and build with specific go use in all workflows * fix: add package to checks to assure it is tested, built cached prior to use * fix: try to use nix shell to settle permission issue * fix: install packer with nix in profile within workflow * fix: use sudo on packer calls * fix: trying skip regiona validation for now * fix: use cachix installer with cache config * fix: try to fix perms and use non-sudo * fix: assure nix version we need is installed at this stage + perm fix * fix: see how nix was installed on this machine originally * fix: for now keep nix and inherit env * fix: use large-linux-arm here going forward * fix: try remove job level perms * fix: match permissions on ami-release * tests: debug role * fix: allows workflow to recv secret when called from other workflows * fix: receive the secret as a parameter * fix: no need for sudo * chore: revert qemu workflow/do not change packer handling there * docs: updating deps doc * chore: tmp suffix to test release * chore: restore versions post testing
1 parent f75ac46 commit da69a37

File tree

11 files changed

+216
-27
lines changed

11 files changed

+216
-27
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ jobs:
4040
run: |
4141
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
4242
43-
- uses: DeterminateSystems/nix-installer-action@main
43+
- name: Install nix
44+
uses: cachix/install-nix-action@v27
45+
with:
46+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
47+
extra_nix_config: |
48+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
49+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
4450
4551
- name: Set PostgreSQL version environment variable
4652
run: echo "POSTGRES_MAJOR_VERSION=${{ github.event.inputs.postgres_version }}" >> $GITHUB_ENV
@@ -57,18 +63,18 @@ jobs:
5763
env:
5864
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
5965
run: |
60-
packer init amazon-arm64-nix.pkr.hcl
6166
GIT_SHA=${{ steps.get_sha.outputs.sha }}
62-
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
67+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
68+
nix run github:supabase/postgres/${GIT_SHA}#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
6369
6470
- name: Build AMI stage 2
6571
env:
6672
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
6773
run: |
68-
packer init stage2-nix-psql.pkr.hcl
6974
GIT_SHA=${{ steps.get_sha.outputs.sha }}
75+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
7076
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
71-
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
77+
nix run github:supabase/postgres/${GIT_SHA}#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
7278
7379
- name: Grab release version
7480
id: process_release_version

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ jobs:
2424
- name: Checkout Repo
2525
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
2626

27-
- uses: DeterminateSystems/nix-installer-action@main
27+
- name: Install nix
28+
uses: cachix/install-nix-action@v27
29+
with:
30+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
31+
extra_nix_config: |
32+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
33+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2834
2935
- name: Set PostgreSQL versions
3036
id: set-versions
@@ -52,7 +58,14 @@ jobs:
5258
aws-region: "us-east-1"
5359
output-credentials: true
5460
role-duration-seconds: 7200
55-
- uses: DeterminateSystems/nix-installer-action@main
61+
62+
- name: Install nix
63+
uses: cachix/install-nix-action@v27
64+
with:
65+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
66+
extra_nix_config: |
67+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
68+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
5669
5770
- name: Run checks if triggered manually
5871
if: ${{ github.event_name == 'workflow_dispatch' }}
@@ -78,19 +91,19 @@ jobs:
7891
env:
7992
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
8093
run: |
81-
packer init amazon-arm64-nix.pkr.hcl
8294
GIT_SHA=${{github.sha}}
95+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
8396
# why is postgresql_major defined here instead of where the _three_ other postgresql_* variables are defined?
84-
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
97+
nix run github:supabase/postgres/${GIT_SHA}#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
8598
8699
- name: Build AMI stage 2
87100
env:
88101
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
89102
run: |
90-
packer init stage2-nix-psql.pkr.hcl
91103
GIT_SHA=${{github.sha}}
104+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
92105
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
93-
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
106+
nix run github:supabase/postgres/${GIT_SHA}#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
94107
95108
- name: Grab release version
96109
id: process_release_version

.github/workflows/nix-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ jobs:
118118
needs: build-run-image
119119
if: ${{ success() }}
120120
uses: ./.github/workflows/testinfra-ami-build.yml
121+
secrets:
122+
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}
121123

122124
run-tests:
123125
needs: build-run-image

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

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ name: Testinfra Integration Tests Nix
33
on:
44
workflow_dispatch:
55
workflow_call:
6+
secrets:
7+
DEV_AWS_ROLE:
8+
description: 'AWS role for dev environment'
9+
required: true
610

711
permissions:
8-
contents: read
12+
contents: write
913
id-token: write
1014

1115
jobs:
@@ -17,7 +21,13 @@ jobs:
1721
- name: Checkout Repo
1822
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
1923

20-
- uses: DeterminateSystems/nix-installer-action@main
24+
- name: Install nix
25+
uses: cachix/install-nix-action@v27
26+
with:
27+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
28+
extra_nix_config: |
29+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
30+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
2131
2232
- name: Set PostgreSQL versions
2333
id: set-versions
@@ -32,22 +42,44 @@ jobs:
3242
matrix:
3343
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
3444
include:
35-
- runner: arm-runner
45+
- runner: large-linux-arm
3646
arch: arm64
3747
ubuntu_release: noble
3848
ubuntu_version: 24.04
3949
mcpu: neoverse-n1
4050
runs-on: ${{ matrix.runner }}
4151
timeout-minutes: 150
42-
permissions:
43-
contents: write
44-
packages: write
45-
id-token: write
4652

4753
steps:
4854
- name: Checkout Repo
4955
uses: supabase/postgres/.github/actions/shared-checkout@HEAD
5056

57+
- name: Debug AWS role secret
58+
run: |
59+
echo "Checking DEV_AWS_ROLE secret availability..."
60+
if [ -z "${{ secrets.DEV_AWS_ROLE }}" ]; then
61+
echo "❌ DEV_AWS_ROLE is empty or not available"
62+
else
63+
echo "✅ DEV_AWS_ROLE is available"
64+
fi
65+
66+
- name: Configure AWS credentials
67+
uses: aws-actions/configure-aws-credentials@v4
68+
with:
69+
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
70+
aws-region: "us-east-1"
71+
output-credentials: true
72+
role-duration-seconds: 7200
73+
74+
- name: Install nix
75+
uses: cachix/install-nix-action@v27
76+
with:
77+
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
78+
extra_nix_config: |
79+
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
80+
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
81+
82+
5183
- id: args
5284
uses: mikefarah/yq@master
5385
with:
@@ -68,23 +100,23 @@ jobs:
68100

69101
- name: Generate common-nix.vars.pkr.hcl
70102
run: |
71-
PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
103+
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
72104
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
73105
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
74106
# Ensure there's a newline at the end of the file
75107
echo "" >> common-nix.vars.pkr.hcl
76108
77109
- name: Build AMI stage 1
78110
run: |
79-
packer init amazon-arm64-nix.pkr.hcl
80111
GIT_SHA=${{github.sha}}
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=" -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
112+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
113+
nix run github:supabase/postgres/${GIT_SHA}#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=" -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
82114
83115
- name: Build AMI stage 2
84116
run: |
85-
packer init stage2-nix-psql.pkr.hcl
86117
GIT_SHA=${{github.sha}}
87-
packer build -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" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "git_sha=${GITHUB_SHA}" stage2-nix-psql.pkr.hcl
118+
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
119+
nix run github:supabase/postgres/${GIT_SHA}#packer -- build -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" -var "postgres-version=${{ steps.random.outputs.random_string }}" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" -var "git_sha=${GITHUB_SHA}" stage2-nix-psql.pkr.hcl
88120
89121
- name: Run tests
90122
timeout-minutes: 10

flake.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
1414
git-hooks.url = "github:cachix/git-hooks.nix";
1515
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
16+
nixpkgs-go124.url = "github:Nixos/nixpkgs/d2ac4dfa61fba987a84a0a81555da57ae0b9a2b0";
1617
};
1718

1819
outputs =

nix/checks.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
wal-g-2
295295
wal-g-3
296296
dbmate-tool
297+
packer
297298
pg_regress
298299
;
299300
}

nix/devShells.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
shellcheck
4646
ansible
4747
ansible-lint
48-
(packer.overrideAttrs (_oldAttrs: {
49-
version = "1.7.8";
50-
}))
48+
self'.packages.packer
5149

5250
self'.packages.start-server
5351
self'.packages.start-client

nix/docs/updating-dependencies.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Updating Dependencies
2+
3+
This document explains how to update various dependencies used in the nix configuration.
4+
5+
## Updating Packer
6+
7+
Packer is used for creating machine images and is defined in `nix/packages/packer.nix`.
8+
9+
### Steps to update Packer version:
10+
11+
1. Create a branch off of `develop`
12+
2. Navigate to `nix/packages/packer.nix`
13+
3. Update the version field:
14+
```nix
15+
version = "1.15.0"; # Update to desired version
16+
```
17+
4. Update the git revision to match the new version:
18+
```nix
19+
rev = "v${version}";
20+
```
21+
5. Temporarily clear the hash to get the new SHA256:
22+
```nix
23+
hash = ""; # Clear this temporarily
24+
```
25+
6. Save the file and run:
26+
```bash
27+
nix build .#packer
28+
```
29+
7. Nix will fail and output the correct SHA256 hash. Copy this hash and update the file:
30+
```nix
31+
hash = "sha256-NEWHASHHEREFROMBUILDOUTPUT";
32+
```
33+
8. Update the vendorHash if needed. If the build fails due to vendor hash mismatch, temporarily set:
34+
```nix
35+
vendorHash = ""; # Clear this temporarily
36+
```
37+
9. Run `nix build .#packer` again to get the correct vendorHash, then update:
38+
```nix
39+
vendorHash = "sha256-NEWVENDORHASHHEREFROMBUILDOUTPUT";
40+
```
41+
10. Verify the build works:
42+
```bash
43+
nix build .#packer
44+
```
45+
11. Test the packer binary:
46+
```bash
47+
./result/bin/packer version
48+
```
49+
12. Run the full test suite to ensure nothing is broken:
50+
```bash
51+
nix flake check -L
52+
```
53+
13. Commit your changes and create a PR for review
54+
14. Update any CI/CD workflows or documentation that reference the old Packer version
55+
56+
### Notes:
57+
- Always check the [Packer changelog](https://github.com/hashicorp/packer/releases) for breaking changes
58+
- Packer uses Go, so ensure compatibility with the Go version specified in the flake inputs
59+
- The current Go version is specified in `flake.nix` under `nixpkgs-go124` input
60+
- If updating to a major version, test all packer templates (`.pkr.hcl` files) in the repository
61+
62+
## Updating Other Dependencies
63+
64+
Similar patterns can be followed for other dependencies defined in the nix packages. Always:
65+
1. Check for breaking changes in changelogs
66+
2. Update version numbers and hashes
67+
3. Run local tests
68+
4. Verify functionality before creating PR

nix/packages/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ self, ... }:
1+
{ self, inputs, ... }:
22
{
33
imports = [ ./postgres.nix ];
44
perSystem =
@@ -37,6 +37,7 @@
3737
supabase-groonga = pkgs.callPackage ./groonga { };
3838
local-infra-bootstrap = pkgs.callPackage ./local-infra-bootstrap.nix { };
3939
migrate-tool = pkgs.callPackage ./migrate-tool.nix { psql_15 = self'.packages."psql_15/bin"; };
40+
packer = pkgs.callPackage ./packer.nix { inherit inputs; };
4041
pg-restore = pkgs.callPackage ./pg-restore.nix { psql_15 = self'.packages."psql_15/bin"; };
4142
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
4243
pg_regress = makePgRegress activeVersion;

0 commit comments

Comments
 (0)