-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathonload_mkcontainer
executable file
·174 lines (145 loc) · 5.43 KB
/
onload_mkcontainer
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
#!/bin/bash -e
# SPDX-License-Identifier: BSD-2-Clause
# X-SPDX-Copyright-Text: (c) Copyright 2023 Advanced Micro Devices, Inc.
bin=$(cd "$(dirname "$0")" && /bin/pwd)
source "${bin}/lib/mkdist/utils"
usage() {
err
err "Usage:"
err " $me [OPTIONS] [MKDIST_TGZ]"
err
err "Options:"
err " -u, --user [onload-user:latest|AUTO] Build onload-user image"
err " -s, --source [onload-source:latest|AUTO] Build onload-source image"
err " -f, --user-from-source [SOURCE_IMAGE] User image using source image"
err " -r, --repo-url Label image with 'source' URL"
err " -o, --output-vars Print mkdist variables"
err " -d, --debug Debug this script"
err
err "Env vars:"
err " SOURCE_DOCKER_EXTRA_ARGS Source image extra args"
err " USER_DOCKER_EXTRA_ARGS User image extra args"
err
exit 1
}
user=false
source=false
output_vars=false
tarball_path=
source_image=
user_image=
repo_url=
context="$bin/../"
while [ $# -gt 0 ]; do
case "$1" in
-u|--user) user=true; shift; user_image="$1";;
-s|--source) source=true; shift; source_image="$1";;
-f|--user-from-source) shift; source_image="$1";;
-r|--repo-url) shift; repo_url="$1";;
-o|--output-vars) output_vars=true;;
-d|--debug) set -x;;
*.tgz|*.tar.gz) { [ -z "$tarball_path" ] && tarball_path="$1"; } || fail "Supply one tarball only.";;
-*) usage;;
*) break;;
esac
shift
done
[ $# = 0 ] || usage
if [ -n "$tarball_path" ]; then
tarball_name=$(basename "$tarball_path")
tarball_subdir=$(tar tf "$tarball_path" | head -1 | tr -d '/')
context=$(dirname "$tarball_path")
readme_date=; readme_revision=; readme_version=
readme_vars=$(tar xzf "$tarball_path" -O "$tarball_subdir/README" | sed '0,/^==========$/d;s/^\s*\(\w*\):\s\(.*\)/readme_\1="\2"/')
eval "$readme_vars"
product=${readme_version%-*}
version=${readme_version#*-}
readme_date_C=$(echo "$readme_date" | sed -E 's/^(\w+) +([0-9]+) +(\w+)/\1 \3 \2/' || echo "$readme_date")
created="$(date --date="$readme_date_C" --rfc-3339=seconds || echo "$readme_date")"
revision="$readme_revision"
elif $source; then
err "Missing an Onload distribution tarball (output of onload_mkdist)."
usage
elif [ -n "$source_image" ]; then
docker inspect "$source_image" >/dev/null 2>&1 || docker pull "$source_image"
product=$(docker inspect -f '{{index .Config.Labels "com.amd.onload.product"}}' "$source_image")
brand=$(docker inspect -f '{{index .Config.Labels "com.amd.onload.brand"}}' "$source_image")
version=$(docker inspect -f '{{index .Config.Labels "org.opencontainers.image.version"}}' "$source_image")
revision=$(docker inspect -f '{{index .Config.Labels "org.opencontainers.image.revision"}}' "$source_image")
created=$(docker inspect -f '{{index .Config.Labels "org.opencontainers.image.created"}}' "$source_image")
source_image_digest=$(docker inspect -f '{{.Id}}' "$source_image")
if [ -z "$product" ]; then
err "Supplied source image does not contain expected LABELs. Continuing anyway."
product=onload
fi
else
err "Supply either path to Onload distribution tarball (output of onload_mkdist)"
err "or existing onload-source container image."
usage
fi
if [ -z "$brand" ]; then
case "$product" in
onload) brand='OpenOnload';;
enterpriseonload) brand='EnterpriseOnload';;
*) brand=Onload;;
esac
fi
if $source; then
[ "$source_image" == "AUTO" ] && source_image="${product}-source:${version}"
iidfile=$(mktemp)
# shellcheck disable=SC2086
DOCKER_BUILDKIT=1 docker build \
--file scripts/onload-user.Dockerfile \
--target onload-source-subdir \
--tag "$source_image" \
--network="host" \
--build-arg BRAND="$brand" \
--build-arg PRODUCT="$product" \
--build-arg VERSION="$version" \
--build-arg REVISION="$revision" \
--build-arg CREATED="$created" \
--build-arg SOURCE="$repo_url" \
--build-arg ONLOAD_LOCATION="$tarball_name" \
--iidfile=$iidfile \
$SOURCE_DOCKER_EXTRA_ARGS \
"$context"
source_image_digest=$(cat "$iidfile")
rm "$iidfile"
fi
if $user; then
[ "$user_image" == "AUTO" ] && user_image="${product}-user:${version}"
[ -z "$source_image" ] && ! $source && source_image=onload-source-subdir
# shellcheck disable=SC2086
DOCKER_BUILDKIT=1 docker build \
--file scripts/onload-user.Dockerfile \
--tag "$user_image" \
--network="host" \
--build-arg BRAND="$brand" \
--build-arg PRODUCT="$product" \
--build-arg VERSION="$version" \
--build-arg REVISION="$revision" \
--build-arg CREATED="$(date --rfc-3339=seconds || echo "$created")" \
--build-arg SOURCE_IMAGE="$source_image" \
--build-arg SOURCE_IMAGE_DIGEST="$source_image_digest" \
--build-arg SOURCE="$repo_url" \
--build-arg ONLOAD_LOCATION="$tarball_name" \
$USER_DOCKER_EXTRA_ARGS \
"$context"
elif [ -n "$source_image" ] && ! $source; then
err "Supply --user output image when building from existing source."
$output_vars || usage
fi
if $output_vars; then
echo "tarball_name=\"$tarball_name\""
echo "tarball_subdir=\"$tarball_subdir\""
echo "context=\"$context\""
echo "$readme_vars"
echo "created=\"$created\""
echo "product=\"$product\""
echo "version=\"$version\""
echo "revision=\"$revision\""
echo "source_image_digest=$source_image_digest"
echo "brand=\"$brand\""
echo "source_image=$source_image"
echo "user_image=$user_image"
fi