forked from IonosatMicro/promis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
136 lines (123 loc) · 4.36 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
#
# Copyright 2016 Space Research Institute of NASU and SSAU (Ukraine)
#
# Licensed under the EUPL, Version 1.1 or – as soon they
# will be approved by the European Commission - subsequent
# versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# https://joinup.ec.europa.eu/software/page/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
# Vagrant 1.8 required for docker and no parallel setting
Vagrant.require_version ">= 1.8.0"
# Prevent parallel setup, we need this for links
ENV["VAGRANT_NO_PARALLEL"] = "yes"
# Enforce default docker provider, for some reason defaults
# to VirtualBox on some Gentoo setups despite configuration
ENV["VAGRANT_DEFAULT_PROVIDER"] = "docker"
vagrant_root = File.dirname(__FILE__)
load File.join(vagrant_root, "config.rb")
# Composing the API url
need_ext = ($conf["disable_ssl"] && $conf["port_web"] == 80) ||
(!$conf["disable_ssl"] && $conf["port_web"] == 443)
$conf["promis_origin"] = $conf["servername_web"] + (need_ext ? "" : ":" + $conf["port_web"].to_s)
# Container definitions
containers = YAML.load_file(File.join(vagrant_root, "conf", "containers.yml"))
# Check if input contains a configuration variable reference, if so, substitute
# TODO: better approach
def cfg(input)
res = input.dup
rexp_conf = /\${conf.([a-zA-Z_][a-zA-Z0-9_]*)}/
while res.match(rexp_conf)
res[rexp_conf] = $conf[res[rexp_conf, 1]].to_s
end
return res
end
# Process auto-generated files
# NOTE: this ALWAYS runs even on vagrant-status etc
generated = YAML.load_file(File.join(vagrant_root, "conf", "/generated.yml"))
generated.each do | ifname, odirs |
s = cfg(IO.read(File.join(vagrant_root, ifname)))
bname = File.basename ifname
odirs.each do | odir |
fp = File.open(File.join(vagrant_root, odir, bname), "w")
fp.puts s
fp.close
end
end
Vagrant.configure("2") do |config|
config.vm.provider "docker"
containers.each do |container|
config.vm.define cfg(container["name"]), autostart: ! container["noauto"] do |node|
# Removing the default folder sync
node.vm.synced_folder ".", "/vagrant", disabled: true
# Adding custom ones
if container["sync"]
container["sync"].each do |sync|
node.vm.synced_folder cfg(sync[0]), cfg(sync[1])
end
end
# Code reload directories
if $conf["code_reload"] and container["reload"]
container["reload"].each do |sync|
node.vm.synced_folder cfg(sync[0]), cfg(sync[1])
end
end
# Setting docker stuff
node.vm.provider "docker" do |docker|
# Not sure we need to set it for every container, but no harm
if $conf["force_host_vm"]
docker.force_host_vm = true
end
# This can be set outside of the block above by vagrant itself
if docker.force_host_vm
docker.vagrant_vagrantfile = "Vagrantfile.hostvm"
end
# Pick up whether we need to build or reuse an image
if container["image"]
docker.image = cfg(container["image"])
elsif
docker.build_dir = cfg(container["build"])
end
# Forward ports if necessary
if container["ports"] && (cfg(container["name"])!=$conf["hostname_db"] || $conf["expose_db"])
ports = container["ports"].dup
ports.each_index do |k|
port = cfg(ports[k])
if ! port.include? ":"
ports[k] = port + ":" + port
else
ports[k] = port
end
end
docker.ports = ports
end
# Link other containers
if container["depend"]
container["depend"].each do |link|
linkhost = cfg(link)
docker.link(linkhost + ":" + linkhost)
end
end
# Set up environment vars
if container["env"]
container["env"].each do |env|
docker.env[env[0]] = cfg(env[1])
end
end
docker.name = cfg(container["name"])
docker.create_args = ["--restart=always"]
end
end
end
end