-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·92 lines (69 loc) · 2.46 KB
/
deploy.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
#!/bin/bash
# SPDX-FileCopyrightText: 2022 Wilfred Nicoll <xyzroller@rollyourown.xyz>
# SPDX-License-Identifier: GPL-3.0-or-later
# deploy.sh
# This script deploys a module
# Help and error messages
#########################
helpMessage()
{
echo "deploy.sh: Deploy a rollyourown module"
echo "Usage: ./deploy.sh -n hostname -v version"
echo "Flags:"
echo -e "-n hostname \t\t(Mandatory) Name of the host on which to deploy the module"
echo -e "-v version \t\t(Mandatory) Version stamp for images to deploy, e.g. 20210101-1"
echo -e "-b remote_build \t\t(Mandatory) Whether to build images for the module remotely (true/false)"
echo -r "-r \t\t\tRestore after system failure (should only be used during a restore after system failure)"
echo -e "-h \t\t\tPrint this help message"
echo ""
exit 1
}
errorMessage()
{
echo "Invalid option or input variables are missing"
echo "Use \"./deploy.sh -h\" for help"
exit 1
}
# Command-line input handling
#############################
restore="false"
while getopts n:v:b:rh flag
do
case "${flag}" in
n) hostname=${OPTARG};;
v) version=${OPTARG};;
b) remote_build=${OPTARG};;
r) restore="true";;
h) helpMessage ;;
?) errorMessage ;;
esac
done
if [ -z "$hostname" ] || [ -z "$version" ] || [ -z "$remote_build" ]; then
errorMessage
fi
# Script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Get Module ID from configuration file
MODULE_ID="$(yq eval '.module_id' "$SCRIPT_DIR"/configuration/configuration.yml)"
# Info
echo "rollyourown deployment script for "$MODULE_ID""
# Update module repository
###########################
if [ $restore == false ]; then
echo "Refreshing module repository with git pull to ensure the current version"
cd "$SCRIPT_DIR" && git pull
fi
# Deploy Module
################
# Run host setup playbooks for module
echo ""
echo "Running module-specific host setup for "$MODULE_ID" on "$hostname""
/bin/bash "$SCRIPT_DIR"/scripts-module/host-setup.sh -n "$hostname"
# Run packer image build for module
echo ""
echo "Running build-images script for "$MODULE_ID" module on "$hostname" with version "$version" -r "$remote_build""
/bin/bash "$SCRIPT_DIR"/scripts-module/build-images.sh -n "$hostname" -v "$version" -r "$remote_build"
# Deploy module
echo ""
echo "Deploying image(s) "$MODULE_ID" module on "$hostname" using images with version "$version""
/bin/bash "$SCRIPT_DIR"/scripts-module/deploy-module.sh -n "$hostname" -v "$version"