Skip to content

feat: source specific version of packer and build with specific go #1735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c60b436
feat: source specific version of packer and build with specific go
samrose Aug 6, 2025
383b3e0
fix: add package to checks to assure it is tested, built cached prior…
samrose Aug 6, 2025
8930cd4
fix: try to use nix shell to settle permission issue
samrose Aug 6, 2025
a3c3591
fix: install packer with nix in profile within workflow
samrose Aug 6, 2025
f9638c5
fix: use sudo on packer calls
samrose Aug 6, 2025
6fceca5
fix: trying skip regiona validation for now
samrose Aug 6, 2025
f825a9b
fix: use cachix installer with cache config
samrose Aug 6, 2025
aca4752
fix: try to fix perms and use non-sudo
samrose Aug 6, 2025
893836e
fix: assure nix version we need is installed at this stage + perm fix
samrose Aug 6, 2025
d73fb5f
fix: see how nix was installed on this machine originally
samrose Aug 6, 2025
34497ce
fix: for now keep nix and inherit env
samrose Aug 6, 2025
325faa4
fix: use large-linux-arm here going forward
samrose Aug 6, 2025
b0bf927
fix: try remove job level perms
samrose Aug 6, 2025
29f9780
fix: match permissions on ami-release
samrose Aug 6, 2025
91d8b31
tests: debug role
samrose Aug 6, 2025
c20a2ff
fix: allows workflow to recv secret when called from other workflows
samrose Aug 7, 2025
9770041
fix: receive the secret as a parameter
samrose Aug 7, 2025
109b062
fix: no need for sudo
samrose Aug 7, 2025
792223e
chore: revert qemu workflow/do not change packer handling there
samrose Aug 7, 2025
4f69e1e
docs: updating deps doc
samrose Aug 7, 2025
fa5f66c
chore: tmp suffix to test release
samrose Aug 7, 2025
8889edc
chore: restore versions post testing
samrose Aug 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/ami-release-nix-single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ jobs:
run: |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

- uses: DeterminateSystems/nix-installer-action@main
- name: Install nix
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
extra_nix_config: |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

- name: Set PostgreSQL version environment variable
run: echo "POSTGRES_MAJOR_VERSION=${{ github.event.inputs.postgres_version }}" >> $GITHUB_ENV
Expand All @@ -57,18 +63,18 @@ jobs:
env:
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
run: |
packer init amazon-arm64-nix.pkr.hcl
GIT_SHA=${{ steps.get_sha.outputs.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
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
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

- name: Build AMI stage 2
env:
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
run: |
packer init stage2-nix-psql.pkr.hcl
GIT_SHA=${{ steps.get_sha.outputs.sha }}
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
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
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

- name: Grab release version
id: process_release_version
Expand Down
25 changes: 19 additions & 6 deletions .github/workflows/ami-release-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ jobs:
- name: Checkout Repo
uses: supabase/postgres/.github/actions/shared-checkout@HEAD

- uses: DeterminateSystems/nix-installer-action@main
- name: Install nix
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
extra_nix_config: |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

- name: Set PostgreSQL versions
id: set-versions
Expand Down Expand Up @@ -52,7 +58,14 @@ jobs:
aws-region: "us-east-1"
output-credentials: true
role-duration-seconds: 7200
- uses: DeterminateSystems/nix-installer-action@main

- name: Install nix
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
extra_nix_config: |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

- name: Run checks if triggered manually
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand All @@ -78,19 +91,19 @@ jobs:
env:
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
run: |
packer init amazon-arm64-nix.pkr.hcl
GIT_SHA=${{github.sha}}
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
# why is postgresql_major defined here instead of where the _three_ other postgresql_* variables are defined?
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
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

- name: Build AMI stage 2
env:
POSTGRES_MAJOR_VERSION: ${{ env.POSTGRES_MAJOR_VERSION }}
run: |
packer init stage2-nix-psql.pkr.hcl
GIT_SHA=${{github.sha}}
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
POSTGRES_MAJOR_VERSION=${{ env.POSTGRES_MAJOR_VERSION }}
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
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

- name: Grab release version
id: process_release_version
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ jobs:
needs: build-run-image
if: ${{ success() }}
uses: ./.github/workflows/testinfra-ami-build.yml
secrets:
DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }}

run-tests:
needs: build-run-image
Expand Down
56 changes: 44 additions & 12 deletions .github/workflows/testinfra-ami-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ name: Testinfra Integration Tests Nix
on:
workflow_dispatch:
workflow_call:
secrets:
DEV_AWS_ROLE:
description: 'AWS role for dev environment'
required: true

permissions:
contents: read
contents: write
id-token: write

jobs:
Expand All @@ -17,7 +21,13 @@ jobs:
- name: Checkout Repo
uses: supabase/postgres/.github/actions/shared-checkout@HEAD

- uses: DeterminateSystems/nix-installer-action@main
- name: Install nix
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
extra_nix_config: |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

- name: Set PostgreSQL versions
id: set-versions
Expand All @@ -32,22 +42,44 @@ jobs:
matrix:
postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }}
include:
- runner: arm-runner
- runner: large-linux-arm
arch: arm64
ubuntu_release: noble
ubuntu_version: 24.04
mcpu: neoverse-n1
runs-on: ${{ matrix.runner }}
timeout-minutes: 150
permissions:
contents: write
packages: write
id-token: write

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

- name: Debug AWS role secret
run: |
echo "Checking DEV_AWS_ROLE secret availability..."
if [ -z "${{ secrets.DEV_AWS_ROLE }}" ]; then
echo "❌ DEV_AWS_ROLE is empty or not available"
else
echo "✅ DEV_AWS_ROLE is available"
fi

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.DEV_AWS_ROLE }}
aws-region: "us-east-1"
output-credentials: true
role-duration-seconds: 7200

- name: Install nix
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.29.1/install
extra_nix_config: |
substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com
trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=


- id: args
uses: mikefarah/yq@master
with:
Expand All @@ -68,23 +100,23 @@ jobs:

- name: Generate common-nix.vars.pkr.hcl
run: |
PG_VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
PG_VERSION=$(echo "$PG_VERSION" | tr -d '"') # Remove any surrounding quotes
echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
# Ensure there's a newline at the end of the file
echo "" >> common-nix.vars.pkr.hcl

- name: Build AMI stage 1
run: |
packer init amazon-arm64-nix.pkr.hcl
GIT_SHA=${{github.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
nix run github:supabase/postgres/${GIT_SHA}#packer -- init amazon-arm64-nix.pkr.hcl
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

- name: Build AMI stage 2
run: |
packer init stage2-nix-psql.pkr.hcl
GIT_SHA=${{github.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
nix run github:supabase/postgres/${GIT_SHA}#packer -- init stage2-nix-psql.pkr.hcl
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

- name: Run tests
timeout-minutes: 10
Expand Down
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs-go124.url = "github:Nixos/nixpkgs/d2ac4dfa61fba987a84a0a81555da57ae0b9a2b0";
};

outputs =
Expand Down
1 change: 1 addition & 0 deletions nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
wal-g-2
wal-g-3
dbmate-tool
packer
pg_regress
;
}
Expand Down
4 changes: 1 addition & 3 deletions nix/devShells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
shellcheck
ansible
ansible-lint
(packer.overrideAttrs (_oldAttrs: {
version = "1.7.8";
}))
self'.packages.packer

self'.packages.start-server
self'.packages.start-client
Expand Down
68 changes: 68 additions & 0 deletions nix/docs/updating-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Updating Dependencies

This document explains how to update various dependencies used in the nix configuration.

## Updating Packer

Packer is used for creating machine images and is defined in `nix/packages/packer.nix`.

### Steps to update Packer version:

1. Create a branch off of `develop`
2. Navigate to `nix/packages/packer.nix`
3. Update the version field:
```nix
version = "1.15.0"; # Update to desired version
```
4. Update the git revision to match the new version:
```nix
rev = "v${version}";
```
5. Temporarily clear the hash to get the new SHA256:
```nix
hash = ""; # Clear this temporarily
```
6. Save the file and run:
```bash
nix build .#packer
```
7. Nix will fail and output the correct SHA256 hash. Copy this hash and update the file:
```nix
hash = "sha256-NEWHASHHEREFROMBUILDOUTPUT";
```
8. Update the vendorHash if needed. If the build fails due to vendor hash mismatch, temporarily set:
```nix
vendorHash = ""; # Clear this temporarily
```
9. Run `nix build .#packer` again to get the correct vendorHash, then update:
```nix
vendorHash = "sha256-NEWVENDORHASHHEREFROMBUILDOUTPUT";
```
10. Verify the build works:
```bash
nix build .#packer
```
11. Test the packer binary:
```bash
./result/bin/packer version
```
12. Run the full test suite to ensure nothing is broken:
```bash
nix flake check -L
```
13. Commit your changes and create a PR for review
14. Update any CI/CD workflows or documentation that reference the old Packer version

### Notes:
- Always check the [Packer changelog](https://github.com/hashicorp/packer/releases) for breaking changes
- Packer uses Go, so ensure compatibility with the Go version specified in the flake inputs
- The current Go version is specified in `flake.nix` under `nixpkgs-go124` input
- If updating to a major version, test all packer templates (`.pkr.hcl` files) in the repository

## Updating Other Dependencies

Similar patterns can be followed for other dependencies defined in the nix packages. Always:
1. Check for breaking changes in changelogs
2. Update version numbers and hashes
3. Run local tests
4. Verify functionality before creating PR
3 changes: 2 additions & 1 deletion nix/packages/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ self, ... }:
{ self, inputs, ... }:
{
imports = [ ./postgres.nix ];
perSystem =
Expand Down Expand Up @@ -37,6 +37,7 @@
supabase-groonga = pkgs.callPackage ./groonga { };
local-infra-bootstrap = pkgs.callPackage ./local-infra-bootstrap.nix { };
migrate-tool = pkgs.callPackage ./migrate-tool.nix { psql_15 = self'.packages."psql_15/bin"; };
packer = pkgs.callPackage ./packer.nix { inherit inputs; };
pg-restore = pkgs.callPackage ./pg-restore.nix { psql_15 = self'.packages."psql_15/bin"; };
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
pg_regress = makePgRegress activeVersion;
Expand Down
Loading
Loading