2015-08-17 06:37:14 +02:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
|
|
|
|
VAGRANTFILE_API_VERSION = "2"
|
|
|
|
|
2016-02-08 06:09:48 +01:00
|
|
|
def command?(name)
|
2016-08-18 20:59:36 +02:00
|
|
|
`which #{name} > /dev/null 2>&1`
|
2016-02-08 06:09:48 +01:00
|
|
|
$?.success?
|
|
|
|
end
|
|
|
|
|
2016-11-27 07:31:48 +01:00
|
|
|
if Vagrant::VERSION == "1.8.7" then
|
|
|
|
path = `which curl`
|
|
|
|
if path.include?('/opt/vagrant/embedded/bin/curl') then
|
2018-02-12 19:36:26 +01:00
|
|
|
puts "In Vagrant 1.8.7, curl is broken. Please use Vagrant 2.0.2 "\
|
2016-11-27 07:31:48 +01:00
|
|
|
"or run 'sudo rm -f /opt/vagrant/embedded/bin/curl' to fix the "\
|
|
|
|
"issue before provisioning. See "\
|
|
|
|
"https://github.com/mitchellh/vagrant/issues/7997 "\
|
|
|
|
"for reference."
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-13 07:50:45 +01:00
|
|
|
# Workaround: the lxc-config in vagrant-lxc is incompatible with changes in
|
|
|
|
# LXC 2.1.0, found in Ubuntu 17.10 artful. LXC 2.1.1 (in 18.04 LTS bionic)
|
|
|
|
# ignores the old config key, so this will only be needed for artful.
|
|
|
|
#
|
|
|
|
# vagrant-lxc upstream has an attempted fix:
|
|
|
|
# https://github.com/fgrehm/vagrant-lxc/issues/445
|
|
|
|
# but it didn't work in our testing. This is a temporary issue, so we just
|
|
|
|
# hack in a fix: we patch the skeleton `lxc-config` file right in the
|
|
|
|
# distribution of the vagrant-lxc "box" we use. If the user doesn't yet
|
|
|
|
# have the box (e.g. on first setup), Vagrant would download it but too
|
|
|
|
# late for us to patch it like this; so we prompt them to explicitly add it
|
|
|
|
# first and then rerun.
|
2018-02-16 20:11:22 +01:00
|
|
|
if ['up', 'provision'].include? ARGV[0]
|
|
|
|
if command? "lxc-ls"
|
2018-02-16 19:13:54 +01:00
|
|
|
LXC_VERSION = `lxc-ls --version`.strip unless defined? LXC_VERSION
|
|
|
|
if LXC_VERSION == "2.1.0"
|
|
|
|
lxc_config_file = ENV['HOME'] + "/.vagrant.d/boxes/fgrehm-VAGRANTSLASH-trusty64-lxc/1.2.0/lxc/lxc-config"
|
|
|
|
if File.file?(lxc_config_file)
|
|
|
|
lines = File.readlines(lxc_config_file)
|
|
|
|
deprecated_line = "lxc.pivotdir = lxc_putold\n"
|
|
|
|
if lines[1] == deprecated_line
|
|
|
|
lines[1] = "# #{deprecated_line}"
|
|
|
|
File.open(lxc_config_file, 'w') do |f|
|
|
|
|
f.puts(lines)
|
|
|
|
end
|
2018-02-13 07:50:45 +01:00
|
|
|
end
|
2018-02-16 19:13:54 +01:00
|
|
|
else
|
|
|
|
puts 'You are running LXC 2.1.0, and fgrehm/trusty64-lxc box is incompatible '\
|
|
|
|
"with it by default. First add the box by doing:\n"\
|
|
|
|
" vagrant box add https://vagrantcloud.com/fgrehm/trusty64-lxc\n"\
|
|
|
|
'Once this command succeeds, do "vagrant up" again.'
|
|
|
|
exit
|
2018-02-13 07:50:45 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 22:26:23 +01:00
|
|
|
# Workaround: Vagrant removed the atlas.hashicorp.com to
|
|
|
|
# vagrantcloud.com redirect in February 2018. The value of
|
|
|
|
# DEFAULT_SERVER_URL in Vagrant versions less than 1.9.3 is
|
|
|
|
# atlas.hashicorp.com, which means that removal broke the fetching and
|
|
|
|
# updating of boxes (since the old URL doesn't work). See
|
|
|
|
# https://github.com/hashicorp/vagrant/issues/9442
|
2018-03-19 06:12:24 +01:00
|
|
|
if Vagrant::DEFAULT_SERVER_URL == "atlas.hashicorp.com"
|
|
|
|
Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
|
|
|
|
end
|
2018-02-08 22:26:23 +01:00
|
|
|
|
2015-08-17 06:37:14 +02:00
|
|
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
|
|
|
|
2015-08-18 02:05:53 +02:00
|
|
|
# For LXC. VirtualBox hosts use a different box, described below.
|
2015-08-17 06:37:14 +02:00
|
|
|
config.vm.box = "fgrehm/trusty64-lxc"
|
|
|
|
|
2015-08-18 02:05:53 +02:00
|
|
|
# The Zulip development environment runs on 9991 on the guest.
|
2016-07-07 23:47:59 +02:00
|
|
|
host_port = 9991
|
2017-09-14 21:10:14 +02:00
|
|
|
http_proxy = https_proxy = no_proxy = nil
|
2016-12-30 04:47:04 +01:00
|
|
|
host_ip_addr = "127.0.0.1"
|
2015-08-17 06:37:14 +02:00
|
|
|
|
|
|
|
config.vm.synced_folder ".", "/vagrant", disabled: true
|
2017-11-24 17:57:31 +01:00
|
|
|
if (/darwin/ =~ RUBY_PLATFORM) != nil
|
2017-12-01 06:05:08 +01:00
|
|
|
config.vm.synced_folder ".", "/srv/zulip", type: "nfs",
|
|
|
|
linux__nfs_options: ['rw']
|
2017-11-24 17:57:31 +01:00
|
|
|
config.vm.network "private_network", type: "dhcp"
|
|
|
|
else
|
|
|
|
config.vm.synced_folder ".", "/srv/zulip"
|
|
|
|
end
|
2015-08-17 06:37:14 +02:00
|
|
|
|
2016-07-07 23:47:59 +02:00
|
|
|
vagrant_config_file = ENV['HOME'] + "/.zulip-vagrant-config"
|
|
|
|
if File.file?(vagrant_config_file)
|
|
|
|
IO.foreach(vagrant_config_file) do |line|
|
2016-04-09 15:06:07 +02:00
|
|
|
line.chomp!
|
|
|
|
key, value = line.split(nil, 2)
|
|
|
|
case key
|
|
|
|
when /^([#;]|$)/; # ignore comments
|
|
|
|
when "HTTP_PROXY"; http_proxy = value
|
|
|
|
when "HTTPS_PROXY"; https_proxy = value
|
|
|
|
when "NO_PROXY"; no_proxy = value
|
2016-07-07 23:47:59 +02:00
|
|
|
when "HOST_PORT"; host_port = value.to_i
|
2016-12-30 04:47:04 +01:00
|
|
|
when "HOST_IP_ADDR"; host_ip_addr = value
|
2016-04-09 15:06:07 +02:00
|
|
|
end
|
|
|
|
end
|
2016-07-07 23:47:59 +02:00
|
|
|
end
|
2016-04-09 15:06:07 +02:00
|
|
|
|
2016-07-07 23:47:59 +02:00
|
|
|
if Vagrant.has_plugin?("vagrant-proxyconf")
|
2017-09-14 21:10:14 +02:00
|
|
|
if !http_proxy.nil?
|
2016-07-07 23:47:59 +02:00
|
|
|
config.proxy.http = http_proxy
|
|
|
|
end
|
2017-09-14 21:10:14 +02:00
|
|
|
if !https_proxy.nil?
|
2016-07-07 23:47:59 +02:00
|
|
|
config.proxy.https = https_proxy
|
|
|
|
end
|
2017-09-14 21:10:14 +02:00
|
|
|
if !no_proxy.nil?
|
2016-07-07 23:47:59 +02:00
|
|
|
config.proxy.no_proxy = no_proxy
|
2016-04-09 15:06:07 +02:00
|
|
|
end
|
2017-09-14 21:10:14 +02:00
|
|
|
elsif !http_proxy.nil? or !https_proxy.nil?
|
|
|
|
# This prints twice due to https://github.com/hashicorp/vagrant/issues/7504
|
|
|
|
# We haven't figured out a workaround.
|
|
|
|
puts 'You have specified value for proxy in ~/.zulip-vagrant-config file but did not ' \
|
|
|
|
'install the vagrant-proxyconf plugin. To install it, run `vagrant plugin install ' \
|
|
|
|
'vagrant-proxyconf` in a terminal. This error will appear twice.'
|
|
|
|
exit
|
2016-04-09 15:06:07 +02:00
|
|
|
end
|
|
|
|
|
2017-09-14 21:10:14 +02:00
|
|
|
config.vm.network "forwarded_port", guest: 9991, host: host_port, host_ip: host_ip_addr
|
2016-01-10 01:31:37 +01:00
|
|
|
# Specify LXC provider before VirtualBox provider so it's preferred.
|
|
|
|
config.vm.provider "lxc" do |lxc|
|
2016-02-08 06:09:48 +01:00
|
|
|
if command? "lxc-ls"
|
|
|
|
LXC_VERSION = `lxc-ls --version`.strip unless defined? LXC_VERSION
|
|
|
|
if LXC_VERSION >= "1.1.0"
|
|
|
|
# Allow start without AppArmor, otherwise Box will not Start on Ubuntu 14.10
|
|
|
|
# see https://github.com/fgrehm/vagrant-lxc/issues/333
|
|
|
|
lxc.customize 'aa_allow_incomplete', 1
|
|
|
|
end
|
Vagrantfile: Fix using Vagrant with LXC >= 2.
Apparently LXC 2 removed support for the `-B best` option in
lxc-create, and Vagrant hasn't been updated appropriately yet, so we
need to add a workaround to explicitly specify a backing store.
Fixes #718.
This manifested as errors of the form:
"""
There was an error executing ["sudo",
"/usr/local/bin/vagrant-lxc-wrapper", "lxc-create", "-B", "best",
"--template",
"/home/tabbott/.vagrant.d/gems/gems/vagrant-lxc-1.2.1/scripts/lxc-template",
"--name", "zulip_default_1461801696512_85064", "--", "--tarball",
"/home/tabbott/.vagrant.d/boxes/fgrehm-VAGRANTSLASH-trusty64-lxc/1.2.0/lxc/rootfs.tar.gz",
"--config",
"/home/tabbott/.vagrant.d/boxes/fgrehm-VAGRANTSLASH-trusty64-lxc/1.2.0/lxc/lxc-config"]
"""
2016-04-28 02:06:37 +02:00
|
|
|
if LXC_VERSION >= "2.0.0"
|
|
|
|
lxc.backingstore = 'dir'
|
|
|
|
end
|
2016-01-10 01:31:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-17 19:18:40 +02:00
|
|
|
config.vm.provider "virtualbox" do |vb, override|
|
2015-08-17 06:37:14 +02:00
|
|
|
override.vm.box = "ubuntu/trusty64"
|
2016-07-21 03:39:54 +02:00
|
|
|
# It's possible we can get away with just 1.5GB; more testing needed
|
|
|
|
vb.memory = 2048
|
2016-09-08 04:22:21 +02:00
|
|
|
vb.cpus = 2
|
2015-08-17 06:37:14 +02:00
|
|
|
end
|
2015-08-17 20:14:52 +02:00
|
|
|
|
2016-09-08 04:30:48 +02:00
|
|
|
config.vm.provider "vmware_fusion" do |vb, override|
|
|
|
|
override.vm.box = "puphpet/ubuntu1404-x64"
|
|
|
|
vb.vmx["memsize"] = "2048"
|
|
|
|
vb.vmx["numvcpus"] = "2"
|
|
|
|
end
|
|
|
|
|
2015-08-19 04:14:50 +02:00
|
|
|
$provision_script = <<SCRIPT
|
|
|
|
set -x
|
|
|
|
set -e
|
2016-07-06 23:29:33 +02:00
|
|
|
set -o pipefail
|
2017-10-27 20:44:47 +02:00
|
|
|
|
|
|
|
# Code should go here, rather than tools/provision, only if it is
|
|
|
|
# something that we don't want to happen when running provision in a
|
|
|
|
# development environment not using Vagrant.
|
|
|
|
|
2018-02-18 11:45:19 +01:00
|
|
|
# Set the MOTD on the system to have Zulip instructions
|
|
|
|
sudo rm -f /etc/update-motd.d/*
|
|
|
|
sudo bash -c 'cat << EndOfMessage > /etc/motd
|
|
|
|
Welcome to the Zulip development environment! Popular commands:
|
|
|
|
* tools/provision - Update the development environment
|
|
|
|
* tools/run-dev.py - Run the development server
|
|
|
|
* tools/lint - Run the linter (quick and catches many problmes)
|
|
|
|
* tools/test-* - Run tests (use --help to learn about options)
|
|
|
|
|
2018-04-05 23:41:38 +02:00
|
|
|
Read https://zulip.readthedocs.io/en/latest/testing/testing.html to learn
|
2018-02-18 11:45:19 +01:00
|
|
|
how to run individual test suites so that you can get a fast debug cycle.
|
|
|
|
|
|
|
|
EndOfMessage'
|
|
|
|
|
2016-11-22 00:48:00 +01:00
|
|
|
# If the host is running SELinux remount the /sys/fs/selinux directory as read only,
|
|
|
|
# needed for apt-get to work.
|
|
|
|
if [ -d "/sys/fs/selinux" ]; then
|
2017-10-27 20:58:25 +02:00
|
|
|
sudo mount -o remount,ro /sys/fs/selinux
|
2016-11-22 00:48:00 +01:00
|
|
|
fi
|
2016-11-22 19:43:01 +01:00
|
|
|
|
|
|
|
# Set default locale, this prevents errors if the user has another locale set.
|
|
|
|
if ! grep -q 'LC_ALL=en_US.UTF-8' /etc/default/locale; then
|
|
|
|
echo "LC_ALL=en_US.UTF-8" | sudo tee -a /etc/default/locale
|
|
|
|
fi
|
|
|
|
|
2017-10-27 20:44:47 +02:00
|
|
|
# Set an environment variable, so that we won't print the virtualenv
|
|
|
|
# shell warning (it'll be wrong, since the shell is dying anyway)
|
|
|
|
export SKIP_VENV_SHELL_WARNING=1
|
|
|
|
|
2017-10-27 20:59:33 +02:00
|
|
|
# End `set -x`, so that the end of provision doesn't look like an error
|
|
|
|
# message after a successful run.
|
|
|
|
set +x
|
|
|
|
|
2018-03-19 06:15:12 +01:00
|
|
|
# Check if the zulip directory is writable
|
|
|
|
if [ ! -w /srv/zulip ]; then
|
|
|
|
echo "The vagrant user is unable to write to the zulip directory."
|
|
|
|
echo "To fix this, run the following commands on the host machine:"
|
|
|
|
# sudo is required since our uid is not 1000
|
|
|
|
echo ' vagrant halt -f'
|
|
|
|
echo ' rm -rf /PATH/TO/ZULIP/CLONE/.vagrant'
|
|
|
|
echo ' sudo chown -R 1000:$(whoami) /PATH/TO/ZULIP/CLONE'
|
|
|
|
echo "Replace /PATH/TO/ZULIP/CLONE with the path to where zulip code is cloned."
|
|
|
|
echo "You can resume setting up your vagrant environment by running:"
|
|
|
|
echo " vagrant up"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-11-22 19:43:01 +01:00
|
|
|
# Provision the development environment
|
2016-06-16 12:50:54 +02:00
|
|
|
ln -nsf /srv/zulip ~/zulip
|
2017-01-14 11:19:26 +01:00
|
|
|
/srv/zulip/tools/provision
|
2016-11-22 19:43:01 +01:00
|
|
|
|
|
|
|
# Run any custom provision hooks the user has configured
|
2017-01-30 16:58:54 +01:00
|
|
|
if [ -f /srv/zulip/tools/custom_provision ]; then
|
2017-10-27 20:58:25 +02:00
|
|
|
chmod +x /srv/zulip/tools/custom_provision
|
|
|
|
/srv/zulip/tools/custom_provision
|
2017-01-30 16:58:54 +01:00
|
|
|
fi
|
2015-08-19 04:14:50 +02:00
|
|
|
SCRIPT
|
|
|
|
|
|
|
|
config.vm.provision "shell",
|
2017-01-14 11:19:26 +01:00
|
|
|
# We want provision to be run with the permissions of the vagrant user.
|
2015-08-19 04:14:50 +02:00
|
|
|
privileged: false,
|
|
|
|
inline: $provision_script
|
2015-08-17 06:37:14 +02:00
|
|
|
end
|