Vagrantfile 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ansible_version = File.read('requirements.txt').split.find { |item| item.start_with? 'ansible==' }.split('==')[1]
  2. goss_version = '0.3.21'
  3. pebble_version = '2.3.1'
  4. install_goss = <<~SHELL
  5. echo "Running Goss tests:"
  6. echo "The target is \$TARGET" && \
  7. curl -Lo /tmp/goss https://github.com/aelsabbahy/goss/releases/download/v#{goss_version}/goss-linux-amd64 && \
  8. echo "9a9200779603acf0353d2c0e85ae46e083596c10838eaf4ee050c924678e4fe3 /tmp/goss" | sha256sum -c --strict - && \
  9. sudo install -m0755 -o root -g root /tmp/goss /usr/bin/goss && \
  10. rm /tmp/goss
  11. cd /vagrant
  12. sudo -E goss --vars vars.yaml validate
  13. SHELL
  14. #Fix for https://github.com/mastodon/mastodon-ansible/pull/33#issuecomment-1126071199
  15. postgres_use_md5 = <<-'SHELL'
  16. echo "Running PostgreSQL commands required for testing"
  17. sudo sed -i 's/host\s\s\s\sall\s\s\s\s\s\s\s\s\s\s\s\s\sall\s\s\s\s\s\s\s\s\s\s\s\s\s127.0.0.1\/32\s\s\s\s\s\s\s\s\s\s\s\sident/host all all 127.0.0.1\/32 md5/g' /var/lib/pgsql/data/pg_hba.conf
  18. sudo sed -i 's/host\s\s\s\sall\s\s\s\s\s\s\s\s\s\s\s\s\sall\s\s\s\s\s\s\s\s\s\s\s\s\s::1\/128\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\sident/host all all ::1\/128 md5/g' /var/lib/pgsql/data/pg_hba.conf
  19. sudo systemctl restart postgresql
  20. SHELL
  21. #Need to run this under root for it to stick and not throw permission errors
  22. #Enabling PEBBLE_VA_ALWAYS_VALID=1 as final challenge response from Pebble returns an empty body
  23. #and always fails the HTTP-01 ACME challenge. Possible upstream bug?
  24. #Until its fixed we don't need Pebble ACME Response Server for the time being
  25. localhost_domain = <<~SHELL
  26. echo "Set localhost to answer to mastodon.local"
  27. sudo su
  28. echo "127.0.0.1 mastodon.local" >> /etc/hosts
  29. echo "Run preventive cleanup tasks for Pebble ACME Server"
  30. rm -rf /etc/letsencrypt/accounts/localhost:14000
  31. echo "Download Pebble ACME Server tarball containing tests"
  32. curl -Lo /tmp/pebble-v#{pebble_version}.tar.gz https://github.com/letsencrypt/pebble/archive/refs/tags/v#{pebble_version}.tar.gz
  33. tar -xvzf /tmp/pebble-v#{pebble_version}.tar.gz -C /tmp/
  34. echo "Install and start Pebble ACME Server binary for testing"
  35. curl -Lo /tmp/pebble-#{pebble_version}/pebble https://github.com/letsencrypt/pebble/releases/download/v#{pebble_version}/pebble_linux-amd64
  36. chmod +x /tmp/pebble-#{pebble_version}/pebble
  37. echo "PEBBLE_VA_ALWAYS_VALID=1 /tmp/pebble-#{pebble_version}/pebble -config ./test/config/pebble-config.json" > /tmp/pebble-#{pebble_version}/pebble.sh && chmod +x /tmp/pebble-#{pebble_version}/pebble.sh
  38. cd /tmp/pebble-#{pebble_version} && nohup ./pebble.sh &> /tmp/pebble.log&
  39. #sleep 2 && cat /tmp/pebble.log #Debug Option, use for when debugging ACME auth issues
  40. SHELL
  41. ansible_extra_vars = {
  42. mastodon_db_password: 'CHANGEME',
  43. mastodon_host: 'mastodon.local',
  44. redis_pass: 'CHANGEME',
  45. local_domain: 'mastodon.local',
  46. certbot_extra_param: '--server https://localhost:14000/dir --no-verify-ssl',
  47. use_legacy_certbot: 'false',
  48. letsencrypt_email: 'webmaster@mastodon.local'
  49. }
  50. Vagrant.require_version ">= 2.3.5"
  51. Vagrant.configure('2') do |config|
  52. # RAM has to be bumped up due of precompile assets silently failing with just 1GB of RAM
  53. # https://github.com/rails/webpacker/issues/955
  54. config.vm.provider 'virtualbox' do |vb|
  55. vb.memory = '4096'
  56. # We need to disable nested virtualization since GitHub Actions doesn't support it
  57. # https://github.com/actions/virtual-environments/issues/183#issuecomment-610723516
  58. #
  59. # I have disabled this for now since we are running our tests on macOS (for now) which has "native" Vagrant support on GH
  60. #
  61. # %w[hwvirtex vtxvpid vtxux].each do |instruction|
  62. # vb.customize ["modifyvm", :id, "--#{instruction}", "off"]
  63. # end if ENV['CI'] == "true"
  64. end
  65. config.vm.provider 'vmware_fusion' do |vb|
  66. vb.memory = '4096'
  67. end
  68. [
  69. {
  70. name: 'focal',
  71. primary: true,
  72. autostart: true
  73. },
  74. {
  75. name: 'jammy',
  76. primary: false,
  77. autostart: false
  78. }
  79. ].each do |d|
  80. config.vm.define d[:name], primary: d[:primary], autostart: d[:autostart] do |bare|
  81. bare.vm.box = "ubuntu/#{d[:name]}64"
  82. #MacOS Ventura workaround
  83. #bare.vm.network :private_network, type: 'dhcp', name: "HostOnly", virtualbox__intnet: true
  84. bare.vm.network 'private_network', type: 'dhcp'
  85. #Needs to be ran before running the playbook or Ansible checks will fail
  86. #as we are checking against non-valid FQDN
  87. bare.vm.provision 'shell' do |shell|
  88. shell.privileged = true
  89. shell.inline = localhost_domain
  90. end
  91. bare.vm.provision 'ansible' do |ansible|
  92. ansible.playbook = 'bare/playbook.yml'
  93. ansible.extra_vars = ansible_extra_vars
  94. ansible.version = ansible_version
  95. ansible.verbose = true
  96. end
  97. bare.vm.provision 'shell' do |shell|
  98. shell.privileged = false
  99. shell.env = {
  100. 'TARGET' => 'ubuntu'
  101. }
  102. shell.inline = install_goss
  103. end
  104. end
  105. end
  106. config.vm.define 'rhel8', autostart: false do |bare|
  107. #For VMWare Provider, you can use generic/rocky8
  108. #bare.vm.box = 'generic/rocky8'
  109. bare.vm.box = 'geerlingguy/rockylinux8'
  110. #MacOS Ventura workaround
  111. #bare.vm.network :private_network, type: 'dhcp', name: "HostOnly", virtualbox__intnet: true
  112. bare.vm.network 'private_network', type: 'dhcp'
  113. #Needs to be ran before running the playbook or Ansible checks will fail
  114. #as we are checking against non-valid FQDN
  115. bare.vm.provision 'shell' do |shell|
  116. shell.privileged = true
  117. shell.inline = localhost_domain
  118. end
  119. bare.vm.provision 'ansible' do |ansible|
  120. ansible.playbook = 'bare/playbook.yml'
  121. ansible.version = ansible_version
  122. ansible.extra_vars = ansible_extra_vars
  123. ansible.verbose = true
  124. end
  125. #We can't have two shell.inline for some reason or the first one won't run
  126. bare.vm.provision 'shell' do |shell|
  127. shell.privileged = true
  128. shell.inline = postgres_use_md5
  129. end
  130. bare.vm.provision 'shell' do |shell|
  131. shell.privileged = true
  132. shell.env = {
  133. 'TARGET' => 'rhel'
  134. }
  135. shell.inline = install_goss
  136. end
  137. end
  138. config.vm.define 'rhel9', autostart: false do |bare|
  139. bare.vm.box = 'generic/rocky9'
  140. bare.vm.network 'private_network', type: 'dhcp'
  141. #Not specifying this results in
  142. #this error to be displayed "`playbook` does not exist on the guest: /vagrant/bare/playbook.yml error"
  143. #The generic image might be a just a little bit broken, but rockylinux/9 is not ready yet
  144. bare.vm.synced_folder ".", "/vagrant"
  145. #Needs to be ran before running the playbook or Ansible checks will fail
  146. #as we are checking against non-valid FQDN
  147. bare.vm.provision 'shell' do |shell|
  148. shell.privileged = true
  149. shell.inline = localhost_domain
  150. end
  151. bare.vm.provision 'ansible' do |ansible|
  152. ansible.playbook = 'bare/playbook.yml'
  153. ansible.version = ansible_version
  154. ansible.extra_vars = ansible_extra_vars
  155. ansible.verbose = true
  156. end
  157. #We can't have two shell.inline for some reason or the first one won't run
  158. bare.vm.provision 'shell' do |shell|
  159. shell.privileged = true
  160. shell.inline = postgres_use_md5
  161. end
  162. bare.vm.provision 'shell' do |shell|
  163. shell.privileged = true
  164. shell.env = {
  165. 'TARGET' => 'rhel'
  166. }
  167. shell.inline = install_goss
  168. end
  169. end
  170. end