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
|
# File 'lib/fig2coreos.rb', line 84
def create_vagrant_file
File.open(File.join(@output_dir, "setup-coreos.sh"), "w") do |file|
file << <<-eof
# Switch to root for setting up systemd
sudo -i
# Clear old containers
systemctl stop local-enable.service
systemctl stop etcd-cluster.service
/usr/bin/docker ps -a -q | xargs docker kill
/usr/bin/docker ps -a -q | xargs docker rm
# Copy the services into place
eof
@fig.each do |service_name, service|
file << "cp " + File.join("share", "media", "state", "units", "#{service_name}.1.service") + " /media/state/units/#{service_name}.1.service\n"
file << "cp " + File.join("share", "media", "state", "units", "#{service_name}-discovery.1.service") + " /media/state/units/#{service_name}-discovery.1.service\n\n"
end
file << <<-eof
# Fix etcd-cluster setup
HOSTNAME=$(</proc/sys/kernel/hostname)
if [ ! -d /var/run/etcd/${HOSTNAME} ]
then
mkdir /var/run/etcd/${HOSTNAME}
chown core:core /var/run/etcd/${HOSTNAME}
fi
echo 192.168.10.2 > /var/run/etcd/MY_IP
# Replace the existing line:
sed -i -e "s@ExecStart=.*@ExecStart=/usr/bin/etcd -s 192.168.10.2:7001 -sl 0.0.0.0 -cl 0.0.0.0 -c 192.168.10.2:4001 ${CLUSTER_OPT} -d /var/run/etcd/${HOSTNAME} -n $HOSTNAME@" /media/state/units/etcd-cluster.service
# Start containers and fleet
systemctl daemon-reload
systemctl start etcd-cluster.service
systemctl start local-enable.service
systemctl start fleet
etcdctl mkdir /services
eof
@fig.each do |service_name, service|
file << "etcdctl mkdir /services/#{service_name}\n"
end
file << "cd /media/state/units; for service in *.service; do fleetctl start $service; done\n"
file << "sleep 3; /usr/bin/docker ps -a -q | xargs docker rm\n"
file << "sleep 3; /usr/bin/docker ps -a -q | xargs docker rm\n"
file << "echo 'SUCCESS'\n"
file << "exit 0\n"
file.chmod(0755)
end
File.open(File.join(@output_dir, "Vagrantfile"), "w") do |file|
file << <<-eof
# -*- mode: ruby -*-
# vi: set ft=ruby :
$expose_port = 8080
Vagrant.configure("2") do |config|
config.vm.box = "coreos"
config.vm.box_url = "http://storage.core-os.net/coreos/amd64-generic/dev-channel/coreos_production_vagrant.box"
config.vm.hostname = "coreos-#{@app_name}"
config.vm.provider :virtualbox do |vb, override|
vb.name = "vagrant-coreos-docker-converted-from-fig-#{@app_name}"
# Fix docker not being able to resolve private registry in VirtualBox
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
# Share this folder so provisioner can access Dockerfile an apache.service
# This is from coreos/coreos-vagrant, but won't work on Windows hosts
config.vm.network "private_network", ip: "192.168.10.2"
config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
# Forward port 80 from coreos (which is forwarding port 80 of the container)
config.vm.network :forwarded_port, guest: 80, host: $expose_port, host_ip: "127.0.0.1"
config.vm.provider :vmware_fusion do |vb, override|
override.vm.box_url = "http://storage.core-os.net/coreos/amd64-generic/dev-channel/coreos_production_vagrant_vmware_fusion.box"
end
# plugin conflict
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
# Provision
config.vm.provision "shell", :path => "setup-coreos.sh"
end
eof
end
if File.directory?(File.join(@output_dir, ".vagrant"))
puts "[SUCCESS] Try this: cd #{@output_dir} && vagrant reload --provision"
else
puts "[SUCCESS] Try this: cd #{@output_dir} && vagrant up"
end
end
|