Skip to content

Commit 25a5143

Browse files
committed
feat: Add provision flags to download ARM binaries
Also take care of any backwards compatibility for those downloading earlier firecracker versions which were named differently. The user input validation is fairly naive because I did not want to get too clever and allow endless options.
1 parent 67a19de commit 25a5143

File tree

1 file changed

+64
-6
lines changed

1 file changed

+64
-6
lines changed

hack/scripts/provision.sh

+64-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ OPT_UNATTENDED=false
1313
DEVELOPMENT=false
1414
DEFAULT_VERSION="latest"
1515
DEFAULT_BRANCH="main"
16+
ARCH=amd64
1617

1718
# paths to be set later, put here to be explicit
1819
CONTAINERD_CONFIG_PATH=""
@@ -26,7 +27,6 @@ DEVPOOL_DATA=""
2627
# firecracker
2728
FIRECRACKER_VERSION="${FIRECRACKER:=$DEFAULT_VERSION}"
2829
FIRECRACKER_BIN="firecracker"
29-
FIRECRACKER_RELEASE_BIN="firecracker"
3030
FIRECRACKER_REPO="weaveworks/firecracker"
3131

3232
# containerd
@@ -38,7 +38,6 @@ CONTAINERD_REPO="containerd/containerd"
3838
FLINTLOCK_VERSION="${FLINTLOCK:=$DEFAULT_VERSION}"
3939
FLINTLOCK_BIN="flintlockd"
4040
FLINTLOCK_REPO="weaveworks/flintlock"
41-
FLINTLOCK_RELEASE_BIN="flintlockd_amd64"
4241
FLINTLOCKD_SERVICE_FILE="/etc/systemd/system/flintlockd.service"
4342
FLINTLOCKD_CONFIG_PATH="/etc/opt/flintlockd/config.yaml"
4443

@@ -150,7 +149,9 @@ build_release_url() {
150149
# If/when we need to support others, we can ammend
151150
build_containerd_release_bin_name() {
152151
local tag=${1//v/} # remove the 'v' from arg $1
153-
echo "containerd-$tag-linux-amd64.tar.gz"
152+
local arch="$2"
153+
154+
echo "containerd-$tag-linux-$arch.tar.gz"
154155
}
155156

156157
# Returns the desired binary download url for a repo, tag and binary
@@ -188,6 +189,19 @@ build_containerd_paths() {
188189
## DOER FUNCS
189190
#
190191
#
192+
# Checks user input for valid architecture and sets the global value for pulling
193+
# correct binaries.
194+
set_arch() {
195+
local input="$1"
196+
197+
if [[ "$input" == *"arm"* ]]; then
198+
ARCH=arm64
199+
elif [[ "$input" == *"amd"* ]]; then
200+
ARCH=amd64
201+
else
202+
die "Unknown arch: $1. Choose either 'arm' or 'amd'"
203+
fi
204+
}
191205
# Returns the tag associated with a "latest" release
192206
latest_release_tag() {
193207
# shellcheck disable=SC2155
@@ -243,13 +257,21 @@ start_service() {
243257
# Fetch and install the firecracker binary
244258
install_firecracker() {
245259
local tag="$1"
260+
246261
say "Installing firecracker version $tag to $INSTALL_PATH"
247262

248263
if [[ "$tag" == "$DEFAULT_VERSION" ]]; then
249264
tag=$(latest_release_tag "$FIRECRACKER_REPO")
250265
fi
251266

252-
url=$(build_download_url "$FIRECRACKER_REPO" "$tag" "$FIRECRACKER_RELEASE_BIN")
267+
bin_name="${FIRECRACKER_BIN}_${ARCH}"
268+
269+
# older firecracker macvtap releases had binaries with different names
270+
if is_older_version "$tag"; then
271+
bin_name="$FIRECRACKER_BIN"
272+
fi
273+
274+
url=$(build_download_url "$FIRECRACKER_REPO" "$tag" "$bin_name")
253275
install_release_bin "$url" "$FIRECRACKER_BIN" || die "could not install firecracker"
254276

255277
"$FIRECRACKER_BIN" --version &>/dev/null
@@ -258,6 +280,13 @@ install_firecracker() {
258280
say "Firecracker version $tag successfully installed"
259281
}
260282

283+
is_older_version() {
284+
local tag="$1"
285+
local cutoff="v1.1.1-macvtap"
286+
287+
[[ "$tag" == $(printf "$tag\n$cutoff" | sort -V | head -n 1) && "$tag" != "$cutoff" ]]
288+
}
289+
261290
## FLINTLOCK
262291
#
263292
#
@@ -285,13 +314,14 @@ do_all_flintlock() {
285314
# Fetch and install the flintlockd binary at the specified version
286315
install_flintlockd() {
287316
local tag="$1"
317+
288318
say "Installing flintlockd version $tag to $INSTALL_PATH"
289319

290320
if [[ "$tag" == "$DEFAULT_VERSION" ]]; then
291321
tag=$(latest_release_tag "$FLINTLOCK_REPO")
292322
fi
293323

294-
url=$(build_download_url "$FLINTLOCK_REPO" "$tag" "$FLINTLOCK_RELEASE_BIN")
324+
url=$(build_download_url "$FLINTLOCK_REPO" "$tag" "${FLINTLOCK_BIN}_${ARCH}")
295325
install_release_bin "$url" "$FLINTLOCK_BIN"
296326

297327
"$FLINTLOCK_BIN" version &>/dev/null
@@ -359,6 +389,7 @@ lookup_address() {
359389
do_all_containerd() {
360390
local version="$1"
361391
local thinpool="$2"
392+
362393
install_containerd "$version"
363394
write_containerd_config "$thinpool"
364395
start_containerd_service
@@ -367,13 +398,14 @@ do_all_containerd() {
367398
# Fetch and install the containerd binary
368399
install_containerd() {
369400
local tag="$1"
401+
370402
say "Installing containerd version $tag to $INSTALL_PATH"
371403

372404
if [[ "$version" == "$DEFAULT_VERSION" ]]; then
373405
tag=$(latest_release_tag "$CONTAINERD_REPO")
374406
fi
375407

376-
bin=$(build_containerd_release_bin_name "$tag")
408+
bin=$(build_containerd_release_bin_name "$tag" "$ARCH")
377409
url=$(build_download_url "$CONTAINERD_REPO" "$tag" "$bin")
378410
install_release_tar "$url" "$(dirname $INSTALL_PATH)" || die "could not install containerd"
379411

@@ -678,6 +710,7 @@ cmd_all() {
678710
local fc_version="$FIRECRACKER_VERSION"
679711
local fl_version="$FLINTLOCK_VERSION"
680712
local ctrd_version="$CONTAINERD_VERSION"
713+
local arch=amd64
681714

682715
while [ $# -gt 0 ]; do
683716
case "$1" in
@@ -717,6 +750,10 @@ cmd_all() {
717750
"--dev")
718751
DEVELOPMENT=true
719752
;;
753+
"--arch")
754+
shift
755+
arch="$1"
756+
;;
720757
*)
721758
die "Unknown argument: $1. Please use --help for help."
722759
;;
@@ -728,6 +765,9 @@ cmd_all() {
728765
say "The following subcommands will be performed:" \
729766
"apt, firecracker, containerd, flintlock, direct_lvm|devpool"
730767

768+
set_arch "$arch"
769+
say "Will install binarys for architecture: $ARCH"
770+
731771
ensure_kvm
732772

733773
if [[ "$skip_apt" == false ]]; then
@@ -767,6 +807,7 @@ cmd_apt() {
767807

768808
cmd_firecracker() {
769809
local version="$FIRECRACKER_VERSION"
810+
local arch="amd64"
770811

771812
while [ $# -gt 0 ]; do
772813
case "$1" in
@@ -778,19 +819,25 @@ cmd_firecracker() {
778819
shift
779820
version="$1"
780821
;;
822+
"--arch")
823+
shift
824+
arch="$1"
825+
;;
781826
*)
782827
die "Unknown argument: $1. Please use --help for help."
783828
;;
784829
esac
785830
shift
786831
done
787832

833+
set_arch "$arch"
788834
install_firecracker "$version"
789835
}
790836

791837
cmd_containerd() {
792838
local version="$CONTAINERD_VERSION"
793839
local thinpool="$DEFAULT_THINPOOL"
840+
local arch=amd64
794841

795842
while [ $# -gt 0 ]; do
796843
case "$1" in
@@ -810,13 +857,18 @@ cmd_containerd() {
810857
DEVELOPMENT=true
811858
thinpool="$DEFAULT_DEV_THINPOOL"
812859
;;
860+
"--arch")
861+
shift
862+
arch="$1"
863+
;;
813864
*)
814865
die "Unknown argument: $1. Please use --help for help."
815866
;;
816867
esac
817868
shift
818869
done
819870

871+
set_arch "$arch"
820872
prepare_dirs
821873
do_all_containerd "$version" "$thinpool"
822874
}
@@ -827,6 +879,7 @@ cmd_flintlock() {
827879
local parent_iface=""
828880
local bridge_name=""
829881
local insecure=false
882+
local arch=amd64
830883

831884
while [ $# -gt 0 ]; do
832885
case "$1" in
@@ -856,13 +909,18 @@ cmd_flintlock() {
856909
"--dev")
857910
DEVELOPMENT=true
858911
;;
912+
"--arch")
913+
shift
914+
arch="$1"
915+
;;
859916
*)
860917
die "Unknown argument: $1. Please use --help for help."
861918
;;
862919
esac
863920
shift
864921
done
865922

923+
set_arch "$arch"
866924
prepare_dirs
867925
do_all_flintlock "$version" "$address" "$parent_iface" "$bridge_name" "$insecure"
868926
}

0 commit comments

Comments
 (0)