Skip to content
This repository was archived by the owner on Jan 6, 2018. It is now read-only.

Commit 1f36887

Browse files
committed
Add custom Vagrant base box to have faster boots and better overall versioning
1 parent 24b04be commit 1f36887

File tree

5 files changed

+96
-55
lines changed

5 files changed

+96
-55
lines changed

Gruntfile.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var current_version = '0.1.0';
2-
var new_version = '0.2.0';
1+
var current_version = '0.2.0';
2+
var new_version = '0.3.0';
33

44
module.exports = function(grunt) {
55
grunt.loadNpmTasks('grunt-replace');
@@ -43,6 +43,25 @@ module.exports = function(grunt) {
4343
]
4444
}
4545
]
46+
},
47+
task3: {
48+
options: {
49+
patterns: [
50+
{
51+
match: 'VERSION = "' + current_version + '"',
52+
replacement: 'VERSION = "' + new_version + '"'
53+
}
54+
],
55+
usePrefix: false
56+
},
57+
files: [
58+
{
59+
expand: true,
60+
src: [
61+
'Vagrantfile'
62+
]
63+
}
64+
]
4665
}
4766
}
4867
});

VERSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.0

Vagrantfile

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,102 @@
1+
VERSION = "0.3.0"
2+
13
require 'yaml'
24

35
required_plugins = %w(vagrant-vbguest)
6+
47
required_plugins.each do |plugin|
58
system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
69
end
710

811
vm_config = YAML.load_file("config.yml")
912

13+
VAGRANT_COMMAND = ARGV[0]
14+
1015
Vagrant.configure("2") do |config|
11-
config.vm.box = "ubuntu/trusty64"
16+
config.vm.box = "dockerizedrupal/base-ubuntu-trusty"
17+
config.vm.box_version = "0.3.0"
18+
config.vm.box_check_update = false
19+
20+
config.ssh.insert_key = false
21+
22+
if VAGRANT_COMMAND == "ssh"
23+
config.ssh.username = "container"
24+
end
1225

1326
config.vm.network :forwarded_port, guest: 80, host: 80
1427
config.vm.network :forwarded_port, guest: 443, host: 443
1528

16-
config.vm.synced_folder "./", "/var/www"
29+
config.vm.synced_folder ".", "/vagrant", disabled: true
30+
config.vm.synced_folder ".", "/var/www"
31+
1732
config.vm.synced_folder File.expand_path('system32/drivers/', ENV['windir']), "/winhost"
1833

1934
config.vm.provider "virtualbox" do |v|
20-
v.memory = vm_config['memory']
35+
name = "dockerizedrupal-" + VERSION
36+
37+
name.gsub!(".", "-")
38+
39+
v.name = name
2140
v.cpus = vm_config['cpus']
41+
v.memory = vm_config['memory_size']
2242
end
2343

44+
config.vm.provision "shell", inline: "initctl emit vagrant-ready", run: "always"
45+
2446
config.vm.provision "shell" do |s|
2547
s.inline = <<-SHELL
26-
# size of swapfile in megabytes
27-
swapsize=$(($1*2))
48+
MEMORY_SIZE="${1}"
49+
SERVER_NAME="${2}"
2850
29-
# does the swap file already exist?
30-
grep -q "swapfile" /etc/fstab
51+
swap_resize() {
52+
local memory_size=$1
53+
local swap_size=$((${memory_size}*2))
54+
55+
swapoff -a
56+
57+
fallocate -l "${swap_size}m" /swapfile
3158
32-
# if not then create it
33-
if [ $? -ne 0 ]; then
34-
fallocate -l ${swapsize}m /swapfile
3559
chmod 600 /swapfile
60+
3661
mkswap /swapfile
3762
swapon /swapfile
38-
fi
39-
40-
sudo apt-get update
41-
sudo apt-get upgrade -y
42-
43-
wget -qO- https://get.docker.com/ | sh
44-
45-
# make docker start on vagrant-ready upstart event
46-
sudo sed -i "s/^start on (local-filesystems and net-device-up IFACE!=lo)/start on vagrant-ready/" /etc/init/docker.conf
47-
48-
sudo usermod -aG docker vagrant
49-
50-
sudo curl -L https://github.com/docker/compose/releases/download/1.5.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose \
51-
&& sudo chmod +x /usr/local/bin/docker-compose
52-
53-
tmp="$(mktemp -d)" \
54-
&& git clone https://github.com/dockerizedrupal/drupal-compose.git "${tmp}" \
55-
&& cd "${tmp}" \
56-
&& git checkout 1.1.5 \
57-
&& sudo cp "${tmp}/drupal-compose.sh" /usr/local/bin/drupal-compose \
58-
&& sudo chmod +x /usr/local/bin/drupal-compose \
59-
&& cd -
60-
61-
tmp="$(mktemp -d)" \
62-
&& git clone https://github.com/dockerizedrupal/crush.git "${tmp}" \
63-
&& cd "${tmp}" \
64-
&& git checkout 1.1.0 \
65-
&& sudo cp "${tmp}/crush.sh" /usr/local/bin/crush \
66-
&& sudo chmod +x /usr/local/bin/crush \
67-
&& sudo ln -s /usr/local/bin/crush /usr/local/bin/drush \
68-
&& cd -
69-
70-
sudo curl -L https://raw.githubusercontent.com/dockerizedrupal/vhost/master/docker-compose.yml > /opt/vhost.yml
71-
sudo sed -i "s/SERVER_NAME=localhost/SERVER_NAME=${2}/" /opt/vhost.yml
72-
sudo sed -i "s|/etc/hosts|/winhost/etc/hosts|" /opt/vhost.yml
73-
74-
sudo docker-compose -f /opt/vhost.yml up -d
63+
64+
sysctl vm.swappiness=10
65+
sysctl vm.vfs_cache_pressure=50
66+
}
67+
68+
user_reconfigure() {
69+
cp -ar /home/vagrant/.ssh /home/container
70+
71+
chown -R container.container /home/container/.ssh
72+
}
73+
74+
vhost_run() {
75+
local server_name="${1}"
76+
local tmp="$(mktemp -d)"
77+
78+
git clone https://github.com/dockerizedrupal/vhost.git "${tmp}"
79+
80+
cd "${tmp}"
81+
82+
git checkout 1.1.6
83+
84+
cp ./docker-compose.yml /opt/vhost.yml
85+
86+
sed -i "s/SERVER_NAME=localhost/SERVER_NAME=${server_name}/" /opt/vhost.yml
87+
sed -i "s|/etc/hosts|/winhost/etc/hosts|" /opt/vhost.yml
88+
89+
docker-compose -f /opt/vhost.yml up -d
90+
}
91+
92+
swap_resize "${MEMORY_SIZE}"
93+
user_reconfigure
94+
vhost_run "${SERVER_NAME}"
7595
SHELL
76-
s.args = [vm_config['memory'],vm_config['server_name']]
77-
end
7896

79-
config.vm.provision :shell, inline: "initctl emit vagrant-ready", run: "always"
97+
s.args = [
98+
vm_config['memory_size'],
99+
vm_config['server_name'],
100+
]
101+
end
80102
end

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
server_name: 'dev'
22
cpus: 2
3-
memory: 2048
3+
memory_size: 2048

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vagrant-dockerizedrupal",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"dependencies": {
55
"grunt": "^0.4.5",
66
"grunt-replace": "^0.11.0"

0 commit comments

Comments
 (0)