Vagrantfile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. ENV["PORT"] ||= "3000"
  4. $provisionA = <<SCRIPT
  5. # Add the yarn repo + yarn repo keys
  6. curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  7. sudo apt-add-repository 'deb https://dl.yarnpkg.com/debian/ stable main'
  8. # Add repo for NodeJS
  9. curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
  10. # Add firewall rule to redirect 80 to PORT and save
  11. sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port #{ENV["PORT"]}
  12. echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
  13. echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
  14. sudo apt-get install iptables-persistent -y
  15. # Add packages to build and run Mastodon
  16. sudo apt-get install \
  17. git-core \
  18. g++ \
  19. libpq-dev \
  20. libxml2-dev \
  21. libxslt1-dev \
  22. imagemagick \
  23. nodejs \
  24. redis-server \
  25. redis-tools \
  26. postgresql \
  27. postgresql-contrib \
  28. libicu-dev \
  29. libidn11-dev \
  30. libreadline6-dev \
  31. autoconf \
  32. bison \
  33. build-essential \
  34. ffmpeg \
  35. file \
  36. gcc \
  37. libffi-dev \
  38. libgdbm-dev \
  39. libjemalloc-dev \
  40. libncurses5-dev \
  41. libprotobuf-dev \
  42. libssl-dev \
  43. libyaml-dev \
  44. pkg-config \
  45. protobuf-compiler \
  46. zlib1g-dev \
  47. -y
  48. # Install rvm
  49. sudo apt-add-repository -y ppa:rael-gc/rvm
  50. sudo apt-get install rvm -y
  51. sudo usermod -a -G rvm $USER
  52. SCRIPT
  53. $provisionElasticsearch = <<SCRIPT
  54. # Install Elastic Search
  55. sudo apt install openjdk-17-jre-headless -y
  56. sudo wget -O /usr/share/keyrings/elasticsearch.asc https://artifacts.elastic.co/GPG-KEY-elasticsearch
  57. sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/elasticsearch.asc] https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
  58. sudo apt update
  59. sudo apt install elasticsearch -y
  60. sudo systemctl daemon-reload
  61. sudo systemctl enable --now elasticsearch
  62. echo 'path.data: /var/lib/elasticsearch
  63. path.logs: /var/log/elasticsearch
  64. network.host: 0.0.0.0
  65. http.port: 9200
  66. discovery.seed_hosts: ["localhost"]
  67. cluster.initial_master_nodes: ["node-1"]' > /etc/elasticsearch/elasticsearch.yml
  68. sudo systemctl restart elasticsearch
  69. # Install Kibana
  70. sudo apt install kibana -y
  71. sudo systemctl enable --now kibana
  72. echo 'server.host: "0.0.0.0"
  73. elasticsearch.hosts: ["http://localhost:9200"]' > /etc/kibana/kibana.yml
  74. sudo systemctl restart kibana
  75. SCRIPT
  76. $provisionB = <<SCRIPT
  77. source "/etc/profile.d/rvm.sh"
  78. # Install Ruby
  79. read RUBY_VERSION < /vagrant/.ruby-version
  80. rvm install ruby-$RUBY_VERSION --disable-binary
  81. # Configure database
  82. sudo -u postgres createuser -U postgres vagrant -s
  83. sudo -u postgres createdb -U postgres mastodon_development
  84. cd /vagrant # This is where the host folder/repo is mounted
  85. # Install gems
  86. gem install bundler foreman
  87. bundle install
  88. # Install node modules
  89. sudo corepack enable
  90. yarn set version classic
  91. yarn install
  92. # Build Mastodon
  93. export RAILS_ENV=development
  94. export $(cat ".env.vagrant" | xargs)
  95. bundle exec rails db:setup
  96. # Configure automatic loading of environment variable
  97. echo 'export RAILS_ENV=development' >> ~/.bash_profile
  98. echo 'export $(cat "/vagrant/.env.vagrant" | xargs)' >> ~/.bash_profile
  99. SCRIPT
  100. VAGRANTFILE_API_VERSION = "2"
  101. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  102. config.vm.box = "ubuntu/focal64"
  103. config.vm.provider :virtualbox do |vb|
  104. vb.name = "mastodon"
  105. vb.customize ["modifyvm", :id, "--memory", "8192"]
  106. vb.customize ["modifyvm", :id, "--cpus", "3"]
  107. # Disable VirtualBox DNS proxy to skip long-delay IPv6 resolutions.
  108. # https://github.com/mitchellh/vagrant/issues/1172
  109. vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
  110. vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
  111. # Use "virtio" network interfaces for better performance.
  112. vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
  113. vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
  114. end
  115. # This uses the vagrant-hostsupdater plugin, and lets you
  116. # access the development site at http://mastodon.local.
  117. # If you change it, also change it in .env.vagrant before provisioning
  118. # the vagrant server to update the development build.
  119. #
  120. # To install:
  121. # $ vagrant plugin install vagrant-hostsupdater
  122. config.vm.hostname = "mastodon.local"
  123. if defined?(VagrantPlugins::HostsUpdater)
  124. config.vm.network :private_network, ip: "192.168.42.42", nictype: "virtio"
  125. config.hostsupdater.remove_on_suspend = false
  126. end
  127. if config.vm.networks.any? { |type, options| type == :private_network }
  128. config.vm.synced_folder ".", "/vagrant", type: "nfs", mount_options: ['rw', 'actimeo=1']
  129. else
  130. config.vm.synced_folder ".", "/vagrant"
  131. end
  132. # Otherwise, you can access the site at http://localhost:3000 and http://localhost:4000 , http://localhost:8080
  133. config.vm.network :forwarded_port, guest: 3000, host: 3000
  134. config.vm.network :forwarded_port, guest: 4000, host: 4000
  135. config.vm.network :forwarded_port, guest: 8080, host: 8080
  136. config.vm.network :forwarded_port, guest: 9200, host: 9200
  137. config.vm.network :forwarded_port, guest: 9300, host: 9300
  138. config.vm.network :forwarded_port, guest: 9243, host: 9243
  139. config.vm.network :forwarded_port, guest: 5601, host: 5601
  140. # Full provisioning script, only runs on first 'vagrant up' or with 'vagrant provision'
  141. config.vm.provision :shell, inline: $provisionA, privileged: false, reset: true
  142. # Run with elevated privileges for Elasticsearch installation
  143. config.vm.provision :shell, inline: $provisionElasticsearch, privileged: true
  144. config.vm.provision :shell, inline: $provisionB, privileged: false
  145. config.vm.post_up_message = <<MESSAGE
  146. To start server
  147. $ vagrant ssh -c "cd /vagrant && foreman start"
  148. MESSAGE
  149. end