@@ -23,7 +23,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
2323source $ROOT /build/images.sh
2424source $ROOT /dev/util.sh
2525
26- images_with_builders =" operator proxy async-gateway enqueuer dequeuer controller- manager"
26+ images_that_can_run_locally =" operator manager"
2727
2828if [ -f " $ROOT /dev/config/env.sh" ]; then
2929 source $ROOT /dev/config/env.sh
@@ -33,6 +33,7 @@ AWS_ACCOUNT_ID=${AWS_ACCOUNT_ID:-}
3333AWS_REGION=${AWS_REGION:- }
3434
3535skip_push=" false"
36+ include_arm64_arch=" false"
3637positional_args=()
3738while [[ $# -gt 0 ]]; do
3839 key=" $1 "
@@ -41,6 +42,10 @@ while [[ $# -gt 0 ]]; do
4142 skip_push=" true"
4243 shift
4344 ;;
45+ --include-arm64-arch)
46+ include_arm64_arch=" true"
47+ shift
48+ ;;
4449 * )
4550 positional_args+=(" $1 " )
4651 shift
@@ -105,59 +110,55 @@ function create_ecr_repository() {
105110
106111# ## HELPERS ###
107112
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() {
124114 local image=$1
115+ local include_arm64_arch=$2
125116 local dir=" ${ROOT} /images/${image} "
126117
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
131119
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"
135122 fi
136123
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
137128 registry_login
138129
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
141136
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
146141
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
149143
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
151149
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
155155}
156156
157157function cleanup_local() {
158158 echo " cleaning local repositories..."
159159 docker container prune -f
160160 docker image prune -f
161+ docker buildx prune -f
161162}
162163
163164function cleanup_ecr() {
@@ -195,14 +196,6 @@ function validate_env() {
195196 fi
196197}
197198
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-
206199# validate environment is correctly set on env.sh
207200validate_env
208201
@@ -218,13 +211,9 @@ elif [ "$cmd" = "create" ]; then
218211# usage: registry.sh update-single IMAGE
219212elif [ " $cmd " = " update-single" ]; then
220213 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
225215
226216# usage: registry.sh update all|dev|api
227- # if parallel utility is installed, the docker build commands will be parallelized
228217elif [ " $cmd " = " update" ]; then
229218 images_to_build=()
230219
@@ -236,20 +225,12 @@ elif [ "$cmd" = "update" ]; then
236225 images_to_build+=( " ${dev_images[@]} " )
237226 fi
238227
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
243230 done
244231
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
253234 cleanup_local
254235
255236else
0 commit comments