Skip to content

Commit 78d3420

Browse files
committed
Switch back to Packer for AMI builds
- Use Packer with existing security group to avoid CreateSecurityGroup permission - Pass security_group_id via secret AWS_SECURITY_GROUP_ID - Remove unused build-ami action Signed-off-by: Joe Isaacs <[email protected]>
1 parent 8431dfb commit 78d3420

File tree

3 files changed

+85
-161
lines changed

3 files changed

+85
-161
lines changed

.github/actions/build-ami/action.yml

Lines changed: 0 additions & 128 deletions
This file was deleted.

.github/packer/vortex-ci.pkr.hcl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ variable "subnet_id" {
3333
default = ""
3434
}
3535

36+
variable "security_group_id" {
37+
type = string
38+
default = ""
39+
description = "Existing security group ID (must allow SSH inbound)"
40+
}
41+
3642
variable "rust_toolchain" {
3743
type = string
3844
default = "1.89"
@@ -83,8 +89,9 @@ source "amazon-ebs" "vortex-ci" {
8389
owners = [var.source_ami_owner]
8490
}
8591

86-
subnet_id = var.subnet_id != "" ? var.subnet_id : null
87-
ssh_username = "runner"
92+
subnet_id = var.subnet_id != "" ? var.subnet_id : null
93+
security_group_id = var.security_group_id != "" ? var.security_group_id : null
94+
ssh_username = "runner"
8895

8996
# User data to start SSH for Packer connectivity
9097
user_data_file = "${path.root}/scripts/user_data.sh"

.github/workflows/ami-prebuild.yml

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,14 @@ env:
4040
AWS_REGION: eu-west-1
4141

4242
jobs:
43-
# Build AMI by running on a runs-on instance and creating an image from it
4443
build-x64:
4544
name: "Build AMI (x64)"
4645
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.arch == '' || github.event.inputs.arch == 'x64' }}
47-
runs-on:
48-
- runs-on=${{ github.run_id }}
49-
- runner=2cpu-linux-x64
50-
- family=m7i+m7i-flex+m7a
51-
- tag=ami-build-x64
46+
runs-on: ubuntu-latest
5247
timeout-minutes: 60
5348
outputs:
54-
ami-id: ${{ steps.build-ami.outputs.ami-id }}
55-
ami-name: ${{ steps.build-ami.outputs.ami-name }}
49+
ami-id: ${{ steps.build.outputs.ami_id }}
50+
ami-name: ${{ steps.build.outputs.ami_name }}
5651

5752
steps:
5853
- name: Checkout
@@ -64,34 +59,57 @@ jobs:
6459
role-to-assume: arn:aws:iam::375504701696:role/GitHubBenchmarkRole
6560
aws-region: ${{ env.AWS_REGION }}
6661

67-
- name: Build AMI
68-
id: build-ami
69-
uses: ./.github/actions/build-ami
62+
- name: Setup Packer
63+
uses: hashicorp/setup-packer@main
7064
with:
71-
arch: x64
72-
ami-prefix: vortex-ci
73-
retention-days: ${{ inputs.retention-days || '30' }}
65+
version: "1.11.2"
66+
67+
- name: Packer Init
68+
working-directory: .github/packer
69+
run: packer init vortex-ci.pkr.hcl
70+
71+
- name: Packer Build
72+
id: build
73+
working-directory: .github/packer
74+
run: |
75+
packer build \
76+
-var "arch=x64" \
77+
-var "aws_region=${{ env.AWS_REGION }}" \
78+
-var "subnet_id=${{ secrets.AWS_SUBNET_ID }}" \
79+
-var "security_group_id=${{ secrets.AWS_SECURITY_GROUP_ID }}" \
80+
-machine-readable \
81+
vortex-ci.pkr.hcl | tee packer-output.log
82+
83+
# Extract AMI ID from Packer output
84+
AMI_ID=$(grep 'artifact,0,id' packer-output.log | tail -1 | cut -d',' -f6 | cut -d':' -f2)
85+
echo "ami_id=$AMI_ID" >> $GITHUB_OUTPUT
86+
echo "ami_name=vortex-ci-x64" >> $GITHUB_OUTPUT
87+
echo "Built AMI: $AMI_ID"
88+
89+
- name: Set AMI Deprecation
90+
run: |
91+
RETENTION_DAYS=${{ inputs.retention-days || '30' }}
92+
DEPRECATION_TIME=$(date -u -d "+${RETENTION_DAYS} days" +%Y-%m-%dT%H:%M:%SZ)
93+
aws ec2 enable-image-deprecation \
94+
--image-id "${{ steps.build.outputs.ami_id }}" \
95+
--deprecate-at "$DEPRECATION_TIME"
96+
echo "AMI will be deprecated at $DEPRECATION_TIME"
7497
7598
- name: Summary
7699
run: |
77100
echo "## AMI Build Complete (x64)" >> $GITHUB_STEP_SUMMARY
78101
echo "" >> $GITHUB_STEP_SUMMARY
79-
echo "- **AMI ID:** ${{ steps.build-ami.outputs.ami-id }}" >> $GITHUB_STEP_SUMMARY
80-
echo "- **AMI Name:** ${{ steps.build-ami.outputs.ami-name }}" >> $GITHUB_STEP_SUMMARY
102+
echo "- **AMI ID:** ${{ steps.build.outputs.ami_id }}" >> $GITHUB_STEP_SUMMARY
81103
echo "- **Deprecation:** ${{ inputs.retention-days || '30' }} days" >> $GITHUB_STEP_SUMMARY
82104
83105
build-arm64:
84106
name: "Build AMI (arm64)"
85107
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.arch == '' || github.event.inputs.arch == 'arm64' }}
86-
runs-on:
87-
- runs-on=${{ github.run_id }}
88-
- runner=2cpu-linux-arm64
89-
- family=m7g
90-
- tag=ami-build-arm64
108+
runs-on: ubuntu-latest
91109
timeout-minutes: 60
92110
outputs:
93-
ami-id: ${{ steps.build-ami.outputs.ami-id }}
94-
ami-name: ${{ steps.build-ami.outputs.ami-name }}
111+
ami-id: ${{ steps.build.outputs.ami_id }}
112+
ami-name: ${{ steps.build.outputs.ami_name }}
95113

96114
steps:
97115
- name: Checkout
@@ -103,20 +121,47 @@ jobs:
103121
role-to-assume: arn:aws:iam::375504701696:role/GitHubBenchmarkRole
104122
aws-region: ${{ env.AWS_REGION }}
105123

106-
- name: Build AMI
107-
id: build-ami
108-
uses: ./.github/actions/build-ami
124+
- name: Setup Packer
125+
uses: hashicorp/setup-packer@main
109126
with:
110-
arch: arm64
111-
ami-prefix: vortex-ci
112-
retention-days: ${{ inputs.retention-days || '30' }}
127+
version: "1.11.2"
128+
129+
- name: Packer Init
130+
working-directory: .github/packer
131+
run: packer init vortex-ci.pkr.hcl
132+
133+
- name: Packer Build
134+
id: build
135+
working-directory: .github/packer
136+
run: |
137+
packer build \
138+
-var "arch=arm64" \
139+
-var "aws_region=${{ env.AWS_REGION }}" \
140+
-var "subnet_id=${{ secrets.AWS_SUBNET_ID }}" \
141+
-var "security_group_id=${{ secrets.AWS_SECURITY_GROUP_ID }}" \
142+
-machine-readable \
143+
vortex-ci.pkr.hcl | tee packer-output.log
144+
145+
# Extract AMI ID from Packer output
146+
AMI_ID=$(grep 'artifact,0,id' packer-output.log | tail -1 | cut -d',' -f6 | cut -d':' -f2)
147+
echo "ami_id=$AMI_ID" >> $GITHUB_OUTPUT
148+
echo "ami_name=vortex-ci-arm64" >> $GITHUB_OUTPUT
149+
echo "Built AMI: $AMI_ID"
150+
151+
- name: Set AMI Deprecation
152+
run: |
153+
RETENTION_DAYS=${{ inputs.retention-days || '30' }}
154+
DEPRECATION_TIME=$(date -u -d "+${RETENTION_DAYS} days" +%Y-%m-%dT%H:%M:%SZ)
155+
aws ec2 enable-image-deprecation \
156+
--image-id "${{ steps.build.outputs.ami_id }}" \
157+
--deprecate-at "$DEPRECATION_TIME"
158+
echo "AMI will be deprecated at $DEPRECATION_TIME"
113159
114160
- name: Summary
115161
run: |
116162
echo "## AMI Build Complete (arm64)" >> $GITHUB_STEP_SUMMARY
117163
echo "" >> $GITHUB_STEP_SUMMARY
118-
echo "- **AMI ID:** ${{ steps.build-ami.outputs.ami-id }}" >> $GITHUB_STEP_SUMMARY
119-
echo "- **AMI Name:** ${{ steps.build-ami.outputs.ami-name }}" >> $GITHUB_STEP_SUMMARY
164+
echo "- **AMI ID:** ${{ steps.build.outputs.ami_id }}" >> $GITHUB_STEP_SUMMARY
120165
echo "- **Deprecation:** ${{ inputs.retention-days || '30' }} days" >> $GITHUB_STEP_SUMMARY
121166
122167
# Test the newly built AMI

0 commit comments

Comments
 (0)