-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-image.sh
executable file
·95 lines (76 loc) · 2.2 KB
/
build-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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
usage() {
echo "build-image.sh [options]"
echo
echo "Options and equivalent environment variables:"
echo " -rp or --root-password <password> VISA_ROOT_PASSWORD set the root password for the VM"
echo " -hp or --http-proxy <URL> VISA_HTTP_PROXY set the HTTP proxy URL"
echo " -np or --no-proxy <no proxy hosts> VISA_NO_PROXY_HOSTS set the HTTP no proxy hosts"
echo " -nh or --notheadless set build process not to be headless"
}
export headless=true
PACKER_HTTP_PROXY="\"\""
PACKER_NO_PROXY_HOSTS="localhost"
# Parse command line arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-rp|--root-psasword)
VISA_ROOT_PASSWORD="$2"
shift
shift
;;
-hp|--http-proxy)
VISA_HTTP_PROXY="$2"
shift
shift
;;
-np|--no-proxy)
VISA_NO_PROXY_HOSTS="$2"
shift
shift
;;
-nh|--not-headless)
headless=false
shift
;;
*)
break
;;
esac
done
# Verify root password is set
if [ -z "$VISA_ROOT_PASSWORD" ]; then
echo "You need to specify a root password for the VM"
usage
exit
fi
# Set PACKER_HTTP_PROXY variables if proxy vars have been specified
if [ ! -z "$VISA_HTTP_PROXY" ]; then
PACKER_HTTP_PROXY="$VISA_HTTP_PROXY"
fi
if [ ! -z "$VISA_NO_PROXY_HOSTS" ]; then
PACKER_NO_PROXY_HOSTS="$VISA_NO_PROXY_HOSTS"
fi
# Set the packer environment variables
export root_password=$VISA_ROOT_PASSWORD
# Modify the files accordingly for the proxy
sed -e "s|{http_proxy}|$PACKER_HTTP_PROXY|g" -e "s|{no_proxy}|$PACKER_NO_PROXY_HOSTS|g" templates/system-base/environment.yml.tlt > templates/system-base/environment.yml
if [ ! -z "$VISA_HTTP_PROXY" ]; then
sed -e "s|{http_proxy}|$VISA_HTTP_PROXY|g" -e "s|{https_proxy}|$VISA_HTTP_PROXY|g" -e "s|{no_proxy}|$VISA_NO_PROXY_HOSTS|g" templates/system-base/system/etc/environment.tlt > templates/system-base/system/etc/environment
else
echo "" > templates/system-base/system/etc/environment
fi
VENV_DIR=.venv_packme
rm -rf $VENV_DIR
python3 -m venv $VENV_DIR
source $VENV_DIR/bin/activate
echo "Installing packme"
pip3 install wheel
pip3 install packme
export PACKER_LOG=1
# Run packme
packme --templates-base-dir templates --debug -l --input config.yml -c -r
deactivate
rm -rf $VENV_DIR