Vagrantfile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. $provisionB = <<SCRIPT
  54. source "/etc/profile.d/rvm.sh"
  55. # Install Ruby
  56. read RUBY_VERSION < /vagrant/.ruby-version
  57. rvm install ruby-$RUBY_VERSION --disable-binary
  58. # Configure database
  59. sudo -u postgres createuser -U postgres vagrant -s
  60. sudo -u postgres createdb -U postgres mastodon_development
  61. cd /vagrant # This is where the host folder/repo is mounted
  62. # Install gems
  63. gem install bundler foreman
  64. bundle install
  65. # Install node modules
  66. sudo corepack enable
  67. yarn set version classic
  68. yarn install
  69. # Build Mastodon
  70. export RAILS_ENV=development
  71. export $(cat ".env.vagrant" | xargs)
  72. bundle exec rails db:setup
  73. # Configure automatic loading of environment variable
  74. echo 'export RAILS_ENV=development' >> ~/.bash_profile
  75. echo 'export $(cat "/vagrant/.env.vagrant" | xargs)' >> ~/.bash_profile
  76. SCRIPT
  77. VAGRANTFILE_API_VERSION = "2"
  78. Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  79. config.vm.box = "ubuntu/focal64"
  80. config.vm.provider :virtualbox do |vb|
  81. vb.name = "mastodon"
  82. vb.customize ["modifyvm", :id, "--memory", "2048"]
  83. # Increase the number of CPUs. Uncomment and adjust to
  84. # increase performance
  85. # vb.customize ["modifyvm", :id, "--cpus", "3"]
  86. # Disable VirtualBox DNS proxy to skip long-delay IPv6 resolutions.
  87. # https://github.com/mitchellh/vagrant/issues/1172
  88. vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
  89. vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
  90. # Use "virtio" network interfaces for better performance.
  91. vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
  92. vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
  93. end
  94. # This uses the vagrant-hostsupdater plugin, and lets you
  95. # access the development site at http://mastodon.local.
  96. # If you change it, also change it in .env.vagrant before provisioning
  97. # the vagrant server to update the development build.
  98. #
  99. # To install:
  100. # $ vagrant plugin install vagrant-hostsupdater
  101. config.vm.hostname = "mastodon.local"
  102. if defined?(VagrantPlugins::HostsUpdater)
  103. config.vm.network :private_network, ip: "192.168.42.42", nictype: "virtio"
  104. config.hostsupdater.remove_on_suspend = false
  105. end
  106. if config.vm.networks.any? { |type, options| type == :private_network }
  107. config.vm.synced_folder ".", "/vagrant", type: "nfs", mount_options: ['rw', 'actimeo=1']
  108. else
  109. config.vm.synced_folder ".", "/vagrant"
  110. end
  111. # Otherwise, you can access the site at http://localhost:3000 and http://localhost:4000 , http://localhost:8080
  112. config.vm.network :forwarded_port, guest: 3000, host: 3000
  113. config.vm.network :forwarded_port, guest: 4000, host: 4000
  114. config.vm.network :forwarded_port, guest: 8080, host: 8080
  115. # Full provisioning script, only runs on first 'vagrant up' or with 'vagrant provision'
  116. config.vm.provision :shell, inline: $provisionA, privileged: false, reset: true
  117. config.vm.provision :shell, inline: $provisionB, privileged: false
  118. config.vm.post_up_message = <<MESSAGE
  119. To start server
  120. $ vagrant ssh -c "cd /vagrant && foreman start"
  121. MESSAGE
  122. end