-
Notifications
You must be signed in to change notification settings - Fork 9
/
vagrant-ci
198 lines (172 loc) · 7.99 KB
/
vagrant-ci
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
# Helpers
def colorize(text, color_code); "#{color_code}#{text}\033[0m"; end
def red(text); colorize(text, "\033[31m"); end
def yellow(text); colorize(text, "\033[33m"); end
def green(text); colorize(text, "\033[32m"); end
def bold(text); colorize(text, "\033[1;97m"); end
###
### BEGINNING OF CONFIGURATION FOR CI
###
# Local directories and files to use
BASE_DIRECTORY = File.expand_path(File.dirname(__FILE__))
SALT_DIRECTORY = BASE_DIRECTORY + "/saltstack"
PILLAR_DIRECTORY = BASE_DIRECTORY + "/pillar"
SPRYKER_DIRECTORY = BASE_DIRECTORY + "/project"
VM_SETTINGS_FILE = BASE_DIRECTORY + "/.vm"
# Check if a VM configuration is already available
if File.exists? VM_SETTINGS_FILE
puts bold "Loading VM settings file: .vm"
load(VM_SETTINGS_FILE)
if ARGV.include? 'destroy'
puts bold "Deleting VM settings file: .vm"
File.delete(VM_SETTINGS_FILE)
end
else
# Project settings
VM_PROJECT = ENV['VM_PROJECT'] || 'suite' # Project name
VM_DOMAIN = ENV['VM_DOMAIN'] || VM_PROJECT # Domain name component, based on project
# Git parameters
SPRYKER_REPOSITORY = ENV['SPRYKER_REPOSITORY'] || "https://github.com/spryker-shop/#{VM_PROJECT}.git"
SPRYKER_BRANCH = ENV['SPRYKER_BRANCH'] || "master"
# Auto-generate IP address based on hash of VM_PROJECT
unique_byte = (Digest::SHA256.hexdigest(VM_PROJECT).to_i(16).modulo(251)+3).to_s
# Settings for the Virtualbox VM
VM_IP_PREFIX = ENV['VM_IP_PREFIX'] || '10.0.240.' # Prefix for IP address of DEV VM
VM_IP = ENV['VM_IP'] || VM_IP_PREFIX + unique_byte # IP Address of the DEV VM
VM_MEMORY = ENV['VM_MEMORY'] || '8000' # Number of memory for DEV VM, in MB
VM_CPUS = ENV['VM_CPUS'] || '4' # Number of CPU cores for DEV VM
VM_NAME = ENV['VM_NAME'] || "Spryker Dev VM (#{VM_PROJECT})" # Display name for VirtualBox
VM_SKIP_SF = ENV['VM_SKIP_SF'] || '0' # Don't mount shared folders
config=
"VM_PROJECT = '#{VM_PROJECT}'\n" +
"VM_IP = '#{VM_IP}'\n" +
"VM_MEMORY = '#{VM_MEMORY}'\n" +
"VM_CPUS = '#{VM_CPUS}'\n" +
"VM_NAME = '#{VM_NAME}'\n" +
"VM_DOMAIN = '#{VM_DOMAIN}'\n" +
"VM_SKIP_SF = '#{VM_SKIP_SF}'\n" +
"SPRYKER_BRANCH = '#{SPRYKER_BRANCH}'\n" +
"SPRYKER_REPOSITORY = '#{SPRYKER_REPOSITORY}'\n"
unless (ARGV & ['up', 'reload', 'provision']).empty?
puts yellow "The following settings will be used for the new VM:"
puts config
puts bold "Press return to save the settings or Ctrl+C to abort"
puts "If you save the settings, they will be stored in a .vm file on your hard drive."
puts "To change a setting, interrupt now and modify the respective environmental variables."
File.write(VM_SETTINGS_FILE, config.gsub(/ *= */, '='))
end
end
# Hostnames to be managed
STORES = ['de', 'at', 'us']
HOSTS = [ 'spryker-vagrant' ]
['', '-test'].each do |host_suffix|
domain = VM_DOMAIN + '.local'
STORES.each do |store|
HOSTS.push [
"www#{host_suffix}.#{store}.#{domain}",
"zed#{host_suffix}.#{store}.#{domain}",
"glue#{host_suffix}.#{store}.#{domain}",
"gateway#{host_suffix}.#{store}.#{domain}",
"backoffice#{host_suffix}.#{store}.#{domain}",
"backend-gateway#{host_suffix}.#{store}.#{domain}",
"backend-api#{host_suffix}.#{store}.#{domain}"
]
end
HOSTS.push [ "static#{host_suffix}.#{domain}" ]
end
HOSTS.push [ "demo-date-time-configurator.spryker.local" ]
###
### END OF CONFIGURATION
###
# Check whether we are running in a UNIX or Windows-based machine
if Vagrant::Util::Platform.windows?
HOSTS_PATH = 'c:\WINDOWS\system32\drivers\etc\hosts'
IS_WINDOWS = true
IS_UNIX = false
IS_LINUX = false
IS_OSX = false
else
HOSTS_PATH = '/etc/hosts'
end
# mkmf
require 'mkmf'
File.delete('mkmf.log') if File.exists?('mkmf.log')
# Verify if salt/pillar directories are present
has_fresh_repos = false
if has_fresh_repos
puts yellow "Fresh repositories have been cloned. If you just cloned the sample repository, have a look at the README.md file in the salt repository"
sleep 5
end
if defined?(SPRYKER_REPOSITORY) and not SPRYKER_REPOSITORY.empty? # Clone Spryker repository (if specified)
# This line is giving exception: Message: TypeError: no implicit conversion of false into Array
#if (not Dir.exists?(SPRYKER_DIRECTORY)) or Dir.entries(SPRYKER_DIRECTORY) - %w{ . .. }.empty? # Only clone if it's empty folder
if (not Dir.exists?(SPRYKER_DIRECTORY))
puts bold "Cloning Spryker git repository..."
if find_executable 'git'
system "git clone #{SPRYKER_REPOSITORY} --branch #{SPRYKER_BRANCH} \"#{SPRYKER_DIRECTORY}\""
else
raise "ERROR: Required #{SPRYKER_DIRECTORY} could not be found and no git executable was found to solve this problem." +
"\n\n\033[0m"
end
elsif not Dir.entries(SPRYKER_DIRECTORY).include? 'composer.json'
raise "ERROR: The directory #{SPRYKER_DIRECTORY} isn't empty, yet it's not a clone of spryker repository!"
end
else
puts yellow "Spryker repository is not defined in Vagrantfile and the SPRYKER_REPOSITORY is empty - no repository to clone..."
end
Vagrant.configure(2) do |config|
# Base box for initial setup. Latest Debian (stable) is recommended.
# The box file should have virtualbox guest additions installed, otherwise shared folders will not work
config.vm.box = "debian10_ci-vm-146"
config.vm.box_url = "http://ci.spryker.systems:8000/debian10_ci-vm-146.box"
# config.vbguest.auto_update = true
config.vm.hostname = "vm-#{VM_PROJECT}"
config.vm.boot_timeout = 300
# Enable ssh agent forwarding
config.ssh.forward_agent = true
# Set the VirtualBox IP address for the browser
config.vm.network :private_network, ip: VM_IP, nic_type: "virtio"
config.vm.synced_folder "project/", "/data/shop/development/current", owner: "www-data", group: "www-data", mount_options: ["dmode=777,fmode=777"]
#configure variables:
config.vm.provision "shell", inline: "set -x; sudo echo ""export APPLICATION_ENV=development"" >> /etc/profile; sudo echo ""export COMPOSER_PROCESS_TIMEOUT=3600"" >> /etc/profile; sudo /usr/sbin/usermod -aG www-data vagrant"
# SaltStack masterless setup
if Dir.exists?(PILLAR_DIRECTORY) && Dir.exists?(SALT_DIRECTORY)
config.vm.synced_folder SALT_DIRECTORY, "/srv/salt/"
config.vm.synced_folder PILLAR_DIRECTORY, "/srv/pillar/"
config.vm.provision :salt do |salt|
salt.minion_config = "salt_minion"
salt.run_highstate = true
salt.bootstrap_options = "-F -P -c /tmp"
salt.version = "v3003.1"
salt.verbose = false
salt.install_type = "git"
end
else
raise "ERROR: Salt (#{SALT_DIRECTORY}) or Pillar (#{PILLAR_DIRECTORY}) directory not found.\n\n\033[0m"
end
# Add hosts to /etc/hosts
if Vagrant.has_plugin? 'vagrant-hostmanager'
puts bold "Configuring vagrant-hostmanager (#{HOSTS.count} hostnames)..."
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.hostmanager.aliases = HOSTS
config.vm.provision :hostmanager
puts "Using vagrant-hostmanager to set hostnames: " + HOSTS.join(', ')
else
hosts_line = VM_IP + " " + HOSTS.join(' ')
if not File.open(HOSTS_PATH).each_line.any? { |line| line.chomp == hosts_line }
puts bold "Please add the following entries to your #{HOSTS_PATH} file: \n\033[0m"
puts hosts_line
end
end
config.vm.provider :virtualbox do |vb|
vb.name = VM_NAME
vb.check_guest_additions = false
vb.customize ["modifyvm", :id, "--nic2", "hostonly", "--hostonlyadapter1", "VirtualBox Host-Only Ethernet Adapter"]
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"]
vb.customize(["modifyvm", :id, "--memory", VM_MEMORY, "--cpus", VM_CPUS, "--audio", "none"])
end
end