-
Notifications
You must be signed in to change notification settings - Fork 7
/
packer.sh
53 lines (43 loc) · 1.41 KB
/
packer.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
#!/bin/bash
# Exit immediately if a command returns a non-zero status
set -e
# Printing script usage
program_name=$0
usage () {
echo "usage: $program_name [--env-file google-env-file.json] [--packer-action build]"
exit 1
}
# Parsing script params
while true; do
case "$1" in
--env-file ) env_file="$2"; shift 2 ;;
--packer-action ) packer_action="$2"; shift 2;;
* ) break ;;
esac
done
# Checking script params
if [ -z "$env_file" ]; then
usage
fi
if [ -z "$packer_action" ]; then
usage
fi
env_file_path=$(realpath "$env_file")
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
project_root_path=$(realpath "$script_dir/..")
packer_project_path=$project_root_path/image
default_tfvars_json_path="$project_root_path/terraform.tfvars.json"
# shellcheck source=.tools/extract-and-export.sh
source "$project_root_path"/.tools/extract-and-export.sh "$default_tfvars_json_path"
# shellcheck source=.tools/extract-and-export.sh
source "$project_root_path"/.tools/extract-and-export.sh "$env_file_path"
# shellcheck source=.tools/load-google-auth.sh
source "$project_root_path"/.tools/load-google-auth.sh "$env_file_path"
packer_cmd="packer $packer_action \
-var region=$GOOGLE_REGION \
-var zone=$GOOGLE_ZONE \
-var machine_type=$RUNNER_MACHINE_TYPE \
-var project_id=$GOOGLE_PROJECT \
-var path=$packer_project_path \
$packer_project_path/runner.json"
eval "$packer_cmd"