Skip to content

Commit 9d2599d

Browse files
committed
fix: a different approach to building and resizing/reset default
1 parent 6cec39e commit 9d2599d

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

.github/workflows/testinfra-nix.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,48 @@ jobs:
5353
GIT_SHA=${{github.sha}}
5454
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 "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
5555
56+
- name: Get pre-resize AMI ID
57+
id: get-ami
58+
run: |
59+
AMI_ID=$(aws ec2 describe-images --owners self --filters "Name=name,Values=supabase-postgres-${{ steps.random.outputs.random_string }}-pre-resize" --query 'Images[0].ImageId' --output text)
60+
echo "AMI_ID=${AMI_ID}" >> $GITHUB_OUTPUT
61+
62+
- name: Launch temporary instance
63+
id: launch-instance
64+
run: |
65+
INSTANCE_ID=$(aws ec2 run-instances --image-id ${{ steps.get-ami.outputs.AMI_ID }} --instance-type t4g.micro --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=AMI-Resize-Temp}]' --query 'Instances[0].InstanceId' --output text)
66+
echo "INSTANCE_ID=${INSTANCE_ID}" >> $GITHUB_OUTPUT
67+
68+
- name: Wait for instance to be running
69+
run: aws ec2 wait instance-running --instance-ids ${{ steps.launch-instance.outputs.INSTANCE_ID }}
70+
71+
- name: Resize filesystem
72+
run: |
73+
aws ec2 start-session --target ${{ steps.launch-instance.outputs.INSTANCE_ID }} --document-name AWS-StartInteractiveCommand --parameters '{"command":["sudo e2fsck -f /dev/sda1 && sudo resize2fs /dev/sda1 8G && sudo sync"]}'
74+
75+
- name: Create new AMI
76+
id: create-ami
77+
run: |
78+
NEW_AMI_NAME="supabase-postgres-${{ steps.random.outputs.random_string }}"
79+
NEW_AMI_ID=$(aws ec2 create-image --instance-id ${{ steps.launch-instance.outputs.INSTANCE_ID }} --name "${NEW_AMI_NAME}" --description "Resized AMI" --query 'ImageId' --output text)
80+
echo "NEW_AMI_ID=${NEW_AMI_ID}" >> $GITHUB_OUTPUT
81+
echo "NEW_AMI_NAME=${NEW_AMI_NAME}" >> $GITHUB_OUTPUT
82+
83+
- name: Wait for AMI to be available
84+
run: aws ec2 wait image-available --image-ids ${{ steps.create-ami.outputs.NEW_AMI_ID }}
85+
86+
- name: Modify AMI block device mapping
87+
run: |
88+
aws ec2 modify-image-attribute --image-id ${{ steps.create-ami.outputs.NEW_AMI_ID }} --block-device-mappings '[{"DeviceName": "/dev/sda1","Ebs":{"VolumeSize":8}}]'
89+
90+
- name: Terminate temporary instance
91+
run: aws ec2 terminate-instances --instance-ids ${{ steps.launch-instance.outputs.INSTANCE_ID }}
92+
5693
- name: Run tests
5794
timeout-minutes: 10
5895
env:
59-
AMI_NAME: "supabase-postgres-${{ steps.random.outputs.random_string }}"
96+
AMI_NAME: ${{ steps.create-ami.outputs.NEW_AMI_NAME }}
6097
run: |
61-
# TODO: use poetry for pkg mgmt
6298
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests
6399
pytest -vv -s testinfra/test_ami_nix.py
64100
@@ -77,7 +113,8 @@ jobs:
77113
run: |
78114
# Define AMI name patterns
79115
STAGE1_AMI_NAME="supabase-postgres-ci-ami-test-stage-1"
80-
STAGE2_AMI_NAME="${{ steps.random.outputs.random_string }}"
116+
PRE_RESIZE_AMI_NAME="supabase-postgres-${{ steps.random.outputs.random_string }}-pre-resize"
117+
FINAL_AMI_NAME="supabase-postgres-${{ steps.random.outputs.random_string }}"
81118
82119
# Function to deregister AMIs by name pattern
83120
deregister_ami_by_name() {
@@ -91,4 +128,5 @@ jobs:
91128
92129
# Deregister AMIs
93130
deregister_ami_by_name "$STAGE1_AMI_NAME"
94-
deregister_ami_by_name "$STAGE2_AMI_NAME"
131+
deregister_ami_by_name "$PRE_RESIZE_AMI_NAME"
132+
deregister_ami_by_name "$FINAL_AMI_NAME"

stage2-nix-psql.pkr.hcl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ source "amazon-ebs" "ubuntu" {
8585
volume_type = "gp3"
8686
delete_on_termination = true
8787
}
88-
ami_block_device_mappings {
89-
device_name = "/dev/sda1"
90-
volume_type = "gp3"
91-
volume_size = 8
92-
delete_on_termination = true
93-
}
9488
run_tags = {
9589
creator = "packer"
9690
appType = "postgres"

0 commit comments

Comments
 (0)