-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·174 lines (153 loc) · 3.48 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
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
#! /usr/bin/env sh
set -e
__numonic_build()
{
platforms=
images=
shells=
runtime=
while :; do
case $1 in
-d|--debug)
debug=1
;;
-dr|--dry-run)
dry_run=1
;;
-i|--image)
images="${images} ${2}"
shift
;;
--image=*)
images="${images} ${1#*=}"
;;
-o|--org)
GITHUB_ORG="${2}"
;;
--org=*)
GITHUB_ORG="${1#*=}"
;;
-p|--platform)
platforms="${platforms},${2}"
shift
;;
--platform=*)
platforms="${platforms},${1#*=}"
;;
-r|--ref)
GITHUB_REF="${2}"
shift
;;
-cr|--runtime)
runtime="${2}"
shift
;;
--runtime=*)
runtime="${1#*=}"
;;
--ref=*)
GITHUB_REF="${1#*=}"
;;
-sha|--sha)
GITHUB_SHA="${2}"
shift
;;
--sha=*)
GITHUB_SHA="${1#*=}"
;;
-s|--shell)
shells="${shells} ${2}"
shift
;;
--shell=*)
shells="${shells} ${1#*=}"
;;
?*)
printf "\nbuild: unknown argument: %s\n" "${1}"
exit 1
;;
*)
break
;;
esac
shift
done
if [ -z "${platforms:-}" ]; then
platforms="linux/amd64,linux/arm64"
fi
if [ -z "${images:-}" ]; then
images="ubuntu:20.04 ubuntu:21.10 debian:10 debian:11 fedora:34 fedora:35 amazonlinux:2 centos:8"
fi
if [ -z "${shells:-}" ]; then
shells="bash zsh"
fi
if [ -z "${runtime:-}" ]; then
if command -v nerdctl 1>/dev/null 2>&1; then
runtime="nerdctl"
elif command -v podman 1>/dev/null 2>&1; then
runtime="podman"
elif command -v docker 1>/dev/null 2>&1; then
runtime="docker"
else
printf "\nbuild: no supported contianer runtime found\n"
return 1
fi
fi
platforms="${platforms#,}"
GITHUB_SHA=${GITHUB_SHA:-$(git rev-parse HEAD)}
GITHUB_REF=${GITHUB_REF:=$(git rev-parse --abbrev-ref HEAD)}
GITHUB_ORG=${GITHUB_ORG:-"automotivemastermind"}
# set up the args to the build command
set -- \
--platform="${platforms}" \
--label=org.opencontainers.image.name=numonic \
--label=org.opencontainers.image.revision="${GITHUB_SHA}" \
--label=org.opencontainers.image.version="${GITHUB_REF}" \
--label=org.opencontainers.image.vendor="automotiveMastermind" \
--label=org.opencontainers.image.licenses="MIT" \
--label=org.opencontainers.image.source="https://github.com/${GITHUB_ORG}/numonic"
(
if [ -n "${debug:-}" ]; then
set -x
fi
# iterate over each image
for image in ${images}; do
# get the name
from_repo=${image%%\:*}
from_tag=${image##*\:}
# determine if a version was specified
if [ -n "${from_tag}" ] && [ "${from_repo}" != "${from_tag}" ]; then
name="${from_repo}-${from_tag}"
else
name="${from_repo}"
from_tag="latest"
fi
# iterate over each shell
for shell in ${shells}; do
# setup the manifest
tag="numonic:${name}-${shell}"
printf 'BUILD FOR %s\n' "${tag}"
printf '%s build\n' "${runtime}"
printf '\t%s\n' "$@"
printf '\t%s\n' --build-arg=FROM_REPO="${from_repo}"
printf '\t%s\n' --build-arg=FROM_TAG="${from_tag}"
printf '\t%s\n' --build-arg=NUMONIC_SHELL="${shell}"
printf '\t%s\n\n' --tag="${tag}"
if [ -n "${dry_run:-}" ]; then
continue
fi
# add the shell to the build command
"${runtime}" build "$@" \
--build-arg=IMAGE="${image}" \
--build-arg=NUMONIC_SHELL="${shell}" \
--tag="${tag}" \
"${PWD}"
"${runtime}" run \
--volume="${PWD}:/testing" \
--workdir=/testing "${tag}" \
./hack/test.sh
done
done
)
}
__numonic_build "$@"