Make vagrant file more configurable (#1424)

This commit is contained in:
Jonas L 2021-10-21 17:16:24 +02:00 committed by GitHub
parent c4692fe011
commit fc2f0ad842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 91 additions and 56 deletions

147
Vagrantfile vendored
View File

@ -1,73 +1,108 @@
# -*- mode: ruby -*- # -*- mode: ruby -*-
# vi: set ft=ruby : # vi: set ft=ruby :
Vagrant.configure("2") do |config| #
# Tweak guest CPUS and MEMORY using:
# export VAGRANT_CPUS=4
# export VAGRANT_MEMORY=4096
# vagrant up debian-buster
#
# libretime web interface Vagrant.configure('2') do |config|
config.vm.network "forwarded_port", guest: 8080, host:8080 config.vm.network 'forwarded_port', guest: 8080, host: 8080 # web
# icecast2 config.vm.network 'forwarded_port', guest: 8081, host: 8081 # api
config.vm.network "forwarded_port", guest: 8000, host:8000 config.vm.network 'forwarded_port', guest: 8000, host: 8000 # icecast2
# liquidsoap input harbors for instreaming (ie. /master) config.vm.network 'forwarded_port', guest: 8001, host: 8001 # liquidsoap
config.vm.network "forwarded_port", guest: 8001, host:8001 config.vm.network 'forwarded_port', guest: 8002, host: 8002 # liquidsoap
config.vm.network "forwarded_port", guest: 8002, host:8002 config.vm.network 'forwarded_port', guest: 5432, host: 5432 # database
# database
config.vm.network "forwarded_port", guest: 5432, host:5432
# api
config.vm.network "forwarded_port", guest: 8081, host:8081
# make sure we are using nfs (doesn't work out of the box with debian) config.vm.provider 'virtualbox' do |v|
nfsPath = "." v.cpus = ENV.fetch('VAGRANT_CPUS', 2)
# macOS Catalina support v.memory = ENV.fetch('VAGRANT_MEMORY', 1024)
if Dir.exist?("/System/Volumes/Data")
nfsPath = "/System/Volumes/Data" + Dir.pwd
end
config.vm.synced_folder nfsPath, "/vagrant", type: "nfs"
# private network for nfs
config.vm.network "private_network", ip: "192.168.10.100"
config.vm.provider "virtualbox" do |v| # Enable audio drivers on VM settings
# to run without OOMing we need at least 1GB of RAM # See https://github.com/geoffreyplitt/vagrant-audio
v.memory = 1024 if RUBY_PLATFORM =~ /darwin/
v.customize [
# enable audio drivers on VM settings 'modifyvm', :id,
# pinched from https://github.com/GeoffreyPlitt/vagrant-audio '--audio', 'coreaudio',
config.vm.provider :virtualbox do |vb| '--audiocontroller', 'hda' # choices: hda sb16 ac97
if RUBY_PLATFORM =~ /darwin/ ]
vb.customize ["modifyvm", :id, '--audio', 'coreaudio', '--audiocontroller', 'hda'] # choices: hda sb16 ac97 elsif RUBY_PLATFORM =~ /mingw|mswin|bccwin|cygwin|emx/
elsif RUBY_PLATFORM =~ /mingw|mswin|bccwin|cygwin|emx/ v.customize [
vb.customize ["modifyvm", :id, '--audio', 'dsound', '--audiocontroller', 'ac97'] 'modifyvm', :id,
end '--audio', 'dsound',
'--audiocontroller', 'ac97'
]
end end
end end
config.vm.provider "libvirt" do |v| config.vm.provider 'libvirt' do |v|
# to run without OOMing we need at least 1GB of RAM v.cpus = ENV.fetch('VAGRANT_CPUS', 2)
v.memory = 1024 v.memory = ENV.fetch('VAGRANT_MEMORY', 1024)
end end
# default installer args used for all distros # NFS
installer_args="--force --in-place --verbose --postgres --apache --icecast " def setup_nfs(config, nfs_version = nil)
config.vm.network 'private_network', ip: '192.168.10.100'
nfs_path = '.'
# define all the OS boxes we support # NFS macOS support
config.vm.define "ubuntu-bionic" do |os| if Dir.exist?('/System/Volumes/Data')
os.vm.box = "bento/ubuntu-18.04" nfs_path = '/System/Volumes/Data' + Dir.pwd
provision_libretime(os, "debian.sh", installer_args) end
# See https://www.vagrantup.com/docs/synced-folders/nfs#nfs-synced-folder-options
case
when nfs_version.nil? then config.vm.synced_folder nfs_path, '/vagrant', type: 'nfs'
when nfs_version == 4 then config.vm.synced_folder nfs_path, '/vagrant', type: 'nfs',
nfs_version: 4,
nfs_udp: false
else
raise 'Invalid nfs_version provided'
end
end end
config.vm.define "debian-buster" do |os|
os.vm.box = "bento/debian-10" def setup_libretime(config, prepare_script, install_args = '')
provision_libretime(os, "debian.sh", installer_args) config.vm.provision 'prepare',
type: 'shell',
path: 'installer/vagrant/%s' % prepare_script
$script = <<-SCRIPT
cd /vagrant
./install \
--force \
--in-place \
--verbose \
--postgres \
--apache \
--icecast \
--web-port=8080 \
#{install_args}
SCRIPT
config.vm.provision 'install', type: 'shell', inline: $script
end end
config.vm.define "centos" do |os|
# Define all the OS boxes we support
config.vm.define 'ubuntu-bionic' do |os|
os.vm.box = 'bento/ubuntu-18.04'
setup_nfs(config)
setup_libretime(os, 'debian.sh')
end
config.vm.define 'debian-buster' do |os|
os.vm.box = 'debian/buster64'
config.vm.provider 'virtualbox' do |v, override|
override.vm.box = 'bento/debian-10'
end
setup_nfs(config)
setup_libretime(os, 'debian.sh')
end
config.vm.define 'centos' do |os|
os.vm.box = 'centos/8' os.vm.box = 'centos/8'
provision_libretime(os, "centos.sh", installer_args + "--selinux") setup_nfs(config)
setup_libretime(os, 'centos.sh', '--selinux')
end end
def provision_libretime(config, prepare_script, installer_args)
# Prepare OS
config.vm.provision "prepare", type: "shell", path: "installer/vagrant/%s" % prepare_script
# Provision LibreTime
config.vm.provision "install", type: "shell", inline: "cd /vagrant; ./install %s --web-port=8080" % installer_args
end
end end