-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·143 lines (115 loc) · 5.24 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
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# Fail on any error
set -e
# Set version info
export BOX_VERSION_BASE="1.5.0"
# Set versions requested of main components (These will be used in Packer and passed to Ansible downstream)
# The apt package versions can be determined with "apt-get madison <package name>", use the exact version number!
export BOX_BASE="ilionx/ubuntu2204"
export BOX_BASE_VERSION="1.5.0-20240320"
export MINIKUBE_VERSION="1.32.0"
export CRIDOCKERD_VERSION="0.3.11"
export CRITOOLS_VERSION="1.28.0-1.1"
export DOCKER_VERSION="5:25.0.5-1~ubuntu.22.04~jammy"
export KUBE_REPO_VERSION="1.28"
export KUBECTL_VERSION="1.28.3-1.1"
export CNI_PLUGINS_VERSION="1.4.1"
export HELM_VERSION="3.14.3"
export KUBETAIL_VERSION="1.6.20"
export KUBELOGS_VERSION="0.0.1"
# Set versions of supported tools, if they don't match, a warning will be shown on screen
export VIRTUALBOX_VERSION="7.0.14r161095"
export PACKER_VERSION="1.10.2-dev"
export VAGRANT_VERSION="2.4.1"
# 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="ubuntu2204-minikube"
# ############################################################################################## #
# Below this point there should be no need to edit anything, unless you know what you are doing! #
# ############################################################################################## #
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 -r
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" ] || [ -z "$DEFAULT_VAGRANT_CLOUD_TOKEN" ]
then
# Ask user for vagrant cloud token
echo -n "What is your Vagrant Cloud username? [ilionx] "
read -r user
user=${user:-ilionx}
export VAGRANT_CLOUD_USER=${user}
# Ask user for vagrant cloud token
echo -n "What is your Vagrant Cloud token? "
read -rs 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
BOX_VERSION=${BOX_VERSION_BASE}-$(date +'%Y%m%d')
export BOX_VERSION
commit=$(git --no-pager log -n 1 --format="%H")
BOX_VERSION_DESCRIPTION="
## Description
This box is based on the ${BOX_BASE} box version ${BOX_BASE_VERSION}. I try to keep the builds up to date with the latest version of this box.
When the box boots it contains a running minikube, ready to deploy kubenetes manifests, and kubectl is pre configured for the vagrant user.
Helm is installed to allow the immediate deployment of charts.
The box defaults to 2 CPU and 4GB of RAM, it is not advised to limit this.
---
## Versions included in this release
Based on box [${BOX_BASE}](https://app.vagrantup.com/ilionx/boxes/ubuntu2204) version ${BOX_BASE_VERSION}
* Latest OS updates installed at build time
* minikube ${MINIKUBE_VERSION}
* docker ${DOCKER_VERSION}
* kubectl ${KUBECTL_VERSION}
* helm ${HELM_VERSION}
* kubetail ${KUBETAIL_VERSION}
---
$(cat CHANGELOG.md)
---
## Source info
[View source on Github](https://github.com/Q24/vagrant-box-ubuntu2204-minikube)
Built on commit: \`${commit}\`
"
export BOX_VERSION_DESCRIPTION
echo "${BOX_VERSION_DESCRIPTION}"
# Install necessary packer plugins
echo "Installing packer plugins: virtualbox, ansible, and vagrant"
packer plugins install github.com/hashicorp/virtualbox
packer plugins install github.com/hashicorp/ansible
packer plugins install github.com/hashicorp/vagrant
# 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."