-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (67 loc) · 2.37 KB
/
build-runner-images.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Build Runner EC2 Images
on:
pull_request:
paths:
- .github/workflows/build-runner-images.yml
schedule:
# 00:00 on Monday each week
- cron: "0 0 * * 1"
workflow_dispatch:
jobs:
build-image:
name: Build
runs-on: ubuntu-latest
defaults:
run:
working-directory: packer/github-actions-runner
permissions:
id-token: write
contents: read
env:
AMI_ACCOUNT: ${{ vars.RUNNER_AMI_ACCOUNT }}
AMI_FILTER: ${{ vars.RUNNER_AMI_FILTER }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ vars.RUNNER_ACCOUNT_ROLE }}
aws-region: us-east-1
- name: Retrieve default VPC ID and subnet
id: vpc
run: |
VPC_ID=`aws ec2 describe-vpcs --filters "Name=tag:Name, Values=bcda-managed-vpc" --query 'Vpcs[].VpcId' --output text`
echo "VPC_ID=$VPC_ID" >> "$GITHUB_ENV"
SUBNET_ID=`aws ec2 describe-subnets --filters "Name=vpc-id,Values=$VPC_ID" --query 'Subnets[0].SubnetId' --output text`
echo "SUBNET_ID=$SUBNET_ID" >> "$GITHUB_ENV"
SECURITY_GROUP_ID=`aws ec2 describe-security-groups --filters "Name=vpc-id,Values=$VPC_ID" "Name=description,Values=bcda-managed-remote-management" --query 'SecurityGroups[].GroupId' --output text`
echo "SUBNET_ID=$SUBNET_ID" >> "$GITHUB_ENV"
- name: Setup `packer`
uses: hashicorp/setup-packer@main
id: setup
with:
version: "latest"
- name: Run `packer init`
id: init
run: packer init .
- name: Run `packer validate`
id: validate
run: |
packer validate \
-var ami_account="$AMI_ACCOUNT" \
-var ami_filter="$AMI_FILTER" \
-var vpc_id="$VPC_ID" \
-var subnet_id="$SUBNET_ID" \
-var security_group_id="$SECURITY_GROUP_ID" \
-evaluate-datasources .
- name: Packer Build
id: build
run: |
packer build \
-var ami_account="$AMI_ACCOUNT" \
-var ami_filter="$AMI_FILTER" \
-var vpc_id="$VPC_ID" \
-var subnet_id="$SUBNET_ID" \
-var security_group_id="$SECURITY_GROUP_ID" \
-color=false -on-error=cleanup .