-
Notifications
You must be signed in to change notification settings - Fork 5
95 lines (79 loc) · 2.45 KB
/
create-ami.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Build AMI with Packer
on:
schedule:
- cron: '0 18 * * *'
workflow_dispatch:
inputs:
environment:
description: 'Image deployment environment'
required: true
default: 'stg'
options:
- stg
- prod
permissions:
id-token: write
contents: read
jobs:
build-ami:
runs-on: codebuild-problem-github-actions-${{ github.run_id }}-${{ github.run_attempt }}
name: build isucon14 contestant image
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install unzip
run: |
sudo apt-get update
sudo apt-get install unzip
- name: Set up Packer
uses: hashicorp/setup-packer@main
with:
version: "1.11.2"
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Setup Task
uses: arduino/setup-task@v2
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Ansible
run: |
python -m pip install --upgrade pip
pip install ansible
- name: Set AWS Role ARN
id: set-role
run: |
if [ "${{ github.event.inputs.environment }}" == "prod" ]; then
echo "AWS_PACKER_BUILD_ROLE_ARN=${{ vars.AWS_PROD_PACKER_BUILD_ROLE_ARN }}" >> $GITHUB_ENV
else
echo "AWS_PACKER_BUILD_ROLE_ARN=${{ vars.AWS_STG_PACKER_BUILD_ROLE_ARN }}" >> $GITHUB_ENV
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_PACKER_BUILD_ROLE_ARN }}
aws-region: ap-northeast-1
- name: Build
run: |
cd provisioning/packer
make
# - name: Cleanup old AMIs
# run: |
# PREFIX="isucon14_contestant-"
# aws ec2 describe-images --owners self --filters "Name=name,Values=${PREFIX}*" --query 'Images[*].[ImageId,CreationDate]' --output json | \
# jq -r 'sort_by(.[1]) | reverse | .[3:] | .[][0]' | \
# xargs -I {} aws ec2 deregister-image --image-id {}