forked from f-droid/repomaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
55 lines (49 loc) · 1.95 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
require 'pathname'
require 'tempfile'
require 'yaml'
srvpath = Pathname.new(File.dirname(__FILE__)).realpath
configfile = YAML.load_file(File.join(srvpath, "/.gitlab-ci.yml"))
# use the first URL for the remote called 'origin'
remote_url = `git remote -v`.gsub(/.*\sorigin\s+(https:\S*).*/m, '\1').strip
# set up essential environment variables
env = configfile['variables']
env['CI_PROJECT_DIR'] = '/builds/fdroid/repomaker'
env_file = Tempfile.new('env')
File.chmod(0644, env_file.path)
env.each do |k,v|
env_file.write("export #{k}='#{v}'\n")
end
env_file.rewind
sourcepath = '/etc/profile.d/env.sh'
header = "#!/bin/bash -ex\nsource #{sourcepath}\ncd $CI_PROJECT_DIR\n"
before_script_file = Tempfile.new('before_script')
File.chmod(0755, before_script_file.path)
before_script_file.write(header)
configfile['units']['before_script'].flatten.each do |line|
before_script_file.write(line)
before_script_file.write("\n")
end
before_script_file.rewind
Vagrant.configure("2") do |config|
config.vm.box = "fdroid/basebox-buster64"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.provision "file", source: env_file.path, destination: 'env.sh'
config.vm.provision :shell, inline: <<-SHELL
set -ex
mv ~vagrant/env.sh #{sourcepath}
source #{sourcepath}
mkdir -p $(dirname $CI_PROJECT_DIR)
chown -R vagrant.vagrant $(dirname $CI_PROJECT_DIR)
git clone #{remote_url} $CI_PROJECT_DIR
chmod -R a+rX,u+w $CI_PROJECT_DIR
chown -R vagrant.vagrant $CI_PROJECT_DIR
SHELL
config.vm.provision "file", source: before_script_file.path, destination: 'before_script.sh'
config.vm.provision :shell, inline: '/home/vagrant/before_script.sh'
config.vm.provision :shell, inline: 'chown -R vagrant.vagrant $CI_PROJECT_DIR'
# remove this block or comment it out to use VirtualBox instead of libvirt
config.vm.provider :libvirt do |libvirt|
libvirt.memory = 512
end
end