This repository has been archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·116 lines (94 loc) · 3.54 KB
/
build.sh
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
#!/usr/bin/env bash
set -e
for i in "$@"
do
case $i in
-nv=*|--nuclio-version=*)
NUCLIO_LABEL="${i#*=}"
shift # past argument=value
;;
-prin=*|--prebaked-registry-image-name=*)
PREBAKED_REGISTRY_IMAGE_NAME="${i#*=}"
shift # past argument=value
;;
-bri=*|--base-registry-image=*)
BASE_REGISTRY_IMAGE="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
if [[ -z ${NUCLIO_LABEL} ]]; then
printf "NUCLIO_LABEL not provided, cannot perform build\n"
exit 1
fi
if [[ -z ${PREBAKED_REGISTRY_IMAGE_NAME} ]]; then
printf "PREBAKED_REGISTRY_IMAGE_NAME not provided, cannot perform build\n"
exit 1
fi
if [[ -z ${BASE_REGISTRY_IMAGE} ]]; then
printf "BASE_REGISTRY_IMAGE not provided, cannot perform build\n"
exit 1
fi
printf "NUCLIO_LABEL = ${NUCLIO_LABEL}\n"
printf "PREBAKED_REGISTRY_IMAGE_NAME = ${PREBAKED_REGISTRY_IMAGE_NAME}\n"
printf "BASE_REGISTRY_IMAGE = ${BASE_REGISTRY_IMAGE}\n"
printf "\n"
printf "\n## Pulling muted-registry ${BASE_REGISTRY_IMAGE}\n"
docker pull ${BASE_REGISTRY_IMAGE}
printf "\n## Releasing prebaked-registry-nuclio version ${NUCLIO_LABEL}, with images from nuclio ${NUCLIO_LABEL}\n"
docker rm -f prebaked-registry-nuclio || true
printf "\n## Running local registry: ${BASE_REGISTRY_IMAGE} \n"
docker run --user 1000:1000 --rm -d -p 5000:5000 --name=prebaked-registry-nuclio ${BASE_REGISTRY_IMAGE}
IMAGES_TO_BAKE=(
"python:2.7-alpine"
"python:3.6"
"mcr.microsoft.com/dotnet/core/runtime:3.1"
"alpine:3.7"
"alpine:3.11"
"openjdk:9-jre-slim"
"node:10.3-alpine"
"ruby:2.4.4-alpine"
"quay.io/nuclio/processor:${NUCLIO_LABEL}-amd64"
"quay.io/nuclio/handler-builder-python-onbuild:${NUCLIO_LABEL}-amd64"
"quay.io/nuclio/handler-builder-golang-onbuild:${NUCLIO_LABEL}-amd64"
"quay.io/nuclio/handler-builder-golang-onbuild:${NUCLIO_LABEL}-amd64-alpine"
"quay.io/nuclio/handler-builder-nodejs-onbuild:${NUCLIO_LABEL}-amd64"
"quay.io/nuclio/handler-builder-java-onbuild:${NUCLIO_LABEL}-amd64"
"quay.io/nuclio/handler-builder-dotnetcore-onbuild:${NUCLIO_LABEL}-amd64"
"quay.io/nuclio/handler-builder-ruby-onbuild:${NUCLIO_LABEL}-amd64"
)
printf "\nResolved images to bake:\n"
printf '%s\n' "${IMAGES_TO_BAKE[@]}"
# PULL IMAGES
echo "${IMAGES_TO_BAKE[@]}" | xargs -n 1 -P 3 docker pull
# RETAG
RETAGGED_IMAGES=()
for ORIG_IMAGE in "${IMAGES_TO_BAKE[@]}"
do
declare RETAGGED_IMAGE
RETAGGED_IMAGE="localhost:5000/"${ORIG_IMAGE#*/}
printf "\n### Tagging image to local prebaked registry\n"
echo $RETAGGED_IMAGE
docker tag $ORIG_IMAGE $RETAGGED_IMAGE
RETAGGED_IMAGES+=($RETAGGED_IMAGE)
done
# PUSH
printf "\n### Pushing images to prebaked registry\n"
printf '%s\n' "${RETAGGED_IMAGES[@]}"
echo "${RETAGGED_IMAGES[@]}" | xargs -n 1 -P 5 docker push
printf "\n## View catalog - Listing baked images in registry\n"
http get localhost:5000/v2/_catalog
printf "\n## Commiting prebaked local registry image\n"
declare PREBAKED_REGISTRY_IMAGE
PREBAKED_REGISTRY_IMAGE="${PREBAKED_REGISTRY_IMAGE_NAME}:${NUCLIO_LABEL}"
docker commit --message "Baking nuclio images for ${NUCLIO_LABEL}" prebaked-registry-nuclio ${PREBAKED_REGISTRY_IMAGE}
docker rm -f prebaked-registry-nuclio
printf "\n## Completed building prebaked-registry for nuclio - image: ${PREBAKED_REGISTRY_IMAGE}\n"
# For visual verification
printf "\n## Running prebaked local registry to validate content\n"
docker run --user 1000:1000 --rm -d -p 5000:5000 --name=prebaked-registry-nuclio ${PREBAKED_REGISTRY_IMAGE}
http get localhost:5000/v2/_catalog
docker rm -f prebaked-registry-nuclio