Skip to content

Commit 1293179

Browse files
brainrakeclaude
andauthored
refactor(ami): share provisioning steps between qemu and ami builds (#2567)
* refactor(ami): share provisioning steps between qemu and ami builds Move the Nix install, playbook run, Nix GC and report steps that qemu-bootstrap-nix.sh and nix-provision.sh duplicated into provision-common.sh. Both Packer builds upload it to /tmp. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): share stage 1 and cleanup steps between builds Move locale, postgres env, sshd password auth and the image cleanup tail into provision-common.sh. The AMI chroot scripts get the library copied into /mnt/tmp. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(ami): set vector-readable wal-g log modes on the ami Share the image log setup between both builds. The AMI now ships /var/log/wal-g as 0310 and pitr.log as 0340, matching QEMU and the salt vector formula, so vector can read pitr.log without salt. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(ami): source the shared script in the surrogate bootstrap clean_system calls setup_image_logs, which lives in provision-common.sh. The surrogate script copied the library into the chroot but never sourced it on the host. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): share the ansible install and drop qemu-vars Add install_ansible to provision-common.sh for all three bootstrap scripts. Delete ansible/qemu-vars.yaml: it set a var the templates never read, so the QEMU splay was always the vars.yml default. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): run the ami stage 1 playbook through run_playbook run_playbook takes the inventory host and connection as arguments, so the chroot run shares it with the local runs. Drop the sed that rewrote the playbook hosts line and use -i localhost, -c local instead. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): stop shadowing library functions in the chroot scripts Drop the update_and_upgrade_apt copies that matched the library. Rename the chroot cleanup_apt and report_packages, which differ from the library versions, to clean_apt_cache and report_chroot_packages. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): share apt setup, boot wait and file cleanup Move the apt mirror fallback, DEBIAN_FRONTEND export, cloud-init wait and the unwanted-files removal into provision-common.sh. Mark only zlib1g-dev for autoremove on QEMU. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(ami): remove /usr/share/doc on qemu and drop libgcc-8-dev purge The qemu doc removal used an /mnt path and did nothing on the live VM. Do it in remove_unwanted_files for both targets. noble has no libgcc-8-dev, so drop it from the aarch64 purge list. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): share the package purge between cleanup scripts Add purge_packages to provision-common.sh with the build leftovers both targets remove and the shared autoremove, autoclean and upgrade tail. cleanup-qemu.sh passes its extra names. The purge sets are unchanged. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ansible): move qemu-specific values into per-target vars Load ansible/vars/aws.yml or qemu.yml from the playbook. The UID and GID pins, the supascan baseline prefix and the differing values in the adminapi, gotrue, postgres_exporter and admin-agent templates now come from vars. Rendered templates and pins are unchanged for both targets. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(ami): mark zlib1g and zlib1g-dev auto on qemu Restore both packages to the base image state after the Kong purge. setup-kong.yml marks them manual, and the previous change left zlib1g manual. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): zero and trim the disk at the end of each build Add finalize_disk to provision-common.sh and call it as the last step of the qemu build, the ami stage 1 clean_system and the ami stage 2 script. Stage 2 only trims. Zeroing and fstrim leave cleanup.sh and cleanup-qemu.sh, and the login records are emptied before them. Refs: MPG-1383, MPG-90 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): address review nits on the stage 2 call and gotrue comments Inline execute_stage2_playbook in nix-provision.sh. Replace the per-target gotrue comment vars with one static comment. Refs: MPG-1383 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * fix(ami): skip fstrim on the ebs-backed ami builds EBS does not support discard, so fstrim failed the ami stage 1 build. Add a trim argument to finalize_disk, zero without trimming in stage 1, and drop the trim-only call from stage 2. Refs: MPG-1383, MPG-90 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * refactor(ami): default the finalize_disk root to / An empty root has no use here. dd and rm on //zerofile hit the same file as /zerofile. Refs: MPG-1383, MPG-90 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 05749ee commit 1293179

28 files changed

Lines changed: 433 additions & 565 deletions

‎ansible/files/adminapi.service.j2‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Restart=always
1414
RestartSec=3
1515
TimeoutStopSec=10
1616
Environment="AWS_USE_DUALSTACK_ENDPOINT=true"
17-
{% if qemu %}
18-
Environment="AWS_SDK_LOAD_CONFIG=true"
19-
{% endif %}
17+
{% for env in adminapi_extra_env %}
18+
Environment="{{ env }}"
19+
{% endfor %}
2020
StandardOutput=journal
2121
StandardError=journal
2222

‎ansible/files/gotrue.service.j2‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,10 @@ Environment=GOTRUE_RELOADING_POLLER_ENABLED=false
9090
# ensures only 1 reload operation occurs during a burst of config updates.
9191
Environment=GOTRUE_RELOADING_GRACE_PERIOD_INTERVAL=2s
9292

93-
{% if qemu %}
94-
# v3 does not use filesystem notifications for config reloads.
95-
Environment=GOTRUE_RELOADING_NOTIFY_ENABLED=false
96-
{% else %}
97-
# v2 currently relies on notify support, so we will enable it until both v2 / v3
98-
# have migrated to strictly use signals across all projects. The default is true
99-
# in gotrue but we will set it defensively here.
100-
Environment=GOTRUE_RELOADING_NOTIFY_ENABLED=true
101-
{% endif %}
93+
# v3 does not use filesystem notifications for config reloads. v2 relies on
94+
# notify support until both have migrated to strictly use signals. The default
95+
# is true in gotrue, but it is set explicitly here.
96+
Environment=GOTRUE_RELOADING_NOTIFY_ENABLED={{ gotrue_reloading_notify_enabled | lower }}
10297

10398
Slice=services.slice
10499

‎ansible/files/postgres_exporter.service.j2‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ StartLimitBurst=0
66

77
[Service]
88
Type=simple
9-
ExecStart=/opt/postgres_exporter/postgres_exporter --disable-settings-metrics --extend.query-path="/opt/postgres_exporter/queries.yml" --disable-default-metrics --no-collector.locks --no-collector.replication --no-collector.replication_slot --no-collector.stat_bgwriter --no-collector.stat_database --no-collector.stat_user_tables --no-collector.statio_user_tables --no-collector.wal --collector.database_wraparound {% if qemu %}--no-collector.database {% endif %}
10-
9+
ExecStart=/opt/postgres_exporter/postgres_exporter --disable-settings-metrics --extend.query-path="/opt/postgres_exporter/queries.yml" --disable-default-metrics --no-collector.locks --no-collector.replication --no-collector.replication_slot --no-collector.stat_bgwriter --no-collector.stat_database --no-collector.stat_user_tables --no-collector.statio_user_tables --no-collector.wal --collector.database_wraparound{% for flag in postgres_exporter_extra_flags %} {{ flag }}{% endfor %}
1110
User=postgres
1211
Group=postgres
1312
Restart=always

‎ansible/files/supabase_admin_agent_config/supabase-admin-agent_salt.service.j2‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ Requires=local-fs.target
66

77
[Service]
88
Type=oneshot
9-
{% if qemu %}
10-
ExecStart=/opt/supabase-admin-agent/supabase-admin-agent --config /opt/supabase-admin-agent/config.yaml salt --apply --store-result --targets-key targetsv3-main.yaml
11-
User=root
12-
Group=root
13-
{% else %}
14-
ExecStart=/opt/supabase-admin-agent/supabase-admin-agent --config /opt/supabase-admin-agent/config.yaml salt --apply --store-result
15-
User=supabase-admin-agent
16-
Group=supabase-admin-agent
17-
{% endif %}
9+
ExecStart=/opt/supabase-admin-agent/supabase-admin-agent --config /opt/supabase-admin-agent/config.yaml {{ supabase_admin_agent_salt.args }}
10+
User={{ supabase_admin_agent_salt.user }}
11+
Group={{ supabase_admin_agent_salt.group }}
1812
StandardOutput=journal
1913
StandardError=journal
2014
StateDirectory=supabase-admin-agent

‎ansible/files/supabase_admin_agent_config/supabase-admin-agent_salt.timer.j2‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@ Description=Run Supabase supabase-admin-agent salt on a schedule
33
Requires=supabase-admin-agent_salt.service
44

55
[Timer]
6-
{# We're using a significantly lower frequency for triggering this agent on qemu images for the moment. Once we've performed additional validations re: the aggregate impact of running it more frequently, the frequency can be increased. #}
7-
{% if qemu %}
8-
OnCalendar=*-*-* 0,6,12,18:00:00
6+
OnCalendar={{ supabase_admin_agent_timer.on_calendar }}
97
RandomizedDelaySec={{ supabase_admin_agent_splay }}
10-
AccuracySec=1h
11-
OnBootSec=5m
12-
Persistent=true
13-
{% else %}
14-
OnCalendar=*:0/10
15-
RandomizedDelaySec={{ supabase_admin_agent_splay }}
16-
AccuracySec=1s
17-
Persistent=true
8+
AccuracySec={{ supabase_admin_agent_timer.accuracy_sec }}
9+
{% if supabase_admin_agent_timer.on_boot_sec %}
10+
OnBootSec={{ supabase_admin_agent_timer.on_boot_sec }}
1811
{% endif %}
12+
Persistent=true
1913

2014
[Install]
2115
WantedBy=timers.target

‎ansible/playbook.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
vars_files:
88
- ./vars.yml
9+
- "./vars/{{ 'qemu' if qemu else 'aws' }}.yml"
910

1011
# Set facts only in here, never in any tasks.
1112
# This avoids redefining/duplicates or different values (buggy)
@@ -186,7 +187,7 @@
186187
- name: Run supascan baseline validation
187188
when: stage2
188189
shell: >-
189-
baseline={{ 'ami' if not qemu else 'qemu' }}-build-{{ platform }}
190+
baseline={{ supascan_baseline_prefix }}-build-{{ platform }}
190191
nix shell {{ nix_store_paths['supascan'] }} --command
191192
/tmp/ansible-playbook/ansible/files/supascan_ami.sh
192193
/tmp/ansible-playbook/audit-specs/baselines/$baseline

‎ansible/qemu-vars.yaml‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎ansible/tasks/internal/admin-api.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- name: adminapi - system user
88
ansible.builtin.user:
99
name: adminapi
10-
uid: "{{ 1006 if not qemu else 1007 }}"
10+
uid: "{{ uids.adminapi }}"
1111
group: adminapi
1212
groups: admin,envoy,gotrue,kong,pgbouncer,postgres,postgrest,root,systemd-journal,vector,wal-g
1313

‎ansible/tasks/internal/supabase-admin-agent.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- name: supabase-admin-agent - system group
22
ansible.builtin.group:
33
name: supabase-admin-agent
4-
gid: "{{ 987 if not qemu else 988 }}"
4+
gid: "{{ gids.supabase_admin_agent }}"
55
system: yes
66

77
- name: supabase-admin-agent - system user

‎ansible/tasks/setup-envoy.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- name: Envoy - user
88
ansible.builtin.user:
99
name: envoy
10-
uid: "{{ 1003 if not qemu else 1004 }}"
10+
uid: "{{ uids.envoy }}"
1111
group: envoy
1212
state: present
1313

0 commit comments

Comments
 (0)