-
Notifications
You must be signed in to change notification settings - Fork 0
264 lines (231 loc) · 11.7 KB
/
build.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: build
on:
pull_request:
types: [opened, synchronize]
branches:
- main
paths:
- app-src/**
- cdk/**
permissions: {}
jobs:
build:
permissions:
contents: read
#runs-on: codebuild-AwsLabsMultiAZWorkshopArm64GithubRunner-${{ github.run_id }}-${{ github.run_attempt }}
runs-on: ubuntu-24.04-arm
env:
CDK_LOCATION: "cdk"
PROJECT_NAME: ${{ github.event.repository.name }}
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 0
BUILD_APP: false
USE_CODEBUILD: false
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Install dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0'
- name: Dotnet version update
if: env.USE_CODEBUILD == true
run: |
cat /codebuild/global.json
dotnet --info
jq '.sdk.version = "9.0.0"' /codebuild/global.json > temp.json && mv temp.json /codebuild/global.json
cat /codebuild/global.json
- name: Install cdk
run: |
npm install aws-cdk -g
cdk --version
- name: Create tmp
run: mkdir -p ${{ github.workspace }}/tmp
- name: Create assets
run: mkdir -p ${{ github.workspace }}/assets
- name: Set versions
run: |
# Read the JSON file and iterate over each key-value pair
for key in $(jq -r 'keys[]' ${{ github.workspace }}/build/versions.json); do
value=$(jq -r ".\"$key\"" ${{ github.workspace }}/build/versions.json)
echo "Setting environment variable for $key with value $value"
# Set the environment variable
echo "$key=$value" >> $GITHUB_ENV
done
- name: Create helm lambda layer
run: |
file=helm-v$HELM-linux-arm64.tar.gz
curl --location https://get.helm.sh/$file --output /tmp/$file
tar -zxvf /tmp/$file --directory /tmp
mkdir -p ${{ github.workspace }}/$CDK_LOCATION/layer/helm
cp /tmp/linux-arm64/helm ${{ github.workspace }}/$CDK_LOCATION/layer/helm/
chmod 0755 ${{ github.workspace }}/$CDK_LOCATION/layer/helm/helm
cd ${{ github.workspace }}/$CDK_LOCATION/layer
zip -r ${{ github.workspace }}/$CDK_LOCATION/helm-layer.zip .
- name: Copy destination rule
run: |
file=destination-rule.yaml
cp ${{ github.workspace }}/$CDK_LOCATION/Configs/$file ${{ github.workspace }}/assets/$file
- name: Get kubectl
run: |
file=kubectl
curl --location https://dl.k8s.io/release/v$KUBECTL/bin/linux/arm64/$file --output ${{ github.workspace }}/assets/$file
- name: Get istio helm charts
run: |
BASE=https://istio-release.storage.googleapis.com/charts
istio_deps=("base-$ISTIO.tgz" "istiod-$ISTIO.tgz" "gateway-$ISTIO.tgz" "cni-$ISTIO.tgz")
for file in ${istio_deps[@]}; do
curl --location $BASE/$file --output ${{ github.workspace }}/assets/$file
done
- name: Get AWS load balancer controller helm chart
run: |
file=aws-load-balancer-controller-$LB_CONTROLLER_HELM.tgz
curl --location https://aws.github.io/eks-charts/$file --output ${{ github.workspace }}/assets/$file
- name: Pull istio containers
run: |
MAX_RETRIES=10
SLEEP_INTERVAL=2
IMAGES=(install-cni proxyv2 pilot)
if [[ "$USE_CODEBUILD" == "true" ]]; then
ACCOUNT_ID=$(echo "$CODEBUILD_BUILD_ARN" | cut -d':' -f5)
BASE=$ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/docker-hub
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
else
BASE=docker.io
fi
for image in "${IMAGES[@]}"; do
SOURCE=$BASE/istio/$image:$ISTIO
docker pull $SOURCE
retries=0
while ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^$SOURCE$"; do
if [ "$retries" -ge "$MAX_RETRIES" ]; then
echo "Image $SOURCE did not appear in 'docker images' after $((MAX_RETRIES * SLEEP_INTERVAL)) seconds. Exiting."
exit 1
fi
echo "Retry $((retries+1))/$MAX_RETRIES - Image not found yet. Retrying in $SLEEP_INTERVAL seconds..."
sleep "$SLEEP_INTERVAL"
retries=$((retries+1))
done
docker tag $SOURCE istio/$image:$ISTIO
docker save istio/$image:$ISTIO | gzip > ${{ github.workspace }}/assets/$image.tar.gz
done
- name: Pull load balancer controller container image
run: |
BASE=public.ecr.aws
file="eks/aws-load-balancer-controller:$LB_CONTROLLER_CONTAINER-linux_arm64"
docker pull $BASE/$file
name=$(echo $file | cut -d '/' -f2 | cut -d ':' -f1)
docker save $BASE/$file | gzip > ${{ github.workspace }}/assets/$name.tar.gz
- name: Pull cloudwatch agent container image
run: |
BASE=public.ecr.aws
file="cloudwatch-agent/cloudwatch-agent:latest"
docker pull $BASE/$file
docker tag $BASE/$file $file
name=$(echo $file | cut -d '/' -f2 | cut -d ':' -f1)
docker save $file | gzip > ${{ github.workspace }}/assets/$name.tar.gz
- name: Pull docker compose
run: curl -SL https://github.com/docker/compose/releases/download/v2.32.4/docker-compose-linux-aarch64 -o ${{ github.workspace }}/assets/docker-compose
- name: Build arm64 web app
if: env.BUILD_APP == true
run: |
rm -rf ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output/src
cd ${{ github.workspace }}/app-src
dotnet restore
dotnet publish --configuration Release --runtime linux-arm64 --output ${{ github.workspace }}/app-src/output/src -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true --self-contained
cd ${{ github.workspace }}/app-src/output
zip -r ${{ github.workspace }}/assets/app_arm64.zip src/
cd ${{ github.workspace }}/app-src
zip -r ${{ github.workspace }}/assets/app_arm64.zip scripts/ appspec.yml
rm -rf ${{ github.workspace }}/app-src/output
- name: Build failing arm64 web app
if: env.BUILD_APP == true
run: |
rm -rf ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output/src
cd ${{ github.workspace }}/app-src
dotnet publish --configuration Release --runtime linux-arm64 --output ${{ github.workspace }}/app-src/output/src -p:DefineConstants="FAIL" -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true --self-contained
cd ${{ github.workspace }}/app-src/output
zip -r ${{ github.workspace }}/assets/app_arm64_fail.zip src/
cd ${{ github.workspace }}/app-src
zip -r ${{ github.workspace }}/assets/app_arm64_fail.zip scripts/ appspec.yml
rm -rf ${{ github.workspace }}/app-src/output
#- name: Set up docker buildx
# uses: docker/setup-buildx-action@v3
- name: Build arm64 container
run: |
rm -rf ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output/src
cd ${{ github.workspace }}/app-src
dotnet publish --configuration Release --runtime linux-musl-arm64 --output ${{ github.workspace }}/app-src/output/src -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true --self-contained
cd ${{ github.workspace }}/app-src/output
docker build --tag $PROJECT_NAME:latest --platform linux/arm64 --build-arg SRC=src --file ${{ github.workspace }}/build/dockerfile .
docker save $PROJECT_NAME:latest | gzip > ${{ github.workspace }}/assets/container.tar.gz
zip -j ${{ github.workspace }}/assets/app_deploy.zip ${{ github.workspace }}/assets/container.tar.gz
zip -j ${{ github.workspace }}/assets/app_deploy.zip ${{ github.workspace }}/assets/cloudwatch-agent.tar.gz
cd ${{ github.workspace }}/app-src
zip -r ${{ github.workspace }}/assets/app_deploy.zip docker/
cd ${{ github.workspace }}/app-src/docker
zip ${{ github.workspace }}/assets/app_deploy.zip appspec.yml
rm -rf ${{ github.workspace }}/app-src/output
- name: Build failing arm64 container
run: |
rm -rf ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output
mkdir -p ${{ github.workspace }}/app-src/output/src
cd ${{ github.workspace }}/app-src
dotnet publish --configuration Release --runtime linux-musl-arm64 --output ${{ github.workspace }}/app-src/output/src -p:DefineConstants="FAIL" -p:PublishReadyToRun=true -p:PublishReadyToRunShowWarnings=true --self-contained
cd ${{ github.workspace }}/app-src/output
docker build --tag $PROJECT_NAME:latest --platform linux/arm64 --build-arg SRC=src --file ${{ github.workspace }}/build/dockerfile .
docker save $PROJECT_NAME:latest | gzip > /tmp/container.tar.gz
zip -j ${{ github.workspace }}/assets/app_deploy_fail.zip /tmp/container.tar.gz
zip -j ${{ github.workspace }}/assets/app_deploy_fail.zip ${{ github.workspace }}/assets/cloudwatch-agent.tar.gz
cd ${{ github.workspace }}/app-src
zip -r ${{ github.workspace }}/assets/app_deploy_fail.zip docker/
cd ${{ github.workspace }}/app-src/docker
zip ${{ github.workspace }}/assets/app_deploy_fail.zip appspec.yml
rm -f /tmp/container.tar.gz
rm -rf ${{ github.workspace }}/app-src/output
- name: Build assets
run: |
cd ${{ github.workspace }}/$CDK_LOCATION
cdk synth --quiet
chmod +x ${{ github.workspace }}/build/package.py
${{ github.workspace }}/build/package.py $PROJECT_NAME ${{ github.workspace }} $CDK_LOCATION
cd ${{ github.workspace }}/assets
zip -r ${{ github.workspace }}/content.zip .
cp ${{ github.workspace }}/static/$PROJECT_NAME.json ${{ github.workspace }}/$PROJECT_NAME.template
cd ${{ github.workspace }}
zip ${{ github.workspace }}/content.zip $PROJECT_NAME.template
cp ${{ github.workspace }}/content.zip ${{ github.workspace }}/assets
- name: Upload workshop artifact
uses: actions/upload-artifact@v4
with:
name: WorkshopArtifact
path: |
${{ github.workspace }}/static
${{ github.workspace }}/content
${{ github.workspace }}/contentspec.yaml
- name: Upload assets artifact
uses: actions/upload-artifact@v4
with:
name: AssetsArtifact
path: ${{ github.workspace }}/assets/**/*
- name: Upload content artifact
uses: actions/upload-artifact@v4
with:
name: ContentArtifact
path: ${{ github.workspace }}/content.zip
- name: Save PR Number
run: echo "${{ github.event.pull_request.number }}" > pr_number.txt
- name: Upload PR Number Artifact
uses: actions/upload-artifact@v4
with:
name: PullRequestNumber
path: pr_number.txt