@@ -23,7 +23,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
23
23
source $ROOT /build/images.sh
24
24
source $ROOT /dev/util.sh
25
25
26
- images_with_builders =" operator proxy async-gateway enqueuer dequeuer controller- manager"
26
+ images_that_can_run_locally =" operator manager"
27
27
28
28
if [ -f " $ROOT /dev/config/env.sh" ]; then
29
29
source $ROOT /dev/config/env.sh
@@ -33,6 +33,7 @@ AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID:-}
33
33
AWS_REGION=${AWS_REGION:- }
34
34
35
35
skip_push=" false"
36
+ include_arm64_arch=" false"
36
37
positional_args=()
37
38
while [[ $# -gt 0 ]]; do
38
39
key=" $1 "
@@ -41,6 +42,10 @@ while [[ $# -gt 0 ]]; do
41
42
skip_push=" true"
42
43
shift
43
44
;;
45
+ --include-arm64-arch)
46
+ include_arm64_arch=" true"
47
+ shift
48
+ ;;
44
49
* )
45
50
positional_args+=(" $1 " )
46
51
shift
@@ -105,59 +110,55 @@ function create_ecr_repository() {
105
110
106
111
# ## HELPERS ###
107
112
108
- function build() {
109
- local image=$1
110
- local tag=$2
111
- local dir=" ${ROOT} /images/${image} "
112
-
113
- tag_args=" "
114
- if [ -n " $AWS_ACCOUNT_ID " ] && [ -n " $AWS_REGION " ]; then
115
- tag_args+=" -t $AWS_ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/cortexlabs/$image :$tag "
116
- fi
117
-
118
- blue_echo " Building $image :$tag ..."
119
- docker build $ROOT -f $dir /Dockerfile -t cortexlabs/$image :$tag $tag_args
120
- green_echo " Built $image :$tag \n"
121
- }
122
-
123
- function cache_builder() {
113
+ function build_and_push() {
124
114
local image=$1
115
+ local include_arm64_arch=$2
125
116
local dir=" ${ROOT} /images/${image} "
126
117
127
- blue_echo " Building $image -builder..."
128
- docker build $ROOT -f $dir /Dockerfile -t cortexlabs/$image -builder:$CORTEX_VERSION --target builder
129
- green_echo " Built $image -builder\n"
130
- }
118
+ set -euo pipefail
131
119
132
- function push() {
133
- if [ " $skip_push " = " true" ]; then
134
- return
120
+ if ! in_array $image " multi_arch_images" ; then
121
+ include_arm64_arch=" false"
135
122
fi
136
123
124
+ if [ ! -n " $AWS_ACCOUNT_ID " ] || [ ! -n " $AWS_REGION " ]; then
125
+ echo " AWS_ACCOUNT_ID or AWS_REGION env vars not found"
126
+ exit 1
127
+ fi
137
128
registry_login
138
129
139
- local image=$1
140
- local tag=$2
130
+ tag=$CORTEX_VERSION
131
+ if [ " $include_arm64_arch " = " true" ]; then
132
+ blue_echo " Building and pushing $image :$tag (amd64 and arm64)..."
133
+ else
134
+ blue_echo " Building and pushing $image :$tag (amd64)..."
135
+ fi
141
136
142
- blue_echo " Pushing $image : $tag ... "
143
- docker push $registry_push_url /cortexlabs/ $image : $tag
144
- green_echo " Pushed $image : $tag \n "
145
- }
137
+ platforms= " linux/amd64 "
138
+ if [ " $include_arm64_arch " = " true " ] ; then
139
+ platforms+= " ,linux/arm64 "
140
+ fi
146
141
147
- function build_and_push() {
148
- local image=$1
142
+ docker buildx build $ROOT -f $dir /Dockerfile -t $AWS_ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/cortexlabs/$image :$tag --platform $platforms --push
149
143
150
- set -euo pipefail # necessary since this is called in a new shell by parallel
144
+ if [ " $include_arm64_arch " = " true" ]; then
145
+ green_echo " Built and pushed $image :$tag (amd64 and arm64)..."
146
+ else
147
+ green_echo " Built and pushed $image :$tag (amd64)..."
148
+ fi
151
149
152
- tag=$CORTEX_VERSION
153
- build $image $tag
154
- push $image $tag
150
+ if [[ " $images_that_can_run_locally " =~ " $image " ]] && [[ " $include_arm64_arch " == " false" ]]; then
151
+ blue_echo " Exporting $image :$tag to local docker..."
152
+ docker buildx build $ROOT -f $dir /Dockerfile -t cortexlabs/$image :$tag -t $AWS_ACCOUNT_ID .dkr.ecr.$AWS_REGION .amazonaws.com/cortexlabs/$image :$tag --platform $platforms --load
153
+ green_echo " Exported $image :$tag to local docker..."
154
+ fi
155
155
}
156
156
157
157
function cleanup_local() {
158
158
echo " cleaning local repositories..."
159
159
docker container prune -f
160
160
docker image prune -f
161
+ docker buildx prune -f
161
162
}
162
163
163
164
function cleanup_ecr() {
@@ -195,14 +196,6 @@ function validate_env() {
195
196
fi
196
197
}
197
198
198
- # export functions for parallel command
199
- export -f build_and_push
200
- export -f push
201
- export -f build
202
- export -f blue_echo
203
- export -f green_echo
204
- export -f registry_login
205
-
206
199
# validate environment is correctly set on env.sh
207
200
validate_env
208
201
@@ -218,13 +211,9 @@ elif [ "$cmd" = "create" ]; then
218
211
# usage: registry.sh update-single IMAGE
219
212
elif [ " $cmd " = " update-single" ]; then
220
213
image=$sub_cmd
221
- if [[ " $images_with_builders " =~ " $image " ]]; then
222
- cache_builder $image
223
- fi
224
- build_and_push $image
214
+ build_and_push $image $include_arm64_arch
225
215
226
216
# usage: registry.sh update all|dev|api
227
- # if parallel utility is installed, the docker build commands will be parallelized
228
217
elif [ " $cmd " = " update" ]; then
229
218
images_to_build=()
230
219
@@ -236,20 +225,12 @@ elif [ "$cmd" = "update" ]; then
236
225
images_to_build+=( " ${dev_images[@]} " )
237
226
fi
238
227
239
- for image in $images_with_builders ; do
240
- if [[ " ${images_to_build[@]} " =~ " $image " ]]; then
241
- cache_builder $image
242
- fi
228
+ for image in " ${images_to_build[@]} " ; do
229
+ build_and_push $image $include_arm64_arch
243
230
done
244
231
245
- if command -v parallel & > /dev/null && [ -n " ${NUM_BUILD_PROCS+set} " ] && [ " $NUM_BUILD_PROCS " != " 1" ]; then
246
- is_registry_logged_in=$is_registry_logged_in ROOT=$ROOT registry_push_url=$registry_push_url SHELL=$( type -p /bin/bash) parallel --will-cite --halt now,fail=1 --eta --jobs $NUM_BUILD_PROCS build_and_push " {}" ::: " ${images_to_build[@]} "
247
- else
248
- for image in " ${images_to_build[@]} " ; do
249
- build_and_push $image
250
- done
251
- fi
252
-
232
+ # usage: registry.sh clean-cache
233
+ elif [ " $cmd " = " clean-cache" ]; then
253
234
cleanup_local
254
235
255
236
else
0 commit comments