Vagrantfile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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"]
  68. xpack.security.enabled: false' > /etc/elasticsearch/elasticsearch.yml
  69. sudo systemctl restart elasticsearch
  70. # Install Kibana
  71. sudo apt install kibana -y
  72. sudo systemctl enable --now kibana
  73. echo 'server.host: "0.0.0.0"
  74. elasticsearch.hosts: ["http://localhost:9200"]' > /etc/kibana/kibana.yml
  75. sudo systemctl restart kibana
  76. SCRIPT
  77. $provisionB = <<SCRIPT
  78. source "/etc/profile.d/rvm.sh"
  79. # Install Ruby
  80. read RUBY_VERSION < /vagrant/.ruby-version
  81. rvm install ruby-$RUBY_VERSION --disable-binary
  82. # Configure database
  83. sudo -u postgres createuser -U postgres vagrant -s
  84. sudo -u postgres createdb -U postgres mastodon_development
  85. cd /vagrant # This is where the host folder/repo is mounted
  86. # Install gems
  87. gem install bundler foreman
  88. bundle install
  89. # Install node modules
  90. sudo corepack enable
  91. yarn set version classic
  92. yarn install
  93. # Build Mastodon
  94. export RAILS_ENV=development
  95. export $(cat ".env.vagrant" | xargs)
  96. bundle exec rails db:setup
  97. # Configure automatic loading of environment variable
  98. echo 'export RAILS_ENV=development' >> ~/.bash_profile
  99. echo 'export $(cat "/vagrant/.env.vagrant" | xargs)' >> ~/.bash_profile
  100. SCRIPT
  101. VAGRANTFILE_API_VERSION = "2"
  102. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  103. config.vm.box = "ubuntu/focal64"
  104. config.vm.provider :virtualbox do |vb|
  105. vb.name = "mastodon"
  106. vb.customize ["modifyvm", :id, "--memory", "8192"]
  107. vb.customize ["modifyvm", :id, "--cpus", "3"]
  108. # Disable VirtualBox DNS proxy to skip long-delay IPv6 resolutions.
  109. # https://github.com/mitchellh/vagrant/issues/1172
  110. vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
  111. vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
  112. # Use "virtio" network interfaces for better performance.
  113. vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
  114. vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
  115. end
  116. # This uses the vagrant-hostsupdater plugin, and lets you
  117. # access the development site at http://mastodon.local.
  118. # If you change it, also change it in .env.vagrant before provisioning
  119. # the vagrant server to update the development build.
  120. #
  121. # To install:
  122. # $ vagrant plugin install vagrant-hostsupdater
  123. config.vm.hostname = "mastodon.local"
  124. if defined?(VagrantPlugins::HostsUpdater)
  125. config.vm.network :private_network, ip: "192.168.42.42", nictype: "virtio"
  126. config.hostsupdater.remove_on_suspend = false
  127. end
  128. if config.vm.networks.any? { |type, options| type == :private_network }
  129. config.vm.synced_folder ".", "/vagrant", type: "nfs", mount_options: ['rw', 'actimeo=1']
  130. else
  131. config.vm.synced_folder ".", "/vagrant"
  132. end
  133. # Otherwise, you can access the site at http://localhost:3000 and http://localhost:4000 , http://localhost:8080
  134. config.vm.network :forwarded_port, guest: 3000, host: 3000
  135. config.vm.network :forwarded_port, guest: 4000, host: 4000
  136. config.vm.network :forwarded_port, guest: 8080, host: 8080
  137. config.vm.network :forwarded_port, guest: 9200, host: 9200
  138. config.vm.network :forwarded_port, guest: 9300, host: 9300
  139. config.vm.network :forwarded_port, guest: 9243, host: 9243
  140. config.vm.network :forwarded_port, guest: 5601, host: 5601
  141. # Full provisioning script, only runs on first 'vagrant up' or with 'vagrant provision'
  142. config.vm.provision :shell, inline: $provisionA, privileged: false, reset: true
  143. # Run with elevated privileges for Elasticsearch installation
  144. config.vm.provision :shell, inline: $provisionElasticsearch, privileged: true
  145. config.vm.provision :shell, inline: $provisionB, privileged: false
  146. config.vm.post_up_message = <<MESSAGE
  147. To start server
  148. $ vagrant ssh -c "cd /vagrant && foreman start"
  149. MESSAGE
  150. end