Skip to content

Commit 9622653

Browse files
committed
CI/CD - use separate instance to build arm64 images (#2286)
# Conflicts: # .circleci/config.yml # build/build-image.sh # build/push-image.sh
1 parent 27fca9f commit 9622653

File tree

8 files changed

+219
-31
lines changed

8 files changed

+219
-31
lines changed

.circleci/config.yml

+91-14
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ commands:
7777
jobs:
7878
test:
7979
machine:
80-
image: ubuntu-1604:202104-01 # machine executor necessary to run go integration tests
80+
image: ubuntu-1604:202104-01
81+
resource_class: medium
8182
steps:
8283
- checkout
8384
- install-go
@@ -87,6 +88,17 @@ jobs:
8788
go get -u -v golang.org/x/lint/golint
8889
go get -u -v github.com/kyoh86/looppointer/cmd/looppointer
8990
pip3 install black aiohttp
91+
- run:
92+
name: Lint
93+
command: make lint
94+
95+
test:
96+
machine:
97+
image: ubuntu-1604:202104-01 # machine executor necessary to run go integration tests
98+
resource_class: medium
99+
steps:
100+
- checkout
101+
- install-go
90102
- run:
91103
name: Initialize Credentials
92104
command: |
@@ -112,30 +124,67 @@ jobs:
112124
name: Go Tests
113125
command: make test
114126

115-
build-and-deploy:
127+
build-and-upload-cli:
116128
docker:
117129
- image: cimg/python:3.6
118-
environment:
119-
DOCKER_CLI_EXPERIMENTAL: enabled
130+
resource_class: medium
120131
steps:
121132
- setup_remote_docker
122133
- checkout
123134
- install-go
124-
- run:
125-
name: Configure Docker Buildx
126-
command: |
127-
docker context create custom-context --default-stack-orchestrator swarm --docker "host=$DOCKER_HOST,ca=$DOCKER_CERT_PATH/ca.pem,cert=$DOCKER_CERT_PATH/cert.pem,key=$DOCKER_CERT_PATH/key.pem"
128-
docker buildx create --name builder --platform linux/amd64,linux/arm64 --use custom-context && docker buildx inspect --bootstrap
129135
- run: pip install awscli
130136
- run: make ci-build-cli
131137
- return-if-not-deployed-branch
132138
- run: make ci-build-and-upload-cli
139+
140+
build-and-push-images-amd64:
141+
machine:
142+
image: ubuntu-2004:202101-01
143+
resource_class: medium
144+
steps:
145+
- checkout
146+
- return-if-not-deployed-branch
147+
- run:
148+
name: Build CI Images (amd64)
149+
command: make ci-build-images-amd64
150+
no_output_timeout: 40m
133151
- quay-login
134152
- run:
135-
name: Build and Push CI Images
136-
command: |
137-
make ci-build-images
138-
make ci-push-images
153+
name: Push CI Images (amd64)
154+
command: make ci-push-images-amd64
155+
no_output_timeout: 40m
156+
157+
build-and-push-images-arm64:
158+
machine:
159+
image: ubuntu-2004:202101-01
160+
resource_class: arm.medium
161+
steps:
162+
- checkout
163+
- return-if-not-deployed-branch
164+
- run:
165+
name: Build CI Images (arm64)
166+
command: make ci-build-images-arm64
167+
no_output_timeout: 40m
168+
- quay-login
169+
- run:
170+
name: Push CI Images (arm64)
171+
command: make ci-push-images-arm64
172+
no_output_timeout: 40m
173+
174+
amend-images:
175+
docker:
176+
- image: cimg/python:3.6
177+
environment:
178+
DOCKER_CLI_EXPERIMENTAL: enabled
179+
resource_class: medium
180+
steps:
181+
- setup_remote_docker
182+
- checkout
183+
- return-if-not-deployed-branch
184+
- quay-login
185+
- run:
186+
name: Amend CI Images
187+
command: make ci-amend-images
139188
no_output_timeout: 40m
140189

141190
e2e-tests:
@@ -206,7 +255,7 @@ workflows:
206255
branches:
207256
only:
208257
- /^[0-9]+\.[0-9]+$/
209-
- build-and-deploy:
258+
- build-and-upload-cli:
210259
requires:
211260
- test
212261
- build-and-deploy-approval
@@ -215,6 +264,34 @@ workflows:
215264
only:
216265
- master
217266
- /^[0-9]+\.[0-9]+$/
267+
- build-and-push-images-amd64:
268+
requires:
269+
- build-and-upload-cli
270+
- build-and-deploy-approval
271+
filters:
272+
branches:
273+
only:
274+
- master
275+
- /^[0-9]+\.[0-9]+$/
276+
- build-and-push-images-arm64:
277+
requires:
278+
- build-and-upload-cli
279+
- build-and-deploy-approval
280+
filters:
281+
branches:
282+
only:
283+
- master
284+
- /^[0-9]+\.[0-9]+$/
285+
- amend-images:
286+
requires:
287+
- build-and-push-images-amd64
288+
- build-and-push-images-arm64
289+
- build-and-deploy-approval
290+
filters:
291+
branches:
292+
only:
293+
- master
294+
- /^[0-9]+\.[0-9]+$/
218295
nightly:
219296
triggers:
220297
- schedule:

Makefile

+13-4
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,20 @@ lint-docs:
200200
# CI Commands #
201201
###############
202202

203-
ci-build-images:
204-
@./build/build-images.sh
203+
ci-build-images-amd64:
204+
@./build/build-images.sh amd64 quay.io docker.io
205205

206-
ci-push-images:
207-
@./build/push-images.sh quay.io docker.io
206+
ci-build-images-arm64:
207+
@./build/build-images.sh arm64 quay.io docker.io
208+
209+
ci-push-images-amd64:
210+
@./build/push-images.sh amd64 quay.io docker.io
211+
212+
ci-push-images-arm64:
213+
@./build/push-images.sh arm64 quay.io docker.io
214+
215+
ci-amend-images:
216+
@./build/amend-images.sh quay.io docker.io
208217

209218
ci-build-cli:
210219
@./build/cli.sh

build/amend-image.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 Cortex Labs, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
set -euo pipefail
19+
20+
CORTEX_VERSION=0.37.0
21+
22+
host_primary=$1
23+
host_backup=$2
24+
image=$3
25+
26+
hosts=(
27+
"$host_primary"
28+
"$host_backup"
29+
)
30+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
31+
32+
for host in "${hosts[@]}"; do
33+
docker manifest create $host/cortexlabs/${image}:${CORTEX_VERSION} \
34+
-a $host/cortexlabs/${image}:manifest-${CORTEX_VERSION}-amd64 \
35+
-a $host/cortexlabs/${image}:manifest-${CORTEX_VERSION}-arm64
36+
docker manifest push $host/cortexlabs/${image}:${CORTEX_VERSION}
37+
done

build/amend-images.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 Cortex Labs, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
set -euo pipefail
19+
20+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
21+
22+
source $ROOT/build/images.sh
23+
source $ROOT/dev/util.sh
24+
25+
host_primary=$1
26+
host_backup=$2
27+
28+
for image in "${all_images[@]}"; do
29+
if in_array $image "multi_arch_images"; then
30+
$ROOT/build/amend-image.sh $host_primary $host_backup $image
31+
fi
32+
done

build/build-image.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,25 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
2121

2222
CORTEX_VERSION=0.37.0
2323

24-
image=$1
25-
platforms=$2
24+
host_primary=$1
25+
host_backup=$2
26+
image=$3
27+
is_multi_arch=$4
28+
arch=$5
2629

2730
if [ "$image" == "inferentia" ]; then
2831
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 790709498068.dkr.ecr.us-west-2.amazonaws.com
2932
fi
30-
docker buildx build $ROOT --progress plain -f $ROOT/images/$image/Dockerfile -t quay.io/cortexlabs/${image}:${CORTEX_VERSION} -t cortexlabs/${image}:${CORTEX_VERSION} --platform $platforms
33+
34+
if [ "$is_multi_arch" = "true" ]; then
35+
tag="manifest-${CORTEX_VERSION}-$arch"
36+
else
37+
tag="${CORTEX_VERSION}"
38+
fi
39+
40+
docker build $ROOT \
41+
--build-arg TARGETOS=linux \
42+
--build-arg TARGETARCH=$arch \
43+
-f $ROOT/images/$image/Dockerfile \
44+
-t $host_primary/cortexlabs/${image}:${tag} \
45+
-t $host_backup/cortexlabs/${image}:${tag}

build/build-images.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
2222
source $ROOT/build/images.sh
2323
source $ROOT/dev/util.sh
2424

25+
arch=$1
26+
host_primary=$2
27+
host_backup=$3
28+
2529
for image in "${all_images[@]}"; do
26-
platforms="linux/amd64"
30+
is_multi_arch="false"
2731
if in_array $image "multi_arch_images"; then
28-
platforms+=",linux/arm64"
32+
is_multi_arch="true"
33+
$ROOT/build/build-image.sh $host_primary $host_backup $image $is_multi_arch $arch
34+
elif [ "$arch" = "amd64" ]; then
35+
$ROOT/build/build-image.sh $host_primary $host_backup $image $is_multi_arch $arch
2936
fi
30-
$ROOT/build/build-image.sh $image $platforms
3137
done

build/push-image.sh

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ CORTEX_VERSION=0.37.0
2424
host_primary=$1
2525
host_backup=$2
2626
image=$3
27-
platforms=$4
27+
is_multi_arch=$4
28+
arch=$5
2829

2930
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
30-
docker buildx build $ROOT --progress plain -f $ROOT/images/$image/Dockerfile -t $host_primary/cortexlabs/${image}:${CORTEX_VERSION} -t $host_backup/cortexlabs/${image}:${CORTEX_VERSION} --platform $platforms --push
31+
32+
if [ "$is_multi_arch" = "true" ]; then
33+
tag="manifest-${CORTEX_VERSION}-$arch"
34+
else
35+
tag="${CORTEX_VERSION}"
36+
fi
37+
38+
docker push $host_primary/cortexlabs/${image}:${tag}
39+
docker push $host_backup/cortexlabs/${image}:${tag}

build/push-images.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
2222
source $ROOT/build/images.sh
2323
source $ROOT/dev/util.sh
2424

25-
host_primary=$1
26-
host_backup=$2
25+
arch=$1
26+
host_primary=$2
27+
host_backup=$3
2728

2829
for image in "${all_images[@]}"; do
29-
platforms="linux/amd64"
30+
is_multi_arch="false"
3031
if in_array $image "multi_arch_images"; then
31-
platforms+=",linux/arm64"
32+
is_multi_arch="true"
33+
$ROOT/build/push-image.sh $host_primary $host_backup $image $is_multi_arch $arch
34+
elif [ "$arch" = "amd64" ]; then
35+
$ROOT/build/push-image.sh $host_primary $host_backup $image $is_multi_arch $arch
3236
fi
33-
$ROOT/build/push-image.sh $host_primary $host_backup $image $platforms
3437
done

0 commit comments

Comments
 (0)