Vagrantfile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. require 'pathname'
  2. require 'tempfile'
  3. require 'yaml'
  4. srvpath = Pathname.new(File.dirname(__FILE__)).realpath
  5. configfile = YAML.load_file(File.join(srvpath, "/.gitlab-ci.yml"))
  6. remote_url = 'https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake'
  7. # set up essential environment variables
  8. env = configfile['variables']
  9. env = env.merge(configfile['android']['variables'])
  10. env['CI_PROJECT_DIR'] = '/builds/tpo/anti-censorship/pluggable-transports/snowflake'
  11. env_file = Tempfile.new('env')
  12. File.chmod(0644, env_file.path)
  13. env.each do |k,v|
  14. env_file.write("export #{k}='#{v}'\n")
  15. end
  16. env_file.rewind
  17. sourcepath = '/etc/profile.d/env.sh'
  18. header = "#!/bin/bash -ex\nsource #{sourcepath}\ncd $CI_PROJECT_DIR\n"
  19. before_script_file = Tempfile.new('before_script')
  20. File.chmod(0755, before_script_file.path)
  21. before_script_file.write(header)
  22. configfile['android']['before_script'].flatten.each do |line|
  23. before_script_file.write(line)
  24. before_script_file.write("\n")
  25. end
  26. before_script_file.rewind
  27. script_file = Tempfile.new('script')
  28. File.chmod(0755, script_file.path)
  29. script_file.write(header)
  30. configfile['android']['script'].flatten.each do |line|
  31. script_file.write(line)
  32. script_file.write("\n")
  33. end
  34. script_file.rewind
  35. Vagrant.configure("2") do |config|
  36. config.vm.box = "debian/bullseye64"
  37. config.vm.synced_folder '.', '/vagrant', disabled: true
  38. config.vm.provision "file", source: env_file.path, destination: 'env.sh'
  39. config.vm.provision :shell, inline: <<-SHELL
  40. set -ex
  41. mv ~vagrant/env.sh #{sourcepath}
  42. source #{sourcepath}
  43. test -d /go || mkdir /go
  44. mkdir -p $(dirname $CI_PROJECT_DIR)
  45. chown -R vagrant.vagrant $(dirname $CI_PROJECT_DIR)
  46. apt-get update
  47. apt-get -qy install --no-install-recommends git
  48. git clone #{remote_url} $CI_PROJECT_DIR
  49. chmod -R a+rX,u+w /go $CI_PROJECT_DIR
  50. chown -R vagrant.vagrant /go $CI_PROJECT_DIR
  51. SHELL
  52. config.vm.provision "file", source: before_script_file.path, destination: 'before_script.sh'
  53. config.vm.provision "file", source: script_file.path, destination: 'script.sh'
  54. config.vm.provision :shell, inline: '/home/vagrant/before_script.sh'
  55. config.vm.provision :shell, privileged: false, inline: '/home/vagrant/script.sh'
  56. # remove this or comment it out to use VirtualBox instead of libvirt
  57. config.vm.provider :libvirt do |libvirt|
  58. libvirt.memory = 1536
  59. end
  60. end