aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-06-23 20:25:20 -0700
committerFuwn <[email protected]>2021-06-23 20:26:25 -0700
commit5fd04f4c035b79c099ec825c035be8a0f8bad2cf (patch)
treefcebcd26c9fe00817aee673ddd6c41c3b1b5ca3d
parentrevert(fmt): error on unformatted (diff)
downloadwhirl-5fd04f4c035b79c099ec825c035be8a0f8bad2cf.tar.xz
whirl-5fd04f4c035b79c099ec825c035be8a0f8bad2cf.zip
ci(vagrant): setup (incomplete)
-rw-r--r--.gitignore3
-rw-r--r--Vagrantfile121
-rw-r--r--bin/base.sh52
-rw-r--r--bin/base_box_optimizations.sh17
-rw-r--r--bin/sqlite.sh4
5 files changed, 197 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 41a7938..f8283b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,6 @@ result*
# Docker
/.whirl-data/
+
+# Vagrant
+/.vagrant/
diff --git a/Vagrantfile b/Vagrantfile
new file mode 100644
index 0000000..3c90d6f
--- /dev/null
+++ b/Vagrantfile
@@ -0,0 +1,121 @@
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+# https://github.com/fideloper/Vaprobash
+
+# Github Configuration
+github_username = "Whirlsplash"
+github_repository = "whirl"
+github_branch = "develop"
+github_url = "https://raw.githubusercontent.com/#{github_username}/#{github_repository}/#{github_branch}"
+
+# Virtual-Machine Configuration
+hostname = "whirlsplash"
+
+# Local private network IP (http://en.wikipedia.org/wiki/Private_network)
+#
+# Valid IP ranges:
+# 10.0.0.1 - 10.255.255.254
+# 172.16.0.1 - 172.31.255.254
+# 192.168.0.1 - 192.168.255.254
+server_ip = "192.168.22.10"
+server_cpus = "1" # Cores
+server_memory = "384" # MB
+server_swap = "768" # MB | false
+ #
+ # Guideline: Keep between one or two times the value of
+ # `server_memory`.
+
+# UTC - Universal Coordinated Time
+# EST - Eastern Standard Time
+# CET - Central European Time
+# US/Central - American Central Time
+# US/Eastern - American Eastern Time
+server_timezone = "UTC"
+
+# https://docs.vagrantup.com.
+Vagrant.configure("2") do |config|
+ # Operating system
+ config.vm.box = "debian/buster64"
+
+ if Vagrant.has_plugin?("vagrant-hostmanager")
+ config.hostmanager.enabled = true
+ config.hostmanager.manage_host = true
+ config.hostmanager.ignore_private_ip = false
+ config.hostmanager.include_offline = false
+ end
+
+ # Hostname, points to the VM's default vhost.
+ #
+ # Don't forget to include this in the `hosts` file!
+ config.vm.hostname = hostname
+
+ # Static IP
+ if Vagrant.has_plugin?("vagrant-auto_network")
+ config.vm.network :private_network, :ip => "0.0.0.0", :auto_network => true
+ else
+ config.vm.network :private_network, ip: server_ip
+
+ config.vm.network :forwarded_port, guest: 80, host: 8080 # API
+ config.vm.network :forwarded_port, guest: 6650, host: 6650 # Distributor
+ config.vm.network :forwarded_port, guest: 5673, host: 5673 # Hub
+ end
+
+ # Forward agent over SSH
+ config.ssh.forward_agent = true
+
+ # Disable rsync-ing the current directory; it takes too long and the
+ # necessary files are rsync'd in the following command, anyway.
+ # https://github.com/devopsgroup-io/vagrant-digitalocean/issues/255#issuecomment-352228157
+ config.vm.synced_folder ".", "/vagrant", disabled: true
+ # https://stackoverflow.com/a/44352166/14452787
+ config.vm.synced_folder ".", "/home/vagrant/whirl",
+ type: "rsync",
+ rsync__auto: true,
+ rsync__exclude: %w[target/ node_modules/ result]
+
+ # VirtualBox Configuration
+ config.vm.provider :virtualbox do |vb|
+ vb.name = hostname # Hostname
+
+ # CPU core count
+ vb.customize ["modifyvm", :id, "--cpus", server_cpus]
+
+ # RAM amount
+ vb.customize ["modifyvm", :id, "--memory", server_memory]
+
+ # Set the Time-Sync threshold to ten seconds instead of the default twenty
+ # minutes:
+ # if the clock gets more than fifteen minutes out of sync, -- due to your
+ # laptop going to sleep, for instance -- then some third-party services
+ # will reject requests.
+ vb.customize ["guestproperty",
+ "set",
+ :id,
+ "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold",
+ 10000]
+
+ # Prevent VMs running on Ubuntu from losing internet connection
+ # vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
+ # vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
+ end
+
+ # VMWare Fusion Configuration
+ config.vm.provider "vmware_fusion" do |vb, _override|
+ vb.vmx["memsize"] = server_memory # RAM amount
+ end
+
+ # Provisioning
+ # Base packages
+ config.vm.provision "shell",
+ path: "./bin/base.sh", # #{github_url}
+ args: [github_url, server_swap, server_timezone]
+
+ # Optimize base box
+ config.vm.provision "shell",
+ path: "./bin/base_box_optimizations.sh",
+ privileged: true
+
+ # Provision SQLite
+ config.vm.provision "shell", path: "./bin/sqlite.sh"
+end
diff --git a/bin/base.sh b/bin/base.sh
new file mode 100644
index 0000000..7e102e2
--- /dev/null
+++ b/bin/base.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+echo ">>> Setting Timezone & Locale to $3 & en_US.UTF-8"
+sudo ln -sf /usr/share/zoneinfo/$3 /etc/localtime
+sudo apt-get install -qq language-pack-en
+sudo locale-gen en_US
+sudo update-locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8
+
+echo ">>> Installing Base Packages"
+# if [[ -z $1 ]]; then
+# github_url="https://raw.githubusercontent.com/fideloper/Vaprobash/master"
+# else
+# github_url="$1"
+# fi
+
+sudo apt-get update
+
+sudo apt-get install -qq curl unzip git-core ack-grep software-properties-common build-essential cachefilesd
+
+# Setup swap
+# Disable case sensitivity
+shopt -s nocasematch
+
+if [[ -n $2 && ! $2 =~ false && $2 =~ ^[0-9]*$ ]]; then
+ echo ">>> Setting up swap ($2 MB)"
+
+ # Create the swap file
+ fallocate -l "$2M" /swapfile
+
+ # Correct swap permissions
+ chmod 600 /swapfile
+
+ # Setup swap space
+ mkswap /swapfile
+
+ # Enable swap space
+ swapon /swapfile
+
+ # Make swap file permanent
+ echo "/swapfile none swap sw 0 0" | tee -a /etc/fstab
+
+ # Add some swap settings:
+ # vm.swappiness=10: Only activate swap when the amount of RAM left is 10% or less.
+ # vm.vfs_cache_pressure=50: http://rudd-o.com/linux-and-free-software/tales-from-responsivenessland-why-linux-feels-slow-and-how-to-fix-that
+ printf "vm.swappiness=10\nvm.vfs_cache_pressure=50" | tee -a /etc/sysctl.conf && sysctl -p
+fi
+
+# Enable case sensitivity
+shopt -u nocasematch
+
+# Enable cachefilesd
+echo "RUN=yes" > /etc/default/cachefilesd
diff --git a/bin/base_box_optimizations.sh b/bin/base_box_optimizations.sh
new file mode 100644
index 0000000..0d595cb
--- /dev/null
+++ b/bin/base_box_optimizations.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# Exit the script if the executor is not root
+if [[ $EUID -ne 0 ]]; then
+ cat <<END
+you need to run this script as root
+use :privileged => true in Vagrantfile
+END
+
+ exit 0
+fi
+
+# Optimize APT sources for fastest mirror
+perl -pi -e 's@^\s*(deb(\-src)?)\s+http://us.archive.*?\s+@\1 mirror://mirrors.ubuntu.com/mirrors.txt @g' /etc/apt/sources.list
+
+# Update repositories
+apt-get update
diff --git a/bin/sqlite.sh b/bin/sqlite.sh
new file mode 100644
index 0000000..1f596e8
--- /dev/null
+++ b/bin/sqlite.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+echo ">>> Installing SQLite"
+sudo apt-get install -qq sqlite