-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·131 lines (103 loc) · 4.56 KB
/
build.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
# Fail on any error
set -e
# Set version info
export BOX_VERSION_BASE=1.0.3
export CENTOS_BASE_ISO="CentOS-7-x86_64-Minimal-2009.iso"
export CENTOS_BASE_ISO_SHA256="07b94e6b1a0b0260b94c83d6bb76b26bf7a310dc78d7a9c7432809fb9bc6194a"
# Set versions requested of main components (These will be used in Packer and passed to Ansible downstream)
export ANSIBLE_VERSION=2.10.7
# The following Ansible dependencies stopped working with CentOS 7 in their latest version, so we lock them to a specific version
export CRYPTOGRAPHY_VERSION=3.3.2
export JINJA2_VERSION=2.11.3
export MARKUPSAFE_VERSION=1.1.1
export BCRYPT_VERSION=3.1.7
export PACKAGING_VERSION=20.9
# Set versions of supported tools, if they don't match, a warning will be shown on screen
export VIRTUALBOX_VERSION="6.1.26r145957"
export PACKER_VERSION="1.7.4"
export VAGRANT_VERSION="2.2.16"
# Set the Vagrant cloud user and box name (make sure you have admin permissions to, or are the owner of this repository)
export VAGRANT_CLOUD_BOX_USER="ilionx"
export VAGRANT_CLOUD_BOX_NAME="centos7"
# ############################################################################################## #
# Below this point there should be no need to edit anything, unless you know what you are doing! #
# ############################################################################################## #
# Generate the final version of the box, adding the date string of today
export BOX_VERSION=${BOX_VERSION_BASE}-$(date +'%Y%m%d')
echo "Testing if all required tools are installed, please wait..."
# Check if all required tools are installed
if ( ! ( vboxmanage --version >/dev/null 2>&1 && packer version >/dev/null 2>&1 && vagrant version >/dev/null 2>&1 ) )
then
echo "ERROR: One of the required tools (VirtualBox, Vagrant, and Packer) is not installed. Cannot continue."
exit 1
fi
# Check the tool versions
INSTALLED_VIRTUALBOX_VERSION=$(vboxmanage --version)
INSTALLED_PACKER_VERSION=$(packer --version)
INSTALLED_VAGRANT_VERSION=$(vagrant --version | awk '{print $2}')
if [[ $INSTALLED_VIRTUALBOX_VERSION != $VIRTUALBOX_VERSION || $INSTALLED_PACKER_VERSION != $PACKER_VERSION || $INSTALLED_VAGRANT_VERSION != $VAGRANT_VERSION ]]
then
echo "WARNING: One of the tool versions does not match the tested versions. Your mileage may vary..."
echo " * Using VirtualBox version ${INSTALLED_VIRTUALBOX_VERSION} (tested with version ${VIRTUALBOX_VERSION})"
echo " * Using Packer version ${INSTALLED_PACKER_VERSION} (tested with version ${PACKER_VERSION})"
echo " * Using Vagrant version ${INSTALLED_VAGRANT_VERSION} (tested with version ${VAGRANT_VERSION})"
echo ""
echo -n "To break, press Ctrl-C now, otherwise press Enter to continue"
read foo
fi
echo "All required tools found. Continuing."
# Check if a build.env file is present, and if so: source it
if [ -f build.env ]
then
source build.env
fi
# Check if the variables VAGRANT_CLOUD_USER and VAGRANT_CLOUD_TOKEN have been set, if not ask for them
if [ -z "$DEFAULT_VAGRANT_CLOUD_USER" -o -z "$DEFAULT_VAGRANT_CLOUD_TOKEN" ]
then
# Ask user for vagrant cloud token
echo -n "What is your Vagrant Cloud username? [ilionx] "
read user
user=${user:-ilionx}
export VAGRANT_CLOUD_USER=${user}
# Ask user for vagrant cloud token
echo -n "What is your Vagrant Cloud token? "
read -s token
echo ""
export VAGRANT_CLOUD_TOKEN=${token}
else
export VAGRANT_CLOUD_USER=$DEFAULT_VAGRANT_CLOUD_USER
export VAGRANT_CLOUD_TOKEN=$DEFAULT_VAGRANT_CLOUD_TOKEN
echo "Your vagrant cloud user and token have been sourced from file build.env"
fi
# Export dynamic versioning info
commit=$(git --no-pager log -n 1 --format="%H")
export BOX_VERSION_DESCRIPTION="
## Description
This base box is based on a clean CentOS 7 minimal install.
The box defaults to 1 CPU and 1GB of RAM, it is not advised to limit this.
---
## Versions included in this release
* Latest OS updates installed at build time
* ansible ${ANSIBLE_VERSION}
* cryptography ${CRYPTOGRAPHY_VERSION}
* MarkupSafe ${MARKUPSAFE_VERSION}
* Jinja2 ${JINJA2_VERSION}
* bcrypt ${BCRYPT_VERSION}
* packaging ${PACKAGING_VERSION}
---
$(cat CHANGELOG.md)
---
## Source info
[View source on Github](https://github.com/Q24/vagrant-box-centos7)
Built on commit: \`${commit}\`
"
echo "${BOX_VERSION_DESCRIPTION}"
# Validate build config
echo "Validating build json files"
packer validate packer.json
# Run the actual build
echo "Building box version ${BOX_VERSION}"
packer build -force -on-error=cleanup packer.json
# Tag git commit for this build
git tag -a "${BOX_VERSION}" -m "Version ${BOX_VERSION} built."