-
Notifications
You must be signed in to change notification settings - Fork 2
150 lines (125 loc) · 4.48 KB
/
oioi-agent-image-push.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: oioi-agent-image-push
on:
push:
paths:
- "oioi/**"
- ".github/workflows/oioi-agent-image-push.yml"
# push:
# branches:
# - master
# pull_request:
concurrency:
group: ${{ github.ref }}-oioi-agent-image-push
cancel-in-progress: true
env:
AWS_ACCOUNT_ID: 962920162112
AWS_DEFAULT_REGION: ap-northeast-2
CDK_DEFAULT_ACCOUNT: 962920162112
CDK_DEFAULT_REGION: ap-northeast-2
CARGO_VERSION: 1.74.0
RUST_CACHE_PATHS: |
~/.cargo/
oioi/agent/target/
permissions:
id-token: write
contents: read
jobs:
oioi-agent-image-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# -- Agent Rust Build
- uses: actions/cache/restore@v3
id: restore-cache
with:
path: ${{ env.RUST_CACHE_PATHS }}
key: ${{ runner.os }}-${{ env.CARGO_VERSION }}-oioi-${{ hashFiles('oioi/agent/Cargo.lock') }}-musl
- name: Set up rust
run: |
rustup toolchain install ${{ env.CARGO_VERSION }} --profile minimal
rustup default ${{ env.CARGO_VERSION }}
- name: Set up aarch64 cross-compilation
run: |
rustup target add aarch64-unknown-linux-musl
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build agent
working-directory: oioi/agent
run: |
cargo build --release --target aarch64-unknown-linux-musl
- uses: actions/cache/save@v3
with:
path: ${{ env.RUST_CACHE_PATHS }}
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
# -- Docker
- uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- uses: docker/setup-buildx-action@v3
with:
install: true
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-role
aws-region: us-east-1 # for public ECR
- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: o4b6l4b3 # should be replaced to namseent after the alias is approved by AWS.
REPOSITORY: oioi
IMAGE_TAG: ${{ github.sha }}
working-directory: oioi/agent
run: |
IMAGE_PATH=$REGISTRY/$REGISTRY_ALIAS/$REPOSITORY
for i in "linux/arm64 aarch64-unknown-linux-musl"
do
set -- $i # Convert the "tuple" into the param args $1 $2...
docker build \
-t $IMAGE_PATH:$IMAGE_TAG \
-t $IMAGE_PATH:latest \
--platform $1 \
--build-arg TARGET=$2 \
--push \
--cache-to mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=$IMAGE_PATH:cache \
--cache-from type=registry,ref=$IMAGE_PATH:cache \
.
done
# -- CDK
- uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"
cache-dependency-path: |
oioi/cdk/package-lock.json
oioi/oioi-test-cdk/package-lock.json
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ env.CDK_DEFAULT_ACCOUNT }}:role/github-actions-role
aws-region: ${{ env.CDK_DEFAULT_REGION }}
- name: Deploy test cdk
working-directory: oioi
run: |
export BRANCH_NAME=$(echo "${{ github.event.ref }}" | tr "[:upper:]" "[:lower:]" | sed -e "s#refs/heads/##g" -e 's/\//-/g' -e 's/|/-/g')
echo $BRANCH_NAME
export STACK_NAME=$(echo $BRANCH_NAME | tr "[:upper:]" "[:lower:]" | tr -cd '[:alnum:]')
echo $STACK_NAME
cd cdk
npm ci
npm run build
cd ../oioi-test-cdk
npm ci
npx cdk bootstrap
npx cdk deploy --require-approval never
DNS_NAME=$(aws cloudformation describe-stacks \
--stack-name $STACK_NAME \
--query "Stacks[0].Outputs[?OutputKey=='LoadBalancerDnsName'].OutputValue" \
--output text)
echo $DNS_NAME
curl --fail http://$DNS_NAME
aws cloudformation delete-stack --stack-name $STACK_NAME