linux_provision 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.linux_provision.json +3 -3
- data/CHANGES +4 -0
- data/Gemfile +8 -5
- data/Gemfile.lock +57 -9
- data/README.md +129 -35
- data/Vagrantfile +1 -1
- data/demo/.ruby-gemset +1 -0
- data/demo/.ruby-version +1 -0
- data/demo/Dockerfile +107 -0
- data/demo/Gemfile +7 -0
- data/demo/Gemfile.lock +45 -0
- data/demo/Rakefile +7 -0
- data/demo/app.rb +29 -0
- data/demo/bin/start-server.sh +7 -0
- data/demo/config.ru +3 -0
- data/demo/db/migrate/20140610203958_create_notes.rb +14 -0
- data/demo/db/migrate/20140610204302_add_notes.rb +7 -0
- data/demo/db/schema.rb +26 -0
- data/demo/db_setup.rb +11 -0
- data/demo/note.rb +2 -0
- data/demo/supervisord.conf +8 -0
- data/demo/views/index.erb +10 -0
- data/demo/views/layout.erb +8 -0
- data/demo/views/new.erb +12 -0
- data/demo/views/note.erb +3 -0
- data/docker/postgres/Dockerfile +61 -0
- data/docker/postgres/bin/create_db.sh +14 -0
- data/docker/sshd/Dockerfile +28 -0
- data/docker/supervisord/Dockerfile +28 -0
- data/docker/supervisord/supervisord.conf +8 -0
- data/lib/linux_provision/generic_provision.rb +28 -19
- data/lib/linux_provision/linux_provision.rb +7 -165
- data/lib/linux_provision/linux_provision_scripts.sh +65 -21
- data/lib/linux_provision/version.rb +1 -1
- data/presentation/virtualization/01-vagrant/slides.md +381 -0
- data/presentation/virtualization/02-provision/slides.md +400 -0
- data/presentation/virtualization/03-docker/slides.md +208 -0
- data/presentation/virtualization/04-conclusion/slides.md +36 -0
- data/presentation/virtualization/default.css +59 -0
- data/presentation/virtualization/default.tpl +2 -0
- data/presentation/virtualization/images/chef.jpg +0 -0
- data/presentation/virtualization/images/provisioning.jpg +0 -0
- data/presentation/virtualization/images/vagrant.jpg +0 -0
- data/presentation/virtualization/showoff.json +23 -0
- data/presentation/virtualization/simple.tpl +2 -0
- data/spec/linux_install_spec.rb +9 -2
- data/spec/linux_provision_spec.rb +1 -1
- data/stats/viewstats.json +1 -0
- data/thor/demo_scripts.sh +34 -0
- data/thor/docker.thor +31 -0
- data/thor/linux_install.thor +17 -115
- metadata +40 -2
@@ -4,7 +4,7 @@ class LinuxProvision < GenericProvision
|
|
4
4
|
|
5
5
|
USER_LOCAL_BIN = "/usr/local/bin"
|
6
6
|
|
7
|
-
def initialize config_file_name=".linux_provision.json", scripts_file_names=[]
|
7
|
+
def initialize parent_class, config_file_name=".linux_provision.json", scripts_file_names=[]
|
8
8
|
scripts_file_names.unshift(File.expand_path("linux_provision_scripts.sh", File.dirname(__FILE__))) # make it first
|
9
9
|
|
10
10
|
super
|
@@ -16,174 +16,16 @@ class LinuxProvision < GenericProvision
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def postgres_drop_schemas
|
20
|
+
env[:postgres][:app_schemas].each do |schema|
|
21
|
+
run(server_info, "postgres_drop_schema", env.merge(schema: schema))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
19
25
|
def mysql_create_schemas
|
20
26
|
env[:mysql][:app_schemas].each do |schema|
|
21
27
|
run(server_info, "mysql_create_schema", env.merge(schema: schema))
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
|
-
def create_postgres_user app_user, schema
|
26
|
-
run("create_postgres_user", binding)
|
27
|
-
end
|
28
|
-
|
29
|
-
# execute(server_info) { "/usr/local/bin/dropuser #{app_user}" }
|
30
|
-
# execute(server_info) { "/usr/local/bin/dropdb #{schema}" }
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def method_missing(method, *args, &block)
|
35
|
-
run(server_info, method.to_s, env)
|
36
|
-
end
|
37
|
-
|
38
|
-
# def test
|
39
|
-
# run(server_info, "test", env)
|
40
|
-
# end
|
41
|
-
|
42
|
-
# def prepare
|
43
|
-
# env['password'] = ask_password("Enter password for #{env[:node][:user]}: ")
|
44
|
-
#
|
45
|
-
# run(server_info.merge(capture_output: false), "prepare", env)
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# def rvm_install
|
49
|
-
# installed = package_installed '#{ENV[\'HOME\']}/.rvm/bin/rvm'
|
50
|
-
#
|
51
|
-
# if installed
|
52
|
-
# puts "rvm already installed."
|
53
|
-
# else
|
54
|
-
# run(server_info, "rvm", env)
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# def npm_install
|
59
|
-
# installed = package_installed "#{USER_LOCAL_BIN}/npm"
|
60
|
-
#
|
61
|
-
# if installed
|
62
|
-
# puts "npm already installed."
|
63
|
-
# else
|
64
|
-
# run(server_info, "npm", env)
|
65
|
-
# end
|
66
|
-
# end
|
67
|
-
|
68
|
-
# def qt_install
|
69
|
-
# installed = package_installed "#{USER_LOCAL_BIN}/qmake"
|
70
|
-
#
|
71
|
-
# if installed
|
72
|
-
# puts "qt already installed."
|
73
|
-
# else
|
74
|
-
# run(server_info, "qt", env)
|
75
|
-
# end
|
76
|
-
# end
|
77
|
-
#
|
78
|
-
# def mysql_install
|
79
|
-
# installed = package_installed "#{USER_LOCAL_BIN}/mysql"
|
80
|
-
#
|
81
|
-
# if installed
|
82
|
-
# puts "mysql already installed."
|
83
|
-
# else
|
84
|
-
# run(server_info, "mysql", env)
|
85
|
-
# end
|
86
|
-
# end
|
87
|
-
#
|
88
|
-
# def mysql_restart
|
89
|
-
# started = service_started("homebrew.mxcl.mysql")
|
90
|
-
#
|
91
|
-
# run(server_info, "mysql_restart", env.merge({started: started}))
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# def postgres_install
|
95
|
-
# installed = package_installed "#{USER_LOCAL_BIN}/postgres"
|
96
|
-
#
|
97
|
-
# if installed
|
98
|
-
# puts "postgres already installed."
|
99
|
-
# else
|
100
|
-
# run(server_info, "postgres", env)
|
101
|
-
# end
|
102
|
-
# end
|
103
|
-
#
|
104
|
-
# def postgres_restart
|
105
|
-
# started = service_started("homebrew.mxcl.postgres")
|
106
|
-
#
|
107
|
-
# run(server_info, "postgres_restart", env.merge({started: started}))
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# def postgres_stop
|
111
|
-
# run server_info, "postgres_stop", env
|
112
|
-
# end
|
113
|
-
#
|
114
|
-
# def postgres_start
|
115
|
-
# run server_info, "postgres_start", env
|
116
|
-
# end
|
117
|
-
#
|
118
|
-
# def ruby_install
|
119
|
-
# installed = package_installed "#{ENV['HOME']}/.rvm/rubies/ruby-1.9.3-p429/bin/ruby"
|
120
|
-
#
|
121
|
-
# if installed
|
122
|
-
# puts "ruby already installed."
|
123
|
-
# else
|
124
|
-
# run(server_info, "ruby", env)
|
125
|
-
# end
|
126
|
-
# end
|
127
|
-
#
|
128
|
-
# def jenkins_install
|
129
|
-
# installed = package_installed "/usr/local/opt/jenkins/libexec/jenkins.war"
|
130
|
-
#
|
131
|
-
# if installed
|
132
|
-
# puts "jenkins already installed."
|
133
|
-
# else
|
134
|
-
# run(server_info, "jenkins", env)
|
135
|
-
# end
|
136
|
-
# end
|
137
|
-
#
|
138
|
-
# def jenkins_restart
|
139
|
-
# started = service_started("homebrew.mxcl.jenkins")
|
140
|
-
#
|
141
|
-
# run(server_info, "jenkins_restart", env.merge({started: started}))
|
142
|
-
# end
|
143
|
-
#
|
144
|
-
# def selenium_install
|
145
|
-
# installed = package_installed "/usr/local/opt/selenium-server-standalone/selenium-server-standalone*.jar"
|
146
|
-
#
|
147
|
-
# if installed
|
148
|
-
# puts "selenium already installed."
|
149
|
-
# else
|
150
|
-
# run(server_info, "selenium", env)
|
151
|
-
# end
|
152
|
-
# end
|
153
|
-
#
|
154
|
-
# def selenium_restart
|
155
|
-
# started = service_started("homebrew.mxcl.selenium-server-standalone")
|
156
|
-
#
|
157
|
-
# run(server_info, "selenium_restart", env.merge({started: started}))
|
158
|
-
# end
|
159
|
-
#
|
160
|
-
# def postgres_create user, schemas
|
161
|
-
# create_postgres_user user, schemas.first
|
162
|
-
#
|
163
|
-
# schemas.each do |schema|
|
164
|
-
# create_postgres_schema user, schema
|
165
|
-
# end
|
166
|
-
# end
|
167
|
-
#
|
168
|
-
# def postgres_drop user, schemas
|
169
|
-
# schemas.each do |schema|
|
170
|
-
# drop_postgres_schema schema
|
171
|
-
# end
|
172
|
-
#
|
173
|
-
# drop_postgres_user user, schemas.first
|
174
|
-
# end
|
175
|
-
#
|
176
|
-
# def postgres_test schema
|
177
|
-
# result = get_postgres_schemas schema
|
178
|
-
#
|
179
|
-
# puts result
|
180
|
-
# end
|
181
|
-
#
|
182
|
-
# def package_installed package_path
|
183
|
-
# result = run server_info.merge(:suppress_output => true, :capture_output => true),
|
184
|
-
# "package_installed", env.merge({package_path: package_path})
|
185
|
-
#
|
186
|
-
# result.chomp == package_path
|
187
|
-
# end
|
188
|
-
|
189
31
|
end
|
@@ -8,29 +8,28 @@ echo "test"
|
|
8
8
|
|
9
9
|
##############################
|
10
10
|
[prepare]
|
11
|
+
# Updates linux core packages
|
11
12
|
|
12
13
|
sudo apt-get update
|
13
14
|
|
14
15
|
sudo apt-get install -y curl
|
15
16
|
sudo apt-get install -y g++
|
16
17
|
sudo apt-get install -y subversion
|
18
|
+
sudo apt-get install -y git
|
17
19
|
|
18
20
|
|
19
21
|
##############################
|
20
22
|
[rvm]
|
21
|
-
#
|
22
|
-
|
23
|
-
USER_HOME="#{node.home}"
|
23
|
+
# Installs rvm
|
24
24
|
|
25
25
|
curl -L https://get.rvm.io | bash
|
26
26
|
|
27
27
|
sudo chown -R vagrant /opt/vagrant_ruby
|
28
28
|
|
29
|
-
source $USER_HOME/.rvm/scripts/rvm
|
30
|
-
|
31
29
|
|
32
30
|
##############################
|
33
31
|
[ruby]
|
32
|
+
# Installs ruby
|
34
33
|
|
35
34
|
USER_HOME="#{node.home}"
|
36
35
|
|
@@ -39,25 +38,23 @@ source $USER_HOME/.rvm/scripts/rvm
|
|
39
38
|
rvm install ruby-1.9.3
|
40
39
|
|
41
40
|
|
42
|
-
##############################
|
43
|
-
[git]
|
44
|
-
|
45
|
-
sudo apt-get install -y git
|
46
|
-
|
47
|
-
|
48
41
|
##############################
|
49
42
|
[node]
|
43
|
+
# Installs node
|
50
44
|
|
51
45
|
sudo apt-get install -y node
|
52
46
|
|
53
47
|
|
54
48
|
##############################
|
55
49
|
[jenkins]
|
50
|
+
# Installs jenkins
|
51
|
+
|
56
52
|
sudo apt-get install -y jenkins
|
57
53
|
|
58
54
|
|
59
55
|
##############################
|
60
56
|
[postgres]
|
57
|
+
# Installs postgres server
|
61
58
|
|
62
59
|
sudo apt-get install -y postgresql-client
|
63
60
|
sudo apt-get install -y libpq-dev
|
@@ -66,6 +63,7 @@ sudo apt-get install -y postgresql
|
|
66
63
|
|
67
64
|
##############################
|
68
65
|
[mysql]
|
66
|
+
# Installs mysql server
|
69
67
|
|
70
68
|
MYSQL_PASSWORD='#{mysql.password}'
|
71
69
|
|
@@ -88,13 +86,20 @@ sudo apt-get -y install mysql-server
|
|
88
86
|
PATH=$PATH:/usr/local/bin
|
89
87
|
|
90
88
|
APP_USER='#{postgres.app_user}'
|
89
|
+
APP_PASSWORD='#{postgres.app_password}'
|
91
90
|
|
92
91
|
sudo -u postgres psql -c "CREATE USER $APP_USER WITH PASSWORD '$APP_USER'"
|
93
|
-
#createuser -s -d -r $APP_USER
|
94
92
|
|
95
93
|
##############################
|
96
94
|
[postgres_drop_user]
|
97
95
|
|
96
|
+
PATH=$PATH:/usr/local/bin
|
97
|
+
|
98
|
+
APP_USER='#{postgres.app_user}'
|
99
|
+
|
100
|
+
sudo -u postgres psql -c "DROP USER $APP_USER"
|
101
|
+
|
102
|
+
|
98
103
|
##############################
|
99
104
|
[postgres_create_schema]
|
100
105
|
|
@@ -113,6 +118,12 @@ sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $SCHEMA to $APP_USER"
|
|
113
118
|
##############################
|
114
119
|
[postgres_drop_schema]
|
115
120
|
|
121
|
+
PATH=$PATH:/usr/local/bin
|
122
|
+
|
123
|
+
SCHEMA='#{schema}'
|
124
|
+
|
125
|
+
sudo -u postgres psql -c "DROP DATABASE $SCHEMA"
|
126
|
+
|
116
127
|
|
117
128
|
##############################
|
118
129
|
[mysql_create_user]
|
@@ -158,19 +169,52 @@ mysql -h $HOST_NAME -u $MYSQL_USER -p"$MYSQL_PASSWORD" -e "create database $SCHE
|
|
158
169
|
|
159
170
|
|
160
171
|
##############################
|
161
|
-
|
172
|
+
# http://www.labelmedia.co.uk/blog/setting-up-selenium-server-on-a-headless-jenkins-ci-build-machine.html
|
173
|
+
[selenium]
|
174
|
+
# Installs selenium server
|
162
175
|
|
163
|
-
|
176
|
+
wget http://selenium-release.storage.googleapis.com/2.42/selenium-server-standalone-2.42.2.jar
|
164
177
|
|
165
|
-
|
178
|
+
sudo mkdir /var/lib/selenium
|
166
179
|
|
167
|
-
|
180
|
+
sudo mv selenium-server-standalone-2.42.2.jar /var/lib/selenium
|
168
181
|
|
169
|
-
|
182
|
+
cd /var/lib/selenium
|
183
|
+
|
184
|
+
sudo ln -s selenium-server-standalone-2.42.2.jar selenium-server.jar
|
185
|
+
|
186
|
+
sudo apt-get install -y xvfb
|
187
|
+
sudo update-rc.d xvfb defaults 10
|
188
|
+
|
189
|
+
sudo apt-get install -y firefox
|
190
|
+
|
191
|
+
# export DISPLAY=":99" && java -jar /var/lib/selenium/selenium-server.jar
|
192
|
+
|
193
|
+
|
194
|
+
##############################
|
195
|
+
[selenium2]
|
196
|
+
cat > xvfb <<END
|
197
|
+
#!/bin/bash
|
198
|
+
|
199
|
+
if [ -z "$1" ]; then
|
200
|
+
echo "`basename $0` {start|stop}"
|
201
|
+
exit
|
202
|
+
fi
|
203
|
+
|
204
|
+
case "$1" in
|
205
|
+
start)
|
206
|
+
/usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 &
|
207
|
+
;;
|
208
|
+
|
209
|
+
stop)
|
210
|
+
killall Xvfb
|
211
|
+
;;
|
212
|
+
esac
|
213
|
+
END
|
214
|
+
|
215
|
+
#sudo mv xvfb /etc/init.d/xvfb
|
170
216
|
|
171
|
-
|
217
|
+
#sudo chmod 755 /etc/init.d/xvfb
|
172
218
|
|
173
|
-
|
219
|
+
/etc/init.d/xvfb start
|
174
220
|
|
175
|
-
# rake db:migrate
|
176
|
-
# rails s
|
@@ -0,0 +1,381 @@
|
|
1
|
+
!SLIDE
|
2
|
+
|
3
|
+
# Boosting developer's productivity: Using Vagrant and Chef
|
4
|
+
|
5
|
+
* Author: **Alexander Shvets**
|
6
|
+
* Year: **2014**
|
7
|
+
|
8
|
+
|
9
|
+
!SLIDE title-and-content transition=fade incremental
|
10
|
+
.notes notes for my slide
|
11
|
+
|
12
|
+
# Why do we need virtualization in development?
|
13
|
+
|
14
|
+
* We want to have **same environment for all developers**, no matter on what platform they are working now.
|
15
|
+
|
16
|
+
* We are **working on multiple projects** on same workstation. As a result, suddenly your computer has "hidden",
|
17
|
+
hard-to-discover inter-project dependencies or different versions of same library.
|
18
|
+
|
19
|
+
* To overcome **It "works on my machine!"** syndrome - development environment is different from production environment.
|
20
|
+
|
21
|
+
* Sometimes required software is **not available** on developer's platform. Example: 64-bit instant client for oracle
|
22
|
+
was broken for almost two years on OS/X >= 10.7.
|
23
|
+
|
24
|
+
* **Development for PAAS**, such as Heroku, Engine Yard etc. You can find/build virtualization that is pretty close to
|
25
|
+
your platform.
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
!SLIDE content transition=cover
|
30
|
+
|
31
|
+
# Vagrant
|
32
|
+
|
33
|
+
>
|
34
|
+
|
35
|
+

|
36
|
+
|
37
|
+
!SLIDE title-and-content transition=cover
|
38
|
+
|
39
|
+
# What is it?
|
40
|
+
|
41
|
+
* It is ruby gem.
|
42
|
+
* it helps to provide easy to configure, reproducible, and portable work environments.
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
!SLIDE title-and-content transition=cover
|
47
|
+
|
48
|
+
# Installation
|
49
|
+
|
50
|
+
* Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads). Download it from dedicated web site and install
|
51
|
+
it as native program. You can use it in UI mode, but it's not required.
|
52
|
+
|
53
|
+
* Install [Vagrant](http://www.vagrantup.com) gem:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
$ gem install vagrant
|
57
|
+
```
|
58
|
+
|
59
|
+
* or put it into **Gemfile**:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
gem "vagrant"
|
63
|
+
```
|
64
|
+
|
65
|
+
* Run bundler:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
bundle install
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
!SLIDE title-and-content transition=cover
|
74
|
+
|
75
|
+
# Playing with vagrant
|
76
|
+
|
77
|
+
* Install linux image
|
78
|
+
|
79
|
+
```bash
|
80
|
+
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
|
81
|
+
```
|
82
|
+
|
83
|
+
* Initialize
|
84
|
+
|
85
|
+
```bash
|
86
|
+
$ vagrant init precise64
|
87
|
+
```
|
88
|
+
|
89
|
+
* Run or reload
|
90
|
+
|
91
|
+
```bash
|
92
|
+
$ vagrant up
|
93
|
+
$ vagrant reload
|
94
|
+
$ vagrant provision
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
!SLIDE title-and-content transition=cover
|
100
|
+
|
101
|
+
# Playing with vagrant (continued)
|
102
|
+
|
103
|
+
* Suspend/destroy:
|
104
|
+
|
105
|
+
```bash
|
106
|
+
$ vagrant suspend
|
107
|
+
$ vagrant destroy
|
108
|
+
```
|
109
|
+
|
110
|
+
* or remove linux image
|
111
|
+
|
112
|
+
```bash
|
113
|
+
$ vagrant box remove precise64
|
114
|
+
```
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
!SLIDE title-and-content transition=cover
|
119
|
+
|
120
|
+
# Access VM
|
121
|
+
|
122
|
+
```bash
|
123
|
+
$ vagrant ssh
|
124
|
+
```
|
125
|
+
|
126
|
+
```bash
|
127
|
+
vagrant> ls /vagrant
|
128
|
+
```
|
129
|
+
|
130
|
+
* You will see all project's files
|
131
|
+
|
132
|
+
```bash
|
133
|
+
drwxr-xr-x 48 alex staff 1.6K Apr 21 15:29 ./
|
134
|
+
drwxrwxrwx 24 alex staff 816B Apr 21 15:31 ../
|
135
|
+
-rw-rw-rw- 1 alex staff 101B Apr 19 10:11 Berksfile
|
136
|
+
-rw-rw-rw- 1 alex staff 512B Apr 19 09:57 Berksfile.lock
|
137
|
+
-rw-rw-rw- 1 alex staff 188B Apr 17 11:40 Cheffile
|
138
|
+
-rw-rw-rw- 1 alex staff 715B Apr 16 11:39 Cheffile.lock
|
139
|
+
-rw-rw-rw- 1 alex staff 4.4K Apr 21 14:20 Gemfile
|
140
|
+
-rw-r--r-- 1 alex staff 9.7K Apr 21 14:20 Gemfile.lock
|
141
|
+
-rw-r--r-- 1 alex staff 106B Mar 23 13:14 Procfile
|
142
|
+
-rw-r--r-- 1 alex staff 297B Mar 23 13:14 README.md
|
143
|
+
-rw-r--r-- 1 alex staff 5.8K Apr 20 11:54 Rakefile
|
144
|
+
-rw-rw-rw- 1 alex staff 5.1K Apr 17 15:19 Vagrantfile
|
145
|
+
drwxr-xr-x 9 alex staff 306B Mar 24 13:37 app/
|
146
|
+
-rwxrwxrwx@ 1 alex staff 3.1K Apr 18 09:56 bootstrap.sh*
|
147
|
+
drwxr-xr-x 8 alex staff 272B Apr 20 07:54 public/
|
148
|
+
```
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
!SLIDE title-and-content transition=cover incremental
|
153
|
+
|
154
|
+
# Available provisioners for Vagrant
|
155
|
+
|
156
|
+
* Shell
|
157
|
+
* Chef Server
|
158
|
+
* Chef Solo
|
159
|
+
* Puppet Server/Standalone
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
!SLIDE title-and-content transition=cover
|
164
|
+
|
165
|
+
|
166
|
+
# Example 1
|
167
|
+
|
168
|
+
* **Vagrantfile** with **bash** shell provisioning:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
Vagrant::Config.run do |config|
|
172
|
+
config.vm.box = "precise64"
|
173
|
+
|
174
|
+
config.vm.network :hostonly, "22.22.22.22"
|
175
|
+
|
176
|
+
config.vm.provision :shell, :path => "bootstrap.sh"
|
177
|
+
end
|
178
|
+
```
|
179
|
+
|
180
|
+
!SLIDE title-and-content transition=cover
|
181
|
+
|
182
|
+
# Example 2
|
183
|
+
|
184
|
+
* **Vagrantfile** with **chef** provisioning
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
Vagrant::Config.run do |config|
|
188
|
+
config.vm.box = "precise64"
|
189
|
+
config.vm.network :hostonly, "22.22.22.22"
|
190
|
+
|
191
|
+
config.vm.provision :chef_solo do |chef|
|
192
|
+
chef.cookbooks_path = ["vendored_cookbooks", "cookbooks"]
|
193
|
+
|
194
|
+
chef.add_recipe 'application'
|
195
|
+
|
196
|
+
chef.json.merge!({
|
197
|
+
application: {app_name: "triton"},
|
198
|
+
|
199
|
+
rvm: {ruby: {version: '1.9.3', implementation: 'ruby',
|
200
|
+
patch_level: 'p392'}},
|
201
|
+
postgresql: { username: "postgres", password: "postgres"},
|
202
|
+
mysql: { server_debian_password: "root",
|
203
|
+
server_root_password: "root",
|
204
|
+
server_repl_password: "root"}
|
205
|
+
})
|
206
|
+
end
|
207
|
+
end
|
208
|
+
```
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
!SLIDE title-and-content transition=cover
|
213
|
+
|
214
|
+
# Example 3
|
215
|
+
|
216
|
+
* **Vagrantfile** with multiple environments:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
Vagrant::Config.run do |config|
|
220
|
+
config.vm.define :node1 do |node_config|
|
221
|
+
node_config.vm.box = "lucid32"
|
222
|
+
end
|
223
|
+
config.vm.define :node2 do |node_config|
|
224
|
+
node_config.vm.box = "precise32"
|
225
|
+
end
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
* Start first node in one tab:
|
230
|
+
|
231
|
+
```bash
|
232
|
+
vagrant up node1
|
233
|
+
vagrant ssh node1
|
234
|
+
```
|
235
|
+
|
236
|
+
* and second node in another tab:
|
237
|
+
|
238
|
+
```bash
|
239
|
+
vagrant up node2
|
240
|
+
vagrant ssh node2
|
241
|
+
```
|
242
|
+
|
243
|
+
|
244
|
+
!SLIDE title-and-content transition=cover
|
245
|
+
|
246
|
+
# Packaging
|
247
|
+
|
248
|
+
* You can create new package based on your vagrant setup.
|
249
|
+
|
250
|
+
* This new package can be used by other developers for faster installation.
|
251
|
+
|
252
|
+
* It will have already preinstalled and configured ruby/rvm/mysql/postgres etc.:
|
253
|
+
|
254
|
+
```bash
|
255
|
+
vagrant package --vagrantfile Vagrantfile --output proteus.box
|
256
|
+
```
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
!SLIDE title-and-content transition=cover
|
261
|
+
|
262
|
+
# What's next?
|
263
|
+
|
264
|
+
* Once you install Vagrant with some provision (script, chef-solo or puppet), you can use it in same way as your worksation:
|
265
|
+
|
266
|
+
```bash
|
267
|
+
vagrant ssh
|
268
|
+
|
269
|
+
cd /vagrant
|
270
|
+
|
271
|
+
rake db:dev:reset
|
272
|
+
|
273
|
+
rspec
|
274
|
+
|
275
|
+
ASSET_HOST=http://22.22.22.22:3000 rails s
|
276
|
+
```
|
277
|
+
|
278
|
+
* and then access it from the browser within [host computer](http://22.22.22.22:3000/triton):
|
279
|
+
|
280
|
+
```
|
281
|
+
open http://22.22.22.22:3000/triton
|
282
|
+
```
|
283
|
+
|
284
|
+
|
285
|
+
!SLIDE title-and-content incremental commandline transition=cover
|
286
|
+
|
287
|
+
# Example of shell script for provisioning:
|
288
|
+
|
289
|
+
```bash
|
290
|
+
# Install core packages
|
291
|
+
|
292
|
+
apt-get update
|
293
|
+
sudo apt-get install -y curl
|
294
|
+
sudo apt-get install -y g++
|
295
|
+
sudo apt-get install -y subversion
|
296
|
+
|
297
|
+
# Install RVM
|
298
|
+
|
299
|
+
\curl -L https://get.rvm.io | bash -s stable --ruby=$RUBY_VERSION
|
300
|
+
source /usr/local/rvm/scripts/rvm
|
301
|
+
chown -R vagrant /usr/local/rvm
|
302
|
+
/usr/local/rvm/bin/rvm autolibs enable
|
303
|
+
|
304
|
+
# Install databases
|
305
|
+
|
306
|
+
sudo apt-get install -y postgresql-client
|
307
|
+
sudo apt-get install -y postgresql
|
308
|
+
sudo apt-get install -y mysql-client
|
309
|
+
apt-get -y install mysql-server
|
310
|
+
|
311
|
+
cd $APP_HOME
|
312
|
+
bundle install --without=production
|
313
|
+
rake db:migrate
|
314
|
+
```
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
!SLIDE title-and-content transition=cover
|
319
|
+
|
320
|
+
# Example of **chef** script for provisioning
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
# cookbooks/application/recipes/default.rb
|
324
|
+
|
325
|
+
include_recipe "apt"
|
326
|
+
|
327
|
+
package "curl"
|
328
|
+
package "g++"
|
329
|
+
package "subversion"
|
330
|
+
|
331
|
+
include_recipe "rvm"
|
332
|
+
|
333
|
+
bash "Registering RVM" do
|
334
|
+
code "source /etc/profile.d/rvm.sh"
|
335
|
+
not_if "test -e /usr/local/rvm/bin/rvm"
|
336
|
+
end
|
337
|
+
|
338
|
+
bash "Configuring RVM" do
|
339
|
+
user "root"
|
340
|
+
|
341
|
+
code <<-CODE
|
342
|
+
chown -R vagrant /usr/local/rvm
|
343
|
+
/usr/local/rvm/bin/rvm autolibs enable
|
344
|
+
CODE
|
345
|
+
end
|
346
|
+
include_recipe "rvm::install"
|
347
|
+
```
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
!SLIDE title-and-content transition=cover
|
352
|
+
|
353
|
+
# Example of **chef** script for provisioning (continued)
|
354
|
+
|
355
|
+
```ruby
|
356
|
+
include_recipe "postgresql"
|
357
|
+
include_recipe "postgresql::server"
|
358
|
+
include_recipe "mysql"
|
359
|
+
include_recipe "mysql::server"
|
360
|
+
|
361
|
+
bash "Installing bundle" do
|
362
|
+
user 'vagrant'
|
363
|
+
cwd app_home
|
364
|
+
|
365
|
+
code <<-CODE
|
366
|
+
source /etc/profile.d/rvm.sh
|
367
|
+
rvm use #{ruby_version}@#{gem_name} --create
|
368
|
+
bundle install --without=production
|
369
|
+
CODE
|
370
|
+
end
|
371
|
+
|
372
|
+
bash "Project db bootstrap" do
|
373
|
+
user 'vagrant'
|
374
|
+
cwd app_home
|
375
|
+
|
376
|
+
code <<-CODE
|
377
|
+
source /etc/profile.d/rvm.sh
|
378
|
+
rake db:migrate
|
379
|
+
CODE
|
380
|
+
end
|
381
|
+
```
|