@@ -53,12 +53,48 @@ jobs:
53
53
GIT_SHA=${{github.sha}}
54
54
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
55
55
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
+
56
93
- name : Run tests
57
94
timeout-minutes : 10
58
95
env :
59
- AMI_NAME : " supabase-postgres- ${{ steps.random .outputs.random_string }}"
96
+ AMI_NAME : ${{ steps.create-ami .outputs.NEW_AMI_NAME }}
60
97
run : |
61
- # TODO: use poetry for pkg mgmt
62
98
pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests
63
99
pytest -vv -s testinfra/test_ami_nix.py
64
100
77
113
run : |
78
114
# Define AMI name patterns
79
115
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 }}"
81
118
82
119
# Function to deregister AMIs by name pattern
83
120
deregister_ami_by_name() {
91
128
92
129
# Deregister AMIs
93
130
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"
0 commit comments