-
Notifications
You must be signed in to change notification settings - Fork 11
/
build-node-image.sh
executable file
·71 lines (60 loc) · 2.88 KB
/
build-node-image.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
#!/bin/bash
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: MPL-2.0
set -e
source $(dirname "${BASH_SOURCE[0]}")/utils.sh
ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
enable_debugging
is_argument_set "KUBERNETES_VERSION argument is required" $KUBERNETES_VERSION
is_argument_set "OS_TARGET argument is required" $OS_TARGET
is_argument_set "TKR_SUFFIX argument is required" $TKR_SUFFIX
is_argument_set "HOST_IP argument is required" $HOST_IP
is_argument_set "IMAGE_ARTIFACTS_PATH argument is required" $IMAGE_ARTIFACTS_PATH
if [ -z "$ARTIFACTS_CONTAINER_PORT" ]; then
# Makefile creates this environment variables
ARTIFACTS_CONTAINER_PORT=$DEFAULT_ARTIFACTS_CONTAINER_PORT
echo "Using default port for artifacts container $DEFAULT_ARTIFACTS_CONTAINER_PORT"
fi
if [ -z "$PACKER_HTTP_PORT" ]; then
# Makefile creates this environment variables
PACKER_HTTP_PORT=$DEFAULT_PACKER_HTTP_PORT
echo "Using default Packer HTTP port $PACKER_HTTP_PORT"
fi
function build_node_image() {
docker rm -f $(get_node_image_builder_container_name "$KUBERNETES_VERSION" "$OS_TARGET")
docker run -d \
--name $(get_node_image_builder_container_name "$KUBERNETES_VERSION" "$OS_TARGET") \
$(get_node_image_builder_container_labels "$KUBERNETES_VERSION" "$OS_TARGET") \
-v $ROOT/ansible:/image-builder/images/capi/image/ansible \
-v $ROOT/goss:/image-builder/images/capi/image/goss \
-v $ROOT/hack:/image-builder/images/capi/image/hack \
-v $ROOT/packer-variables:/image-builder/images/capi/image/packer-variables \
-v $ROOT/scripts:/image-builder/images/capi/image/scripts \
-v $IMAGE_ARTIFACTS_PATH:/image-builder/images/capi/artifacts \
-w /image-builder/images/capi/ \
-e HOST_IP=$HOST_IP -e ARTIFACTS_CONTAINER_PORT=$ARTIFACTS_CONTAINER_PORT -e OS_TARGET=$OS_TARGET \
-e TKR_SUFFIX=$TKR_SUFFIX -e KUBERNETES_VERSION=$KUBERNETES_VERSION \
-e PACKER_HTTP_PORT=$PACKER_HTTP_PORT \
-p $PACKER_HTTP_PORT:$PACKER_HTTP_PORT \
--platform linux/amd64 \
$(get_image_builder_container_image_name $KUBERNETES_VERSION)
}
supported_os_list=$(jq -r '."'$KUBERNETES_VERSION'".supported_os' $SUPPORTED_VERSIONS_JSON)
if [ "$supported_os_list" == "null" ]; then
print_error 'Use supported KUBERNETES_VERSION, run "make list-versions" to list the supported kubernetes versions'
exit 1
fi
supported_os=false
while read SUPPORTED_OS_TARGET; do
if [ $SUPPORTED_OS_TARGET == $OS_TARGET ]; then
build_node_image
echo ""
next_hint_msg "Use \"docker logs -f $(get_node_image_builder_container_name $KUBERNETES_VERSION $OS_TARGET)\" to see logs and status"
next_hint_msg "Node Image OVA can be found at $IMAGE_ARTIFACTS_PATH/ovas/"
supported_os=true
fi
done < <(jq -r '."'$KUBERNETES_VERSION'".supported_os[]' "$SUPPORTED_VERSIONS_JSON")
if [ "$supported_os" == false ]; then
print_error 'Use supported OS_TARGET, run "make list-versions" to list the supported kubernetes versions'
exit 1
fi