forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
207 lines (174 loc) · 7.6 KB
/
Vagrantfile
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright (c) 2012-2016 Codenvy, S.A.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Codenvy, S.A. - initial API and implementation
# Set to "<proto>://<user>:<pass>@<host>:<port>"
$http_proxy = ENV['HTTP_PROXY'] || ""
$https_proxy = ENV['HTTPS_PROXY'] || ""
$no_proxy = ENV['NO_PROXY'] || "localhost,127.0.0.1"
$che_version = ENV['CHE_VERSION'] || "4.7.2"
$ip = ENV['CHE_HOST_IP'] || "192.168.28.100"
$hostPort = (ENV['CHE_PORT'] || 8080).to_i
$containerPort = (ENV['CHE_CONTAINER_PORT'] || ($hostPort == -1 ? 8080 : $hostPort)).to_i
$user_data = ENV['CHE_DATA'] || "."
$vm_name = ENV['CHE_VM_NAME'] || "eclipse-che-vm"
$provisionProgress = ENV['PROVISION_PROGRESS'] || "extended"
Vagrant.configure(2) do |config|
puts ("ECLIPSE CHE: VAGRANT INSTALLER")
puts ("ECLIPSE CHE: REQUIRED: VIRTUALBOX 5.x")
puts ("ECLIPSE CHE: REQUIRED: VAGRANT 1.8.x")
puts ("")
if ($http_proxy.to_s != '' || $https_proxy.to_s != '') && !Vagrant.has_plugin?("vagrant-proxyconf")
puts ("You configured a proxy, but Vagrant's proxy plugin not detected.")
puts ("Install the plugin with: vagrant plugin install vagrant-proxyconf")
Process.kill 9, Process.pid
end
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = $http_proxy
config.proxy.https = $https_proxy
config.proxy.no_proxy = $no_proxy
end
config.vm.box = "boxcutter/centos72"
config.vm.box_download_insecure = true
config.ssh.insert_key = false
if $ip.to_s.downcase == "dhcp"
config.vm.network :private_network, type: "dhcp"
else
config.vm.network :private_network, ip: $ip
end
if $hostPort != -1
config.vm.network "forwarded_port", guest: $containerPort, host: $hostPort
end
config.vm.synced_folder $user_data, "/home/user/che"
config.vm.define "che" do |che|
end
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.name = $vm_name
end
$script = <<-'SHELL'
HTTP_PROXY=$1
HTTPS_PROXY=$2
NO_PROXY=$3
CHE_VERSION=$4
IP=$5
PORT=$6
PROVISION_PROGRESS=$7
if [ "${IP,,}" = "dhcp" ]; then
echo "----------------------------------------"
echo "ECLIPSE CHE: CHECKING DYNAMIC IP ADDRESS"
echo "----------------------------------------"
DEV=$(grep -l "VAGRANT-BEGIN" /etc/sysconfig/network-scripts/ifcfg-*|xargs grep "DEVICE="|sort|tail -1|cut -d "=" -f 2)
if [ -z "${DEV}" ]; then
>&2 echo "Unable to find DHCP network device"
exit 1
fi
IP=$(ip addr show dev ${DEV} | sed -r -e '/inet [0-9]/!d;s/^[[:space:]]*inet ([^[:space:]/]+).*$/\1/')
if [ -z "${IP}" ]; then
>&2 echo "Unable to find DHCP network ip"
exit 1
fi
echo "IP: ${IP}"
echo
fi
if [ -n "$HTTP_PROXY" ] || [ -n "$HTTPS_PROXY" ]; then
echo "-------------------------------------"
echo "."
echo "ECLIPSE CHE: CONFIGURING SYSTEM PROXY"
echo "."
echo "-------------------------------------"
echo "export http_proxy=$HTTP_PROXY" >> /etc/profile.d/vars.sh
echo "export https_proxy=$HTTPS_PROXY" >> /etc/profile.d/vars.sh
echo "export no_proxy=$NO_PROXY" >> /etc/profile.d/vars.sh
source /etc/profile.d/vars.sh
# Configuring the Che properties file - mounted into Che container when it starts
echo "export CHE_PROPERTY_http_proxy=${HTTP_PROXY}" >> /etc/profile.d/vars.sh
echo "export CHE_PROPERTY_https_proxy=${HTTP_PROXY}" >> /etc/profile.d/vars.sh
echo "HTTP PROXY set to: $HTTP_PROXY"
echo "HTTPS PROXY set to: $HTTPS_PROXY"
fi
echo "------------------------------"
echo "ECLIPSE CHE: INSTALLING DOCKER"
echo "------------------------------"
sudo yum -y install expect
# INstall docker
sudo yum -y update
# perform $PROVISION_PROGRESS sudo yum install docker-engine
curl -fsSL https://get.docker.com/ | sh
sudo service docker start
echo $(docker --version)
# Add the 'vagrant' user to the 'docker' group
usermod -aG docker vagrant &>/dev/null
# We need write access to this file to enable Che container to create other containers
sudo chmod 777 /var/run/docker.sock &>/dev/null
# Setup the overlay storage driver to eliminate errors
#sudo sed -i '/ExecStart=\/usr\/bin\/dockerd/c\ExecStart=\/usr\/bin\/dockerd --storage-driver=overlay' /lib/systemd/system/docker.service
# Configure Docker daemon with the proxy
if [ -n "$HTTP_PROXY" ] || [ -n "$HTTPS_PROXY" ]; then
mkdir /etc/systemd/system/docker.service.d
fi
if [ -n "$HTTP_PROXY" ]; then
printf "[Service]\nEnvironment=\"HTTP_PROXY=${1}\"" > /etc/systemd/system/docker.service.d/http-proxy.conf
printf ""
fi
if [ -n "$HTTPS_PROXY" ]; then
printf "[Service]\nEnvironment=\"HTTPS_PROXY=${2}\"" > /etc/systemd/system/docker.service.d/https-proxy.conf
fi
if [ -n "$HTTP_PROXY" ] || [ -n "$HTTPS_PROXY" ]; then
printf "[Service]\nEnvironment=\"NO_PROXY=${3}\"" > /etc/systemd/system/docker.service.d/no-proxy.conf
fi
systemctl daemon-reload
systemctl restart docker
echo "--------------------------------------------------"
echo "ECLIPSE CHE: DOWNLOADING ECLIPSE CHE DOCKER IMAGES"
echo "--------------------------------------------------"
docker pull alpine:latest
docker pull codenvy/che-launcher:${4}
docker pull codenvy/che-server:${4}
curl -sL https://raw.githubusercontent.com/eclipse/che/master/che.sh | tr -d '\15\32' > /home/vagrant/che.sh
chmod +x /home/vagrant/che.sh
echo "export CHE_PORT=${6}" >> /etc/profile.d/vars.sh
echo "export CHE_VERSION=${4}" >> /etc/profile.d/vars.sh
echo "export CHE_HOST_IP=${5}" >> /etc/profile.d/vars.sh
echo "export CHE_HOSTNAME=${5}" >> /etc/profile.d/vars.sh
echo "export IS_INTERACTIVE=false" >> /etc/profile.d/vars.sh
echo "export IS_PSEUDO_TTY=false" >> /etc/profile.d/vars.sh
SHELL
config.vm.provision "shell" do |s|
s.inline = $script
s.args = [$http_proxy, $https_proxy, $no_proxy, $che_version, $ip, $containerPort, $provisionProgress]
end
$script2 = <<-'SHELL'
IP=$1
PORT=$2
MAPPED_PORT=$3
echo "--------------------------------"
echo "ECLIPSE CHE: BOOTING ECLIPSE CHE"
echo "--------------------------------"
docker run --rm -t -v /var/run/docker.sock:/var/run/docker.sock \
-e "CHE_PORT=${2}" \
-e "CHE_RESTART_POLICY=always" \
-e "CHE_HOST_IP=${1}" \
-e "CHE_HOSTNAME=${1}" \
codenvy/che-launcher:${CHE_VERSION} start
if [ "${IP,,}" = "dhcp" ]; then
DEV=$(grep -l "VAGRANT-BEGIN" /etc/sysconfig/network-scripts/ifcfg-*|xargs grep "DEVICE="|sort|tail -1|cut -d "=" -f 2)
IP=$(ip addr show dev ${DEV} | sed -r -e '/inet [0-9]/!d;s/^[[:space:]]*inet ([^[:space:]/]+).*$/\1/')
fi
rm -f /home/user/che/.che_url
rm -f /home/user/che/.che_host_port
CHE_URL="http://${IP}:${PORT}"
echo "${CHE_URL}" > /home/user/che/.che_url
echo "${MAPPED_PORT}" > /home/user/che/.che_host_port
echo ""
echo "ECLIPSE CHE READY AT: ${CHE_URL}"
SHELL
config.vm.provision "shell", run: "always" do |s|
s.inline = $script2
s.args = [$ip, $containerPort, $hostPort]
end
end