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

Commit 8c5ce7d

Browse files
author
Leonid Makarov
committed
Merge branch 'release/v0.12.0'
2 parents 98af7b8 + 4b09a85 commit 8c5ce7d

File tree

5 files changed

+148
-65
lines changed

5 files changed

+148
-65
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 0.12.0 (2015-05-07)
4+
5+
- Use our own vagrant box - [blinkreaction/boot2docker](https://vagrantcloud.com/blinkreaction/boxes/boot2docker)
6+
- Updated Docker to v1.6.0
7+
- Updated Docker Compose to v1.2.0
8+
- [SMB2 (experimental)] sync folder option for Windows - complete automation of SMB sharing setup.
9+
- Automatically start containers if docker-compose.yml is present in the Vagrantfile directory (single project mode)
10+
- Miscellaneous code cleanup
11+
312
## 0.11.1 (2015-04-09)
413

514
- Hotfix: added check for empty hosts in vagrant.yml

README.md

+12-21
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ The best balance between performance and convenience can be achieved with NFS on
5656
5757
Additional steps are required to get SMB or rsync to work on Windows. [See below](#synced-folders-win).
5858
59+
In addition to the stock SMB synced folders option this box provides an experimental one: [SMB2](#synced-folders-smb2).
60+
With the **SMB2** option you will receive several "elevated command prompt" prompts which you accept.
61+
No need to enter usernames and passwords unlike the stock SMB option Vagrant ships with.
62+
5963
<a name="synced-folders-mac"></a>
6064
### Mac
6165
@@ -87,6 +91,14 @@ To use the SMB synced folder type:
8791
8892
While using SMB you have to control Vagrant from an elevated (run as admin) Git Bash shell.
8993
94+
<a name="synced-folders-smb2"></a>
95+
**SMB2 (experimental option)**
96+
97+
This is an experimental option.
98+
Compared to **SMB**, **SMB2** does not require running vagrant as admin and does not prompt for username and password.
99+
You will receive several "elevated command prompt" prompts which you accept.
100+
Vagrant will automatically create a user, set correct file permissions, create the SMB share, and mount it.
101+
90102
**Enabling rsync**
91103
92104
rsync is not natively available on Windows.
@@ -100,27 +112,6 @@ To use rsync on Windows:
100112
3. Provide an explicit list of folders to sync in the `vagrant.yml` file (`folders` sequence).
101113
4. Reload the VM: `vagrant reload`
102114
103-
**SMB2 (experimental option)**
104-
105-
This is an experimental option.
106-
Compared to `smb`, `smb2` does not require running vagrant as admin, but requires initial manual setup:
107-
108-
1. Create a Windows user with a password (e.g. `vagrant:<password>`)
109-
2. Share the `<Projects>` directory.
110-
> The share name has to match the directory name.
111-
> E.g. share `C:\Work\Projects` as `Projects`
112-
113-
3. Give the user created in step 1 full access to the share.
114-
4. Update `vagrant.yml`:
115-
> ...
116-
> type: 'smb2'
117-
> ...
118-
> smb_username: '<username>'
119-
> smb_password: '<password>'
120-
> ...
121-
122-
5. Reload the VM (`vagrant reload`)
123-
124115
<a name="vm-settings"></a>
125116
## VirtualBox VM settings
126117

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.1
1+
0.12.0

Vagrantfile

+119-40
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,76 @@
1+
# UI Object for console interactions.
2+
@ui = Vagrant::UI::Colored.new
13

2-
# Determine paths
4+
# Install required plugins if not present.
5+
required_plugins = %w(vagrant-triggers)
6+
required_plugins.each do |plugin|
7+
need_restart = false
8+
unless Vagrant.has_plugin? plugin
9+
system "vagrant plugin install #{plugin}"
10+
need_restart = true
11+
end
12+
exec "vagrant #{ARGV.join(' ')}" if need_restart
13+
end
14+
15+
# Determine paths.
316
vagrant_root = File.dirname(__FILE__) # Vagrantfile location
4-
vagrant_mount = vagrant_root.gsub(/[a-zA-Z]:/, '') # Trim Windows drive letters
5-
vagrant_folder = File.basename(vagrant_root) # Folder name only. Used as the SMB share name
17+
vagrant_mount_point = vagrant_root.gsub(/[a-zA-Z]:/, '') # Trim Windows drive letters.
18+
vagrant_folder_name = File.basename(vagrant_root) # Folder name only. Used as the SMB share name.
619

720
# Use vagrant.yml for local VM configuration overrides.
821
require 'yaml'
922
if !File.exist?(vagrant_root + '/vagrant.yml')
10-
raise 'Configuration file not found! Please copy vagrant.yml.dist to vagrant.yml and try again.'
23+
@ui.error 'Configuration file not found! Please copy vagrant.yml.dist to vagrant.yml and try again.'
24+
exit
1125
end
12-
vconfig = YAML::load_file(vagrant_root + '/vagrant.yml')
26+
$vconfig = YAML::load_file(vagrant_root + '/vagrant.yml')
1327

14-
# Determine if we are on Windows host or not
28+
# Determine if we are on Windows host or not.
1529
is_windows = Vagrant::Util::Platform.windows?
1630
if is_windows
1731
require 'win32ole'
18-
# Determine if Vagrant was launched from the elevated command prompt
32+
# Determine if Vagrant was launched from the elevated command prompt.
1933
running_as_admin = ((`reg query HKU\\S-1-5-19 2>&1` =~ /ERROR/).nil? && is_windows)
20-
21-
# Method to create a network share on Windows using elevated command prompt
22-
def windows_net_share(share, path)
34+
35+
# Run command in an elevated shell.
36+
def windows_elevated_shell(args)
2337
command = 'cmd.exe'
24-
args = "/C net share #{share}=#{path} /grant:everyone,FULL || timeout 5"
25-
puts args
38+
args = "/C #{args} || timeout 10"
2639
shell = WIN32OLE.new('Shell.Application')
2740
shell.ShellExecute(command, args, nil, 'runas')
2841
end
42+
43+
# Method to create the user and SMB network share on Windows.
44+
def windows_net_share(share_name, path)
45+
# Add the vagrant user if it does not exist.
46+
smb_username = $vconfig['synced_folders']['smb_username']
47+
smb_password = $vconfig['synced_folders']['smb_password']
48+
49+
command_user = "net user #{smb_username} || net user #{smb_username} #{smb_password} /add"
50+
@ui.info "Adding vagrant user"
51+
windows_elevated_shell command_user
52+
53+
# Add the SMB share if it does not exist.
54+
command_share = "net share #{share_name} || net share #{share_name}=#{path} /grant:#{smb_username},FULL"
55+
@ui.info "Adding vagrant SMB share"
56+
windows_elevated_shell command_share
57+
58+
# Set folder permissions.
59+
command_permissions = "icacls #{path} /grant #{smb_username}:(OI)(CI)M"
60+
@ui.info "Setting folder permissions"
61+
windows_elevated_shell command_permissions
62+
end
63+
64+
# Method to remove the user and SMB network share on Windows.
65+
def windows_net_share_remove(share_name)
66+
smb_username = $vconfig['synced_folders']['smb_username']
67+
68+
command_user = "net user #{smb_username} /delete || echo 'User #{smb_username} does not exist' && timeout 10"
69+
windows_elevated_shell command_user
70+
71+
command_share = "net share #{share_name} /delete || echo 'Share #{share_name} does not exist' && timeout 10"
72+
windows_elevated_shell command_share
73+
end
2974
else
3075
# Determine if Vagrant was launched with sudo (as root).
3176
running_as_root = (Process.uid == 0)
@@ -34,7 +79,8 @@ end
3479
# Vagrant should NOT be run as root/admin.
3580
if running_as_root
3681
# || running_as_admin
37-
raise "Vagrant should be run as a regular user to avoid issues."
82+
@ui.error "Vagrant should be run as a regular user to avoid issues."
83+
exit
3884
end
3985

4086
######################################################################
@@ -45,63 +91,74 @@ Vagrant.require_version ">= 1.6.3"
4591
Vagrant.configure("2") do |config|
4692
config.vm.define "boot2docker"
4793

48-
config.vm.box = "dduportal/boot2docker"
94+
config.vm.box = "blinkreaction/boot2docker"
95+
config.vm.box_version = "1.6.0"
4996
config.vm.box_check_update = false
5097

5198
## Network ##
5299

53100
# The default box private network IP is 192.168.10.10
54101
# Configure additional IP addresses in vagrant.yml
55-
vconfig['hosts'].each do |host|
102+
$vconfig['hosts'].each do |host|
56103
config.vm.network "private_network", ip: host['ip']
57-
end unless vconfig['hosts'].nil?
104+
end unless $vconfig['hosts'].nil?
58105

59106
####################################################################
60107
## Synced folders configuration ##
61108

62-
synced_folders = vconfig['synced_folders']
109+
synced_folders = $vconfig['synced_folders']
63110
# nfs: better performance on Mac
64111
if synced_folders['type'] == "nfs" && !is_windows
65-
config.vm.synced_folder vagrant_root, vagrant_mount,
112+
config.vm.synced_folder vagrant_root, vagrant_mount_point,
66113
type: "nfs",
67114
mount_options: ["nolock", "vers=3", "tcp"]
68115
config.nfs.map_uid = Process.uid
69116
config.nfs.map_gid = Process.gid
70117
# smb: better performance on Windows. Requires Vagrant to be run with admin privileges.
71118
elsif synced_folders['type'] == "smb" && is_windows
72-
config.vm.synced_folder vagrant_root, vagrant_mount,
119+
config.vm.synced_folder vagrant_root, vagrant_mount_point,
73120
type: "smb",
74121
smb_username: synced_folders['smb_username'],
75122
smb_password: synced_folders['smb_password']
76-
# smb2: experimental, does not require running vagrant as admin, requires initial manual setup.
123+
# smb2: experimental, does not require running vagrant as admin.
77124
elsif synced_folders['type'] == "smb2" && is_windows
78-
# Create the share on the Windows host
79-
#windows_net_share vagrant_share, vagrant_root
80-
#Mount the share in boot2docker
125+
# Create the share before 'up'.
126+
config.trigger.before :up, :stdout => true, :force => true do
127+
info 'Setting up SMB user and share'
128+
windows_net_share vagrant_folder_name, vagrant_root
129+
end
130+
131+
# Remove the share after 'halt'.
132+
config.trigger.after :destroy, :stdout => true, :force => true do
133+
info 'Removing SMB user and share'
134+
windows_net_share_remove vagrant_folder_name
135+
end
136+
137+
# Mount the share in boot2docker.
81138
config.vm.provision "shell", run: "always" do |s|
82139
s.inline = <<-SCRIPT
83140
mkdir -p vagrant $2
84141
mount -t cifs -o uid=`id -u docker`,gid=`id -g docker`,sec=ntlm,username=$3,pass=$4 //192.168.10.1/$1 $2
85142
SCRIPT
86-
s.args = "#{vagrant_folder} #{vagrant_mount} #{vconfig['synced_folders']['smb_username']} #{vconfig['synced_folders']['smb_password']}"
143+
s.args = "#{vagrant_folder_name} #{vagrant_mount_point} #{$vconfig['synced_folders']['smb_username']} #{$vconfig['synced_folders']['smb_password']}"
87144
end
88145
# rsync: the best performance, cross-platform platform, one-way only. Run `vagrant rsync-auto` to start auto sync.
89146
elsif synced_folders['type'] == "rsync"
90147
# Only sync explicitly listed folders.
91148
if (synced_folders['folders']).nil?
92-
puts "WARNING: 'folders' list cannot be empty when using 'rsync' sync type. Please check your vagrant.yml file."
149+
@ui.warn "WARNING: 'folders' list cannot be empty when using 'rsync' sync type. Please check your vagrant.yml file."
93150
else
94151
for synced_folder in synced_folders['folders'] do
95-
config.vm.synced_folder "#{vagrant_root}/#{synced_folder}", "#{vagrant_mount}/#{synced_folder}",
152+
config.vm.synced_folder "#{vagrant_root}/#{synced_folder}", "#{vagrant_mount_point}/#{synced_folder}",
96153
type: "rsync",
97154
rsync__exclude: ".git/",
98155
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--chmod=ugo=rwX"]
99156
end
100157
end
101158
# vboxfs: reliable, cross-platform and terribly slow performance
102159
else
103-
puts "WARNING: defaulting to the slowest sync option (vboxfs)"
104-
config.vm.synced_folder vagrant_root, vagrant_mount
160+
@ui.warn "WARNING: defaulting to the slowest folder sync option (vboxfs)"
161+
config.vm.synced_folder vagrant_root, vagrant_mount_point
105162
end
106163

107164
# Make host SSH keys available to containers on /.ssh
@@ -111,18 +168,18 @@ Vagrant.configure("2") do |config|
111168

112169
######################################################################
113170

114-
## VirtualBox VM settings
171+
## VirtualBox VM settings.
115172

116173
config.vm.provider "virtualbox" do |v|
117-
v.gui = vconfig['v.gui'] # Set to true for debugging. Will unhide VM's primary console screen.
118-
v.name = vagrant_folder + "_boot2docker" # VirtualBox VM name
119-
v.cpus = vconfig['v.cpus'] # CPU settings. VirtualBox works much better with a single CPU.
120-
v.memory = vconfig['v.memory'] # Memory settings.
174+
v.gui = $vconfig['v.gui'] # Set to true for debugging. Will unhide VM's primary console screen.
175+
v.name = vagrant_folder_name + "_boot2docker" # VirtualBox VM name.
176+
v.cpus = $vconfig['v.cpus'] # CPU settings. VirtualBox works much better with a single CPU.
177+
v.memory = $vconfig['v.memory'] # Memory settings.
121178
end
122179

123180
## Provisioning scripts ##
124181

125-
# Allow Mac OS X docker client to connect to Docker without TLS auth
182+
# Allow Mac OS X docker client to connect to Docker without TLS auth.
126183
# https://github.com/deis/deis/issues/2230#issuecomment-72701992
127184
config.vm.provision "shell" do |s|
128185
s.inline = <<-SCRIPT
@@ -135,10 +192,20 @@ Vagrant.configure("2") do |config|
135192
# https://github.com/docker/compose/issues/598#issuecomment-67762456
136193
config.vm.provision "shell", run: "always" do |s|
137194
s.inline = <<-SCRIPT
138-
echo 'docker run --rm -it \
139-
-v $(pwd):$(pwd) -v /var/run/docker.sock:/var/run/docker.sock \
140-
-e COMPOSE_PROJECT_NAME=$(basename $(pwd)) -w="$(pwd)" \
141-
blinkreaction/docker-compose $*' > /usr/local/bin/docker-compose
195+
DC_SCRIPT='
196+
#/bin/sh
197+
198+
# Check if we are in an interactive shell and use "-it" flags if so.
199+
interactive=$([ -t 0 ] && echo "-it")
200+
201+
# Run docker-compose in a container
202+
docker run --rm $interactive \
203+
-v $(pwd):$(pwd) -v /var/run/docker.sock:/var/run/docker.sock \
204+
-e COMPOSE_PROJECT_NAME=$(basename $(pwd)) -w="$(pwd)" \
205+
blinkreaction/docker-compose:1.2.0 $*
206+
'
207+
208+
echo "$DC_SCRIPT" > /usr/local/bin/docker-compose
142209
chmod +x /usr/local/bin/docker-compose
143210
echo 'alias fig=docker-compose' >> /home/docker/.ashrc
144211
SCRIPT
@@ -150,10 +217,10 @@ Vagrant.configure("2") do |config|
150217
echo "export VAGRANT_ROOT=$1" >> /home/docker/.profile
151218
echo "cd $1" >> /home/docker/.ashrc
152219
SCRIPT
153-
s.args = "#{vagrant_mount}"
220+
s.args = "#{vagrant_mount_point}"
154221
end
155222

156-
# dsh script lookup wrapper (Drude Shell)
223+
# dsh script lookup wrapper (Drude Shell).
157224
# https://github.com/blinkreaction/drude
158225
config.vm.provision "shell", run: "always" do |s|
159226
s.inline = <<-SCRIPT
@@ -184,4 +251,16 @@ Vagrant.configure("2") do |config|
184251
SCRIPT
185252
end
186253

254+
# Automatically start containers if docker-compose.yml is present in the current directory.
255+
# See "autostart" property in vagrant.yml.
256+
if File.file?('./docker-compose.yml') && $vconfig['compose_autostart']
257+
config.vm.provision "shell", run: "always", privileged: false do |s|
258+
s.inline = <<-SCRIPT
259+
cd $1
260+
docker-compose up -d
261+
SCRIPT
262+
s.args = "#{vagrant_mount_point}"
263+
end
264+
end
265+
187266
end

vagrant.yml.dist

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
synced_folders:
33
# nfs: better performance on Mac, recommended.
44
# smb: better performance on Windows. Requires Vagrant to be run with admin privileges.
5-
# smb2: experimental, does not require running vagrant as admin, requires initial manual setup.
5+
# smb2: experimental, does not require running vagrant as admin.
66
# rsync: the best performance, cross-platform platform, one-way only. Run `vagrant rsync-auto` to start auto sync.
77
# When using rsync sync type the "folders" list below is mandatory.
88
# vboxfs (or leave empty): best compatibility and ease of setup, but poor performance.
99
type: 'nfs'
1010
# smb_user, smb_password - The username and password used for authentication to mount the SMB mount.
1111
# This is usually your Windows username and password, unless you created a dedicated user for vagrant.
12-
smb_username: ''
13-
smb_password: ''
12+
# If using the 'smb2' type above the user and share will be configured automatically.
13+
smb_username: 'vagrant'
14+
smb_password: 'vagrant'
1415
# List of folders to sync with rsync. These should be subfolder names within the <Projects> folder (e.g. "drupal7")
1516
# Uncomment and add folders per the example below as neccessary.
1617
folders:
@@ -31,3 +32,6 @@ hosts:
3132
#- ip: 192.168.10.11
3233
#- ip: 192.168.10.12
3334
#- ip: 192.168.10.13
35+
36+
# Automatically start containers if docker-compose.yml is present in the current directory (default: false).
37+
compose_autostart: false

0 commit comments

Comments
 (0)