forked from oriuminc/vagrant-ariadne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
145 lines (128 loc) · 4.36 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class String
# Strip leading whitespace from each line that is the same as the
# amount of whitespace on the first line of the string.
# Leaves _additional_ indentation on later lines intact.
# SEE: http://stackoverflow.com/a/5638187/504018
def unindent
gsub /^#{self[/\A\s*/]}/, ''
end
end
desc "Prepare Ariadne environmnet to spin up a project.
This runs librarian-chef to install cookbooks, and creates several empty
directories required for sharing with the VM."
task :setup do
# Write the config file if doesn't exist.
unless File.exists?("roles/config.yml")
p "Creating roles/config.yml..."
conf = File.open("roles/config.yml", "w")
conf.puts <<-EOF.unindent
---
basebox: lucid64
project: example
# host_name default to PROJECT.dev (from above) if none given.
host_name:
branch: develop
memory: 1000
cpu_count: 2
roles: acquia,dev_tools
# If building an install profile according to Myplanet layout assumptions,
# enter its repository URL here. (Otherwise, leave blank.)
repo_url: ''
EOF
conf.close
end
p "Creating required directories:"
rel_dirs = %w{
tmp/apt/cache/partial
tmp/drush/cache
data/html
data/make
data/profiles
cookbooks-projects
}
rel_dirs.each do |rel_dir|
p rel_dir
abs_dir = File.join(Dir::pwd, rel_dir)
FileUtils.mkdir_p abs_dir
end
end
desc "Import an Ariadne project from an external git repo.
If the repo name is prefixed with 'ariadne-', this will be stripped before
cloning to `cookbooks-projects`."
task :init_project, [:repo] do |t, args|
repository_name = args.repo.sub(/\.git$/, '').split(/([\w-]+)?$/)[-1]
project_name = repository_name.sub(/^ariadne-/, '')
system "git clone #{args.repo} cookbooks-projects/#{project_name}"
end
desc "Restarts the network service inside the VM.
This often needs to be run when you've changes wifi hotspots or have been
disconnected temporily. If the VM is taking a long to time provision, or timing
out, run this task."
task :fix_network do
require 'vagrant'
env = Vagrant::Environment.new
env.vms.each do |id, vm|
raise Vagrant::Errors::VMNotCreatedError if !vm.created?
raise Vagrant::Errors::VMNotRunningError if vm.state != :running
vm.channel.sudo("/etc/init.d/networking restart")
end
end
desc "Transfers your user-specific .gitconfig to the VM.
While this will transfer lots of personal settings into the VM, it perhaps most
importantly ensures that your commits are tied to your name and email. This
will ensure that your commits are properly linked your GitHub account."
task :send_gitconfig do
require 'vagrant'
env = Vagrant::Environment.new
env.vms.each do |id, vm|
raise Vagrant::Errors::VMNotCreatedError if !vm.created?
raise Vagrant::Errors::VMNotRunningError if vm.state != :running
ssh_info = vm.ssh.info
ssh_host = ssh_info[:host]
ssh_port = ssh_info[:port]
ssh_user = ssh_info[:username]
private_key_path = ssh_info[:private_key_path]
system "scp -i #{private_key_path} -P #{ssh_port} ~/.gitconfig #{ssh_user}@#{ssh_host}:~"
raise "Could not find .gitconfig in home directory (~)." if $? != 0
puts ".gitconfig sent to #{vm.name} VM!"
end
end
desc "WARNING! Will bring Ariadne back to a pristine state, good-as-new.
This will:
* destroy the VM
* delete cookbooks, gems, apt packages & project-specific datas
* remove ariadne ruby version and source"
task :fresh_start do
system "vagrant destroy --force"
system "rm -rf tmp/ cookbooks/ .bundle/"
system "chmod -R u+w data/html/; rm -rf data/html data/make cookbooks-projects/*;"
system "rvm remove 1.9.3-p194-ariadne"
end
namespace :test do
desc "Runs foodcritic linter"
task :foodcritic do
if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup)
cmd = %w{
bundle exec foodcritic cookbooks*/*
--include test/support/foodcritic/*
--epic-fail any
--tags ~CINK001
--tags ~FC011
--tags ~FC031
}
sh cmd.join(" ")
else
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
end
end
desc "Runs knife cookbook test"
task :knife do
cmd = %w{
bundle exec knife cookbook test
$(ls -m cookbooks-override | tr -d ',')
$(ls -m cookbooks-projects | tr -d ',')
--config=test/support/knife.rb
}
sh cmd.join(" ")
end
end