forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-pkgs.sh
executable file
·228 lines (208 loc) · 6.75 KB
/
parse-pkgs.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
# Poor man's[1] yml generator
#
#
# [1] A poor man is a man on a deadline.
#
# if this has problems, it should fail right away
set -e
EVE="$(cd "$(dirname "$0")" && pwd)/../"
PATH="$EVE/build-tools/bin:$PATH"
get_git_tag() {
echo "${EVE_HASH:-$(git tag -l --points-at HEAD | grep '[0-9]*\.[0-9]*\.[0-9]*' | head -1)}"
}
linuxkit_tag() {
local pkg="$1"
_linuxkit_tag 0 0 "${pkg}"
}
linuxkit_dev_tag() {
local pkg="$1"
_linuxkit_tag 0 1 "${pkg}"
}
linuxkit_kubevirt_tag() {
local pkg="$1"
_linuxkit_tag 1 0 "${pkg}"
}
linuxkit_kubevirt_dev_tag() {
local pkg="$1"
_linuxkit_tag 1 1 "${pkg}"
}
# Function returns tag generated by linuxkit for a given EVE package.
# Arguments: <is-kubevirt-build> <is-dev-build> <package>
# where <is-kubevirt-build> should be 1 if HV=kubevirt, 0 otherwise;
# <is-dev-build> should be 1 if DEV=y, 0 otherwise;
# <package> should be eve package name in the format "pkg/<name>" (e.g. "pkg/pillar").
_linuxkit_tag() {
local is_kubevirt_build="$1"
local is_dev_build="$2"
local pkg="$3"
local -a build_yml_cmd
if [[ "${is_dev_build}" == 1 && "${is_kubevirt_build}" == 1 ]]; then
build_yml_cmd=(--build-yml build-kubevirt-dev.yml)
elif [[ "${is_dev_build}" == 1 ]]; then
build_yml_cmd=(--build-yml build-dev.yml)
elif [[ "${is_kubevirt_build}" == 1 ]]; then
build_yml_cmd=(--build-yml build-kubevirt.yml)
fi
echo "$(linuxkit pkg show-tag "${build_yml_cmd[@]}" ${EVE_HASH:+--hash $EVE_HASH} "${EVE}/${pkg}")${ARCH}"
}
immutable_tag() {
# we have to resolve symbolic tags like x.y.z or snapshot to something immutable
# so that we can detect when the symbolic tag starts pointing a different immutable
# object and thus trigger a new SHA for things like EVE
docker inspect --format='{{.Id}}' "$1" 2>/dev/null ||
docker inspect --format='{{index .RepoDigests 0}}' "$1" 2>/dev/null ||
echo "$1"
}
external_tag() {
# Since the tag is external to us, we can't rely on local git SHAs,
# thus the best we can do is:
# 1. if we're building a release from a tag, we expect external tag to be the same
# 2. if we're NOT building from a tag, the external tag is simply snapshot
local TAG
TAG="$(get_git_tag)"
PKG="$1:${TAG:-snapshot}${ARCH}"
# for external packages we have to always try to pull first - otherwise
# we may have something stale in our local Docker cache
docker pull "$PKG" 2>/dev/null >&2 || echo "WARNING: couldn't fetch the latest $PKG - may be using stale cache" >&2
if docker inspect "$PKG" >/dev/null 2>&1 ; then
echo "$PKG"
else
echo "WARNING: failed to obtain $PKG - using $2 instead" >&2
echo "$2"
fi
}
synthetic_tag() {
NAME=$1
shift 1
# ignore undefined EVE_TAG in resolve_tags because not defined yet
# shellcheck disable=SC2086
echo ${NAME}:${EVE_HASH:-$( (cat "$@" ; git rev-parse HEAD) | resolve_tags | git hash-object --stdin)}"$ARCH"
}
resolve_tags() {
local tags="${1:-default}"
local file="${2:-default}"
if [ "$tags" != "default" ]; then
local sedcmd
sedcmd=$(echo "$tags" | sed -e "s/^/s#/g" -e "s/$/#g/g" -e "s/=/#/g")
sed -e "$sedcmd" "${file:-}"
fi
}
gen_tags() {
cat <<EOF
CURDIR=$(pwd)
ACRN_KERNEL_TAG=${ACRN_KERNEL_TAG}
KERNEL_TAG=${KERNEL_TAG}
FW_TAG=${FW_TAG}
XENTOOLS_TAG=${XENTOOLS_TAG}
DOM0ZTOOLS_TAG=${DOM0ZTOOLS_TAG}
RNGD_TAG=${RNGD_TAG}
XEN_TAG=${XEN_TAG}
ACRN_TAG=${ACRN_TAG}
DNSMASQ_TAG=${DNSMASQ_TAG}
TESTMSVCS_TAG=${TESTMSVCS_TAG}
PILLAR_TAG=${PILLAR_TAG}
PILLAR_DEV_TAG=${PILLAR_DEV_TAG}
PILLAR_KUBEVIRT_TAG=${PILLAR_KUBEVIRT_TAG}
PILLAR_KUBEVIRT_DEV_TAG=${PILLAR_KUBEVIRT_DEV_TAG}
STORAGE_INIT_TAG=${STORAGE_INIT_TAG}
WWAN_TAG=${WWAN_TAG}
WLAN_TAG=${WLAN_TAG}
GUACD_TAG=${GUACD_TAG}
GRUB_TAG=${GRUB_TAG}
UBOOT_TAG=${UBOOT_TAG}
GPTTOOLS_TAG=${GPTTOOLS_TAG}
NEWLOGD_TAG=${NEWLOGD_TAG}
NVIDIA_TAG=${NVIDIA_TAG}
EDGEVIEW_TAG=${EDGEVIEW_TAG}
WATCHDOG_TAG=${WATCHDOG_TAG}
MEMORY_MONITOR_TAG=${MEMORY_MONITOR_TAG}
MKRAW_TAG=${MKRAW_TAG}
MKISO_TAG=${MKISO_TAG}
MKCONF_TAG=${MKCONF_TAG}
DEBUG_TAG=${DEBUG_TAG}
VTPM_TAG=${VTPM_TAG}
UEFI_TAG=${UEFI_TAG}
EVE_TAG=${EVE_TAG:-}
KVMTOOLS_TAG=${KVMTOOLS_TAG}
IPXE_TAG=${IPXE_TAG}
KEXEC_TAG=${KEXEC_TAG}
KDUMP_TAG=${KDUMP_TAG}
BPFTRACE_TAG=${BPFTRACE_TAG}
MEASURE_CONFIG_TAG=${MEASURE_CONFIG_TAG}
BSP_IMX_TAG=${BSP_IMX_TAG}
APPARMOR_TAG=${APPARMOR_TAG}
KUBE_TAG=${KUBE_TAG}
RECOVERTPM_TAG=${RECOVERTPM_TAG}
UDEV_TAG=${UDEV_TAG}
INSTALLER_TAG=${INSTALLER_TAG}
EOF
}
if [ -z "$DOCKER_ARCH_TAG" ] ; then
case $(uname -m) in
x86_64) ARCH=-amd64
;;
aarch64) ARCH=-arm64
;;
*) echo "Unsupported architecture $(uname -m). Exiting" && exit 1
;;
esac
else
ARCH="-${DOCKER_ARCH_TAG}"
fi
ACRN_KERNEL_TAG=$(linuxkit_tag pkg/acrn-kernel)
FW_TAG=$(linuxkit_tag pkg/fw)
XENTOOLS_TAG=$(linuxkit_tag pkg/xen-tools)
XEN_TAG=$(linuxkit_tag pkg/xen)
ACRN_TAG=$(linuxkit_tag pkg/acrn)
GRUB_TAG=$(linuxkit_tag pkg/grub)
UBOOT_TAG=$(linuxkit_tag pkg/u-boot)
DNSMASQ_TAG=$(linuxkit_tag pkg/dnsmasq)
DOM0ZTOOLS_TAG=$(linuxkit_tag pkg/dom0-ztools)
RNGD_TAG=$(linuxkit_tag pkg/rngd)
NEWLOGD_TAG=$(linuxkit_tag pkg/newlog)
EDGEVIEW_TAG=$(linuxkit_tag pkg/edgeview)
WWAN_TAG=$(linuxkit_tag pkg/wwan)
WLAN_TAG=$(linuxkit_tag pkg/wlan)
GUACD_TAG=$(linuxkit_tag pkg/guacd)
PILLAR_TAG=$(linuxkit_tag pkg/pillar)
PILLAR_DEV_TAG=$(linuxkit_dev_tag pkg/pillar)
PILLAR_KUBEVIRT_TAG=$(linuxkit_kubevirt_tag pkg/pillar)
PILLAR_KUBEVIRT_DEV_TAG=$(linuxkit_kubevirt_dev_tag pkg/pillar)
STORAGE_INIT_TAG=$(linuxkit_tag pkg/storage-init)
GPTTOOLS_TAG=$(linuxkit_tag pkg/gpt-tools)
WATCHDOG_TAG=$(linuxkit_tag pkg/watchdog)
MEMORY_MONITOR_TAG=$(linuxkit_tag pkg/memory-monitor)
MKRAW_TAG=$(linuxkit_tag pkg/mkimage-raw-efi)
MKISO_TAG=$(linuxkit_tag pkg/mkimage-iso-efi)
MKCONF_TAG=$(linuxkit_tag pkg/mkconf)
NVIDIA_TAG=$(linuxkit_tag pkg/nvidia)
DEBUG_TAG=$(linuxkit_tag pkg/debug)
VTPM_TAG=$(linuxkit_tag pkg/vtpm)
UEFI_TAG=$(linuxkit_tag pkg/uefi)
KVMTOOLS_TAG=$(linuxkit_tag pkg/kvm-tools)
IPXE_TAG=$(linuxkit_tag pkg/ipxe)
KEXEC_TAG=$(linuxkit_tag pkg/kexec)
KDUMP_TAG=$(linuxkit_tag pkg/kdump)
BPFTRACE_TAG=$(linuxkit_tag pkg/bpftrace)
MEASURE_CONFIG_TAG=$(linuxkit_tag pkg/measure-config)
BSP_IMX_TAG=$(linuxkit_tag pkg/bsp-imx)
APPARMOR_TAG=$(linuxkit_tag pkg/apparmor)
KUBE_TAG=$(linuxkit_tag pkg/kube)
RECOVERTPM_TAG=$(linuxkit_tag pkg/recovertpm)
UDEV_TAG=$(linuxkit_tag pkg/udev)
INSTALLER_TAG=$(linuxkit_tag pkg/installer)
# Synthetic tags: the following tags are based on hashing
# the contents of all the Dockerfile.in that we can find.
# That way, these tags are guaranteed to change whenever
# *any* *single* dependency changes.
#
# These tags need to be declared last sine they depend
# on the previous tags being already defined.
EVE_TAG=$(synthetic_tag zededa/eve pkg/eve/Dockerfile.in)
TAGS=$(gen_tags)
if [ $# -ge 1 ]; then
resolve_tags "$TAGS" "$1"
else
echo "$TAGS"
fi