forked from ids/cluster-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·78 lines (71 loc) · 2.5 KB
/
build
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
#!/bin/bash
OP_KEY=~/.ssh/id_rsa.pub
IMAGE=centos7
if [ "$1" != "" ]; then
IMAGE=$1
fi
if [ ! -f keys/authorized_keys ]; then
if [ ! -f $OP_KEY ]; then
echo
echo "Error: 'authorized_keys' must be set before the image is built, run 'bash keys/set-key' to use your current public key"
echo "Unable to find ${OP_KEY}, can't auto-set the authorized_keys!"
echo "Make sure keys/authorized_keys exists and has the cluster-builder operator key."
exit 1
fi
bash keys/set-key
fi
START_TIME=$SECONDS
PACKER_CMD="packer build cluster-node-${IMAGE}.json"
if [ "`uname -r | grep Microsoft | wc -l | xargs`" == "1" ]; then
echo "Building in Windows Mode using cmd.exe..."
WIN_BUILD_DIR=`wslpath -w $PWD`
echo "Using path: ${WIN_BUILD_DIR}"
PACKER_CMD="cmd.exe /c \"cd ${WIN_BUILD_DIR} && packer.exe build cluster-node-${IMAGE}.json && exit\""
rm -rf 'output_'$IMAGE'_vmx'
fi
if [ "$IMAGE" == "rhel7" ]; then
if [ "$3" == "" ]; then
echo
echo "Error: No license key found. Make sure rhel.lic is located in the clusters folder."
exit 1
fi
RHEL_LIC=$3
RHEL_FOLDER=$2
PACKER_CMD="packer build -var rhel_folder=${RHEL_FOLDER} -var rhel_lic=${RHEL_LIC} cluster-node-${IMAGE}.json"
rm -rf 'output_'$IMAGE'_vmx'
fi
if [ "$IMAGE" == "centos7-dcos" ] || \
[ "$IMAGE" == "win2016" ] || \
[ "$IMAGE" == "win2019" ] || \
[ "$IMAGE" == "centos7" ] || \
[ "$IMAGE" == "centos8" ] || \
[ "$IMAGE" == "fedora" ] || \
[ "$IMAGE" == "ubuntu" ] || \
[ "$IMAGE" == "rhel7" ]; then
echo
echo 'Building VM image:' $IMAGE
rm -rf 'output_'$IMAGE'_vmx'
eval $PACKER_CMD
rm -rf 'output_'$IMAGE'_vmx'
elif [ "$IMAGE" == "targetd-server" ]; then
echo
echo 'Building Targetd iSCSI Storage Appliance'
PACKER_CMD="packer build targetd-server-appliance.json"
if [ "`uname -r | grep Microsoft | wc -l | xargs`" == "1" ]; then
echo "Building in Windows Mode using cmd.exe..."
WIN_BUILD_DIR=`wslpath -w $PWD`
echo "Using path: ${WIN_BUILD_DIR}"
PACKER_CMD="cmd.exe /c \"cd ${WIN_BUILD_DIR} && packer.exe build targetd-server-appliance.json && exit\""
fi
rm -rf 'output_'$IMAGE'_vmx'
eval $PACKER_CMD
rm -rf 'output_'$IMAGE'_vmx'
else
echo
echo 'Error: Not a valid VM image type!'
echo 'usage: build [centos7 (default), centos8, centos7-dcos, rhel7, win2016, win2019, coreos-provisioner, coreos-pxe, fedora, targetd-server]'
exit
fi
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "Template image built in: $(($ELAPSED_TIME/60)) min $(($ELAPSED_TIME%60)) sec"
echo