From 7146eaab5a47057f1f50ee346ac7f608cbd0d855 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 20 Aug 2026 15:14:12 -0400 Subject: [PATCH 1/3] nix-provision: Remove unnecessary sudos This was left over from #2380 from when I did some commit re-ordering. --- ebssurrogate/scripts/nix-provision.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ebssurrogate/scripts/nix-provision.sh b/ebssurrogate/scripts/nix-provision.sh index 360c7231a..7d3a48afa 100755 --- a/ebssurrogate/scripts/nix-provision.sh +++ b/ebssurrogate/scripts/nix-provision.sh @@ -9,21 +9,21 @@ exec 1>&2 function install_packages { # Setup Ansible on host VM - sudo apt-get update && sudo apt-get install -y software-properties-common + apt-get update && apt-get install -y software-properties-common # Install EC2-specific packages that were deferred from stage 1 # These packages have post-install scripts that need EC2 metadata service access # which only works on a real running EC2 instance (not in chroot) - sudo apt-get install -y ec2-hibinit-agent ec2-instance-connect hibagent + apt-get install -y ec2-hibinit-agent ec2-instance-connect hibagent # Manually add GPG key with explicit keyserver - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367 + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 93C4A3FD7BB9C367 # Add repository and install # TODO (darora): temporarily disabling while Launchpad is under ddos attack and very frequently timing out # sudo add-apt-repository --yes ppa:ansible/ansible # sudo apt-get update - sudo apt-get install -y ansible + apt-get install -y ansible ansible-galaxy collection install community.general } From fcbbad661d00c50b9c106459691599f6df45823d Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Fri, 21 Aug 2026 13:49:37 -0400 Subject: [PATCH 2/3] ci/testinfra: Drop docker stuff We don't use docker in the tests so no need to do any of these actions/install packages. --- .github/workflows/testinfra-ami-build.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/testinfra-ami-build.yml b/.github/workflows/testinfra-ami-build.yml index 1582214e7..bcdbf8814 100644 --- a/.github/workflows/testinfra-ami-build.yml +++ b/.github/workflows/testinfra-ami-build.yml @@ -100,20 +100,14 @@ jobs: postgres_version: ${{ matrix.postgres_version }} region: ${{ env.AWS_REGION }} - - run: docker context create builders - - - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 - with: - endpoint: builders - - name: Run tests timeout-minutes: 10 env: AMI_ID: ${{ steps.build-ami.outputs.stage2_ami_id }} EXECUTION_ID: ${{ steps.build-ami.outputs.execution_id }} run: | - # TODO: use poetry for pkg mgmt - pip3 install boto3 "boto3-stubs[essential]" docker ec2instanceconnectcli pytest "pytest-testinfra[paramiko,docker]" requests + # TODO: use uv for pkg mgmt + pip3 install boto3 'boto3-stubs[essential]' ec2instanceconnectcli pytest 'pytest-testinfra[paramiko]' requests pytest -vv -s testinfra/test_ami_nix.py - name: Cleanup resources on build cancellation From 231b29d65ac13edf626c3870fede97bd05dc35c8 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 20 Aug 2026 15:14:12 -0400 Subject: [PATCH 3/3] AMI: Report disk usage I've had a few occasions where I wanted to see disk usage changes and had to create a one-of PR to do so. Since AMI image size is important to us we should at least show it somewhere. I might post as a comment in the future, holding off for now because I'd like to post just one comment with the Postgres Extension Dependency Analysis info too. Note: I'm aware that if there's any issue getting, outputting, parsing the disk usage it'll break the build and I'm ok with that. I want to see disk usage and if we can't get it then something is wrong and should be fixed. --- .github/actions/build-ami/action.yml | 3 ++ .github/workflows/testinfra-ami-build.yml | 50 +++++++++++++++++++++-- ebssurrogate/scripts/nix-provision.sh | 7 ++++ nix/packages/build-ami.nix | 15 +++++++ stage2-nix-psql.pkr.hcl | 6 +++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/.github/actions/build-ami/action.yml b/.github/actions/build-ami/action.yml index 9743fa202..b241ec4ee 100644 --- a/.github/actions/build-ami/action.yml +++ b/.github/actions/build-ami/action.yml @@ -37,6 +37,9 @@ outputs: execution_id: description: 'The execution ID for this build' value: ${{ steps.set-execution-id.outputs.execution_id }} + disk_usage_json: + description: 'The stage 2 AMI root disk usage as json' + value: ${{ steps.build-stage2.outputs.disk_usage_json }} runs: using: "composite" diff --git a/.github/workflows/testinfra-ami-build.yml b/.github/workflows/testinfra-ami-build.yml index bcdbf8814..728835839 100644 --- a/.github/workflows/testinfra-ami-build.yml +++ b/.github/workflows/testinfra-ami-build.yml @@ -19,7 +19,7 @@ env: AWS_REGION: ap-southeast-1 jobs: - prepare: + gen-matrix: runs-on: blacksmith-2vcpu-ubuntu-2404 outputs: postgres_versions: ${{ steps.set-versions.outputs.postgres_versions }} @@ -37,11 +37,11 @@ jobs: echo "postgres_versions=$VERSIONS" >> "$GITHUB_OUTPUT" test-ami-nix: - needs: prepare + needs: gen-matrix strategy: fail-fast: false matrix: - postgres_version: ${{ fromJson(needs.prepare.outputs.postgres_versions) }} + postgres_version: ${{ fromJson(needs.gen-matrix.outputs.postgres_versions) }} target: - arch: amd64 instance_type: c6i.4xlarge @@ -100,6 +100,27 @@ jobs: postgres_version: ${{ matrix.postgres_version }} region: ${{ env.AWS_REGION }} + - name: Save AMI disk usage + env: + ARCH: ${{ matrix.target.arch }} + DISK_USAGE_JSON: ${{ steps.build-ami.outputs.disk_usage_json }} + POSTGRES_VERSION: ${{ matrix.postgres_version }} + run: >- + jq -cnr + --arg arch "$ARCH" + --arg version "$POSTGRES_VERSION" + --argjson disk_usage "$DISK_USAGE_JSON" + '{$version,$arch,bytes:$disk_usage.bytes,human:$disk_usage.human}' + >"ami-disk-usage-$POSTGRES_VERSION-$ARCH.json" + + - name: Upload AMI disk usage + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: ami-disk-usage-${{ matrix.postgres_version }}-${{ matrix.target.arch }} + path: ami-disk-usage-*.json + overwrite: true + retention-days: 1 + - name: Run tests timeout-minutes: 10 env: @@ -167,3 +188,26 @@ jobs: else echo "No stage 2 AMI to clean up" fi + + report-disk-usage: + needs: test-ami-nix + runs-on: blacksmith-2vcpu-ubuntu-2404 + steps: + - name: Download AMI disk usage + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + pattern: ami-disk-usage-* + path: ami-disk-usage + merge-multiple: true + + - name: Report AMI disk usage + run: | + cat <>"$GITHUB_STEP_SUMMARY" + ### AMI Root Disk Usage + + | Version | Arch | Human | Bytes | + | ------- | ---- | ----- | ----- | + EOF + cat ami-disk-usage/ami-disk-usage-*.json | + sort -V | + jq -rs '.[]|{version,arch,human,bytes}|"| \(join("|")) |"' >>"$GITHUB_STEP_SUMMARY" diff --git a/ebssurrogate/scripts/nix-provision.sh b/ebssurrogate/scripts/nix-provision.sh index 7d3a48afa..3b576dc17 100755 --- a/ebssurrogate/scripts/nix-provision.sh +++ b/ebssurrogate/scripts/nix-provision.sh @@ -72,7 +72,14 @@ function cleanup_packages { # sudo add-apt-repository --yes --remove ppa:ansible/ansible } +function report_disk_usage { + read -r dub _ < <(du -sx -B1 /) + read -r duh _ < <(du -sx -h /) + printf '::notice::disk_usage bytes=%s human=%s\n' "$dub" "$duh" | tee -a /tmp/ansible.log +} + install_packages install_nix execute_stage2_playbook cleanup_packages +report_disk_usage diff --git a/nix/packages/build-ami.nix b/nix/packages/build-ami.nix index d46d62e09..4e89e5500 100644 --- a/nix/packages/build-ami.nix +++ b/nix/packages/build-ami.nix @@ -194,6 +194,21 @@ writeShellApplication { -var "source_ami=$STAGE1_AMI_ID" \ "$@" + disk_usage_notice=$(grep '^::notice::disk_usage ' /tmp/ansible-stage2.log | tail -n 1 || true) + disk_usage_notice_pattern='^::notice::disk_usage bytes=([0-9]+) human=([0-9]+(\.[0-9]+)?[MGT]?)$' + if [[ $disk_usage_notice =~ $disk_usage_notice_pattern ]]; then + disk_usage_bytes=''${BASH_REMATCH[1]} + disk_usage_human=''${BASH_REMATCH[2]} + else + echo "Error: Missing or invalid disk usage notice in stage 2 log: '$disk_usage_notice'" >&2 + exit 1 + fi + echo "::notice::AMI Disk Usage $disk_usage_human $disk_usage_bytes" + if [[ -n ''${GITHUB_OUTPUT:-} ]]; then + disk_usage_json=$(jq -cnr --arg bytes "$disk_usage_bytes" --arg human "$disk_usage_human" '{$bytes,$human}') + echo "disk_usage_json=$disk_usage_json" >>"$GITHUB_OUTPUT" + fi + if [ -n "''${PACKER_EXECUTION_ID:-}" ]; then STAGE2_AMI_ID=$(aws ec2 describe-images \ --region "$REGION" \ diff --git a/stage2-nix-psql.pkr.hcl b/stage2-nix-psql.pkr.hcl index 234d6c506..6bd12a1c4 100644 --- a/stage2-nix-psql.pkr.hcl +++ b/stage2-nix-psql.pkr.hcl @@ -132,4 +132,10 @@ build { script = "ebssurrogate/scripts/nix-provision.sh" execute_command = "sudo -S sh -c '. {{.EnvVarFile}} && cd /tmp/ansible-playbook && {{.Path}}'" } + + provisioner "file" { + source = "/tmp/ansible.log" + destination = "/tmp/ansible-stage2.log" + direction = "download" + } }