linux_provision 0.9.8 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjE4ZDM5OWUzMGM1YWE3OTA3MmFkNmJhMDE1NjVmMGVhYzYxYzE4NQ==
4
+ NGY4ZmY3MzQyOWVlODIyM2ZiYzlhMmY3YzJkYTNmYmY2NmM3NDgzMw==
5
5
  data.tar.gz: !binary |-
6
- YWJlMTE3MDEwZTg3YTE0ZjUxMjAyYzYzZWNjMDZkYzA2YzA1ZDFiZQ==
6
+ OGVmZWQ4ZDA1ZTlmOTlhYzUzYTliZWY2ZjIxMTA5NjdjYjI1MDk0MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTAyNWQ4OGQ4OTg3MDNhNjdlYWRlZDU4YTY5MzUwYjdkNGM0YjcxZjY4NTNk
10
- NzlmYzMwY2I5ZmIyZDJkZjEzZTZmYTM3OTFlYWFlNTg3MmU3YmEwYmRlMjI3
11
- MTUwNTMxMTU5MDJiNjk5OTc3ZjdhNjNkY2FhMzBiZjMwMGE5MDc=
9
+ MjJjMzgyZTAxZGEzNjFmYjYxYWUxNmI3NjFhNGQzODZmNGM3NmE2ODM2YmQ2
10
+ OGE5MWNiYzMyZjYzZTViNzExMGM0MmNiMTUyOGU0YzgxNTE1MTRhZGQ5ZmJm
11
+ ZGRkNjZkNWYyZjE4NDRiMjMwODFmYzA5NGVmNTNkZjg3ZTAxNGE=
12
12
  data.tar.gz: !binary |-
13
- NzEwMGQzYmVjODZjM2RmNGQ4YWY5OWVmNzJlZjUyMTUxZWQ4MTlkNTBkMmM1
14
- YWM5MWI2NmIyNGFhZmZmNTlhY2ZlZjQ1MDY5MjE1NzIwMDI3MjcwNWU4NjE0
15
- NjI2ZWY3MGMwNmU4N2ZiZjMyNzE2OWU3ZWJmMDFmZmM1OWMwOTc=
13
+ NWVmMWFkNjAyZTVmMmViZWUzMDA5ZWI1NmJjYzg2OTljZjBiN2EzMDViYzMx
14
+ OGUxYzg3Njg5OWZmYWY0ZWY5NmNmODU0MTcxM2E2ZGNiOTI4NzNhMDZhNzAw
15
+ NjkwZDkwN2E0NjNlZGY2M2UyNDdhZjY2YTZlOGEzODdiZmQ4MWQ=
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "node": {
3
- "domain": "22.22.22.22",
4
- "port": "22",
5
- //"domain": "192.168.59.103",
6
- //"port": "42222",
3
+ //"domain": "22.22.22.22",
4
+ //"port": "22",
5
+ "domain": "192.168.59.103",
6
+ "port": "42222",
7
7
  "user": "vagrant",
8
8
  "password": "vagrant",
9
9
  "home": "/home/vagrant",
10
+ "simulate": true,
10
11
  "remote": true
11
12
  },
12
13
 
13
14
  "project": {
14
15
  "home": "#{node.home}/demo",
15
16
  "ruby_version": "1.9.3",
16
- "gemset": "linux_provision"
17
+ "gemset": "linux_provision_demo"
17
18
  },
18
19
 
19
20
  "postgres": {
@@ -27,5 +28,4 @@
27
28
  "app_user": "ruby_dev", "app_password": "ruby_dev",
28
29
  "app_schemas": ["ruby_dev_test", "ruby_dev_dev", "ruby_dev_prod"]
29
30
  }
30
-
31
31
  }
data/CHANGES CHANGED
@@ -32,6 +32,14 @@
32
32
 
33
33
  * Adding support for docker.
34
34
 
35
- == Version 0.9.7
35
+ == Version 0.9.8
36
+
37
+ * Bug fix.
38
+
39
+ == Version 0.9.9
40
+
41
+ * Bug fixes.
42
+
43
+ == Version 0.9.10
36
44
 
37
- * Bug fix.
45
+ * Bug fixes.
data/Gemfile.lock CHANGED
@@ -15,14 +15,14 @@ GEM
15
15
  gemspec_deps_gen (1.1.2)
16
16
  bundler
17
17
  file_utils
18
- gli (2.11.0)
18
+ gli (2.12.1)
19
19
  highline (1.6.21)
20
20
  htmlentities (4.3.2)
21
21
  json (1.8.1)
22
22
  json_pure (1.8.1)
23
23
  mini_portile (0.6.0)
24
24
  net-ssh (2.9.1)
25
- nokogiri (1.6.2.1)
25
+ nokogiri (1.6.3.1)
26
26
  mini_portile (= 0.6.0)
27
27
  parslet (1.6.1)
28
28
  blankslate (~> 2.0)
@@ -31,29 +31,29 @@ GEM
31
31
  rack
32
32
  rake (10.3.2)
33
33
  redcarpet (3.1.2)
34
- rspec (3.0.0)
35
- rspec-core (~> 3.0.0)
36
- rspec-expectations (~> 3.0.0)
37
- rspec-mocks (~> 3.0.0)
38
- rspec-core (3.0.2)
39
- rspec-support (~> 3.0.0)
40
- rspec-expectations (3.0.2)
34
+ rspec (3.1.0)
35
+ rspec-core (~> 3.1.0)
36
+ rspec-expectations (~> 3.1.0)
37
+ rspec-mocks (~> 3.1.0)
38
+ rspec-core (3.1.4)
39
+ rspec-support (~> 3.1.0)
40
+ rspec-expectations (3.1.1)
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.0.0)
43
- rspec-mocks (3.0.2)
44
- rspec-support (~> 3.0.0)
45
- rspec-support (3.0.2)
42
+ rspec-support (~> 3.1.0)
43
+ rspec-mocks (3.1.1)
44
+ rspec-support (~> 3.1.0)
45
+ rspec-support (3.1.0)
46
46
  ruby-debug-base19x (0.11.30.pre15)
47
47
  debugger-ruby_core_source (> 0)
48
48
  rake (>= 0.8.1)
49
49
  ruby-debug-ide (0.4.23.beta1)
50
50
  rake (>= 0.8.1)
51
- script_executor (1.5.1)
51
+ script_executor (1.5.3)
52
52
  highline (~> 1.6)
53
53
  json_pure (~> 1.8)
54
54
  net-ssh (~> 2.8)
55
55
  text-interpolator (~> 1.0)
56
- showoff (0.9.8.1)
56
+ showoff (0.9.9.1)
57
57
  gli (>= 1.3.2)
58
58
  htmlentities
59
59
  json
@@ -71,7 +71,7 @@ GEM
71
71
  em-websocket (~> 0.3.6)
72
72
  eventmachine
73
73
  thin (>= 1.3.1)
74
- text-interpolator (1.1.5)
74
+ text-interpolator (1.1.6)
75
75
  thin (1.6.2)
76
76
  daemons (>= 1.0.9)
77
77
  eventmachine (>= 1.0.0)
data/README.md CHANGED
@@ -1,132 +1,582 @@
1
- # Linux Provision
1
+ # Library for provisioning initial setup of Linux computer for Ruby/Rails development
2
2
 
3
- ## Library and thor tasks for provisioning of Linux computer initial setup for Ruby/Rails development
3
+
4
+ ## Introduction
5
+
6
+
7
+ Why do we need virtualization in development?
8
+
9
+ * We want to have **same environment for all developers**, no matter on what platform they are working now.
10
+
11
+ * We are **working on multiple projects** on same computer unit. As a result, suddenly your computer has "hidden",
12
+ hard-to-discover inter-project dependencies or different versions of the same library.
13
+
14
+ * We want to run Continuous Integration Server jobs that start services on **same ports** for different set
15
+ of acceptance tests (isolated jobs).
16
+
17
+ * To overcome **"It works on my machine!"** syndrome - when development environment is different from production environment.
18
+
19
+ * Sometimes required software is **not available** on developer's platform. Example: 64-bit instant client for oracle
20
+ was broken for almost two years on OSX >= 10.7.
21
+
22
+ * **Development for PAAS**, such as Heroku, Engine Yard etc. You can find and build virtualization that is pretty close to your platform.
23
+
24
+ We will take a look at how can we do provisioning for **Vagrant** and **Docker**. Both tools are built on top of **VirtualBox**.
25
+
26
+
27
+ ## Installing and configuring Vagrant
28
+
29
+
30
+ **Vagrant** is the wrapper around VirtualBox. It is a tool for managing virtual machines via simple to use **command line** interface. With it you can work in a clean environment based on a standard template - **base box**.
31
+
32
+ In order to use Vagrant you have to install these programs:
33
+
34
+ * [VirtualBox][VirtualBox]. Download it from dedicated web site and install
35
+ it as native program. You can use it in UI mode, but it's not required.
36
+
37
+ * [Vagrant][Vagrant]. Before it was distributed as ruby gem, now it's packaged as **native application**. Once installed, it will be accessible from command line as **vagrant** command.
38
+
39
+ You have to decide what linux image fits your needs. I our case we use **Ubuntu 14.04 LTS 64-bit** image - it is identified with **"ubuntu/trusty64"** key.
40
+
41
+ Download and install it:
4
42
 
5
43
  ```bash
6
- vagrant box add precise64 http://files.vagrantup.com/precise64.box
7
- vagrant init precise64
44
+ vagrant box add ubuntu/trusty64 https://vagrantcloud.com/ubuntu/boxes/trusty64
45
+ ```
46
+
47
+ Initialize it:
48
+
49
+ ```
50
+ vagrant init ubuntu/trusty64
51
+ ```
52
+
53
+ This command creates **Vagrantfile** file in the root of your project. Below is an example of such a file:
54
+
55
+ ```ruby
56
+ # -*- mode: ruby -*-
57
+ # vi: set ft=ruby :
8
58
 
59
+ VAGRANTFILE_API_VERSION = "2"
60
+
61
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
62
+ config.vm.box = "ubuntu/trusty64"
63
+ end
64
+ ```
65
+
66
+ You can do various commands with **vagrant** tool. For example:
67
+
68
+ ```bash
69
+ vagrant up # starts up: creates and configures guest machine
70
+ vagrant suspend # suspends the guest machine
71
+ vagrant halt # shuts down the running machine
72
+ vagrant reload # vagrant halt; vagrant up
73
+ vagrant destroy # stops machine and destroys all related resources
74
+ vagrant provision # perform provisioning for machine
75
+ vagrant box remove ubuntu/trusty64 # removes a box from vagrant
76
+ ```
77
+
78
+ You can package currently running VirtualBox environment into reusable box:
79
+
80
+ ```bash
81
+ vagrant package --vagrantfile Vagrantfile --output linux_provision.box
82
+ ```
83
+
84
+ After **Vagrantfile** is generated, you can start your base box:
85
+
86
+ ```bash
9
87
  vagrant up
10
- vagrant reload
11
- vagrant provision
88
+ ```
12
89
 
13
- vagrant suspend
14
- vagrant halt
15
- vagrant destroy
16
- vagrant box remove precise64
90
+ Now you have a **fully running virtual machine** in VirtualBox. You can access it through **vagrant ssh** command:
17
91
 
92
+ ```bash
18
93
  vagrant ssh
94
+ ```
95
+
96
+ or **directly via ssh** (use **vagrant** password for **vagrant** user and port **2222**, this port is used as default by vagrant for ssh connections):
19
97
 
98
+ ```bash
20
99
  ssh vagrant@127.0.0.1 -p 2222
100
+ ```
21
101
 
22
- vagrant ssh
102
+ You can assign IP address for your linux box, e.g.:
103
+
104
+ ```ruby
105
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
106
+ config.vm.network "private_network", ip: "22.22.22.22"
107
+ end
108
+ ```
109
+
110
+ With this configuration you can access ssh on default port:
111
+
112
+ ```bash
113
+ ssh vagrant@22.22.22.22
114
+ ```
115
+
116
+ Your initial setup of linux box is completed now and ready to use.
117
+
118
+
119
+ ## Installing and configuring Docker
120
+
121
+
122
+ Docker helps you create and manage **Linux containers** - extremely lightweight VMs. Containers allow code to run in isolation from other containers. They safely share the machine's resources, all without the overhead of a hypervisor.
23
123
 
24
- cd /vagrant
124
+ In order to use Docker you have to install these programs:
25
125
 
26
- rake db:dev:reset
126
+ * [VirtualBox][VirtualBox].
27
127
 
28
- rspec
128
+ * [boot2docker][boot2docker]. You need to install it only for non-Linux environment.
129
+
130
+ boot2docker is a lightweight Linux image made specifically to run Docker containers. It runs completely from RAM, weighs approximately 27 MB and boots in about 5 seconds.
131
+
132
+ We'll run the Docker client natively on OSX, but the Docker server will run inside our boot2docker VM. This also means that boot2docker, not OSX, is the Docker host.
133
+
134
+ This command will create **boot2docker-vm** virtual machine:
135
+
136
+ ```bash
137
+ boot2docker init
138
+ ```
139
+ Go to VirtualBox UI - new VM will be added.
140
+
141
+ Start it up:
29
142
 
30
- ASSET_HOST=http://22.22.22.22:3000 rails s
143
+ ```bash
144
+ boot2docker up
31
145
  ```
32
146
 
33
- and then access it from the browser within [host computer](http://22.22.22.22:3000/app):
147
+ or shut it down:
34
148
 
35
149
  ```bash
36
- open http://22.22.22.22:3000/app
150
+ boot2docker down
37
151
  ```
38
152
 
153
+ Upgrade Boot2docker VM image:
154
+
39
155
  ```bash
40
- vagrant package --vagrantfile Vagrantfile --output linux_provision.box
156
+ boot2docker stop
157
+ boot2docker download
158
+ boot2docker up
41
159
  ```
42
160
 
161
+ When docker daemon first started, it gives you recommendation about how to run docker client.
162
+ It needs to know where docker is running, e.g.:
43
163
 
44
- ## Docker
164
+ ```bash
165
+ export DOCKER_HOST=tcp://192.168.59.103:2375
166
+ ```
45
167
 
168
+ You have to setup it globally in **.bash\_profile** file or specify it each time when docker client is started.
46
169
 
47
- docker is an open-source project that makes creating and managing Linux containers really easy.
48
- Containers are like extremely lightweight VMs – they allow code to run in isolation from other containers
49
- but safely share the machine’s resources, all without the overhead of a hypervisor.
170
+ You can access boot2docker over ssh (user: **docker**, password: **tcuser**):
50
171
 
51
- docker containers can boot extremely fast (in milliseconds!) which gives you unprecedented flexibility
52
- in managing load across your cluster. For example, instead of running chef on each of your VMs,
53
- it’s faster and more reliable to have your build system create a container and launch it on
54
- the appropriate number of CoreOS hosts. When these containers start, they can signal your proxy (via etcd)
55
- to start sending them traffic.
172
+ ```bash
173
+ boot2docker ssh
174
+ ```
56
175
 
176
+ Download the small base image named **busybox**:
57
177
 
58
- ## Installation
178
+ ```bash
179
+ docker pull busybox
180
+ ```
59
181
 
60
- * Download and install VirtualBox for OSX
182
+ Run and test docker as separate command:
61
183
 
62
- https://www.virtualbox.org/wiki/Downloads
184
+ ```bash
185
+ docker run busybox echo "hello, linus!"
186
+ ```
63
187
 
64
- * Install boot2docker and docker via homebrew:
188
+ or interactively:
65
189
 
66
190
  ```bash
67
- brew install boot2docker
191
+ docker run -t -i busybox /bin/sh
192
+ ```
193
+
194
+
195
+ ## Install and confige linux_provision gem
196
+
197
+ Both programs - Vagrant and Docker - have their own ways to serve provisioning. Vagrant is doing it with the help of **provision** attribute. Example with simple shell script:
198
+
199
+ ```ruby
200
+ Vagrant::Config.run do |config|
201
+ config.vm.provision :shell, :path => "bootstrap.sh"
202
+ end
203
+ ```
204
+ or with chef solo:
205
+
206
+ ```ruby
207
+ Vagrant::Config.run do |config|
208
+ config.vm.provision :chef_solo do |chef|
209
+ ...
210
+ end
211
+ end
212
+ ```
213
+ Docker also lets you do provisioning in form of **RUN** command:
214
+
215
+ ```text
216
+ # Dockerfile
217
+
218
+ RUN apt-get -y -q install postgresql-9.3
68
219
  ```
69
- Docker will be installed as an dependency.
70
220
 
71
- Initialize boot2docker virtual machine:
221
+ After multiple experiments with provisions both from Vagrant and Docker it was discovered that it is not convenient to use. It does not let you to easy install or uninstall separate packages. It's better to do it as **set of independent scripts**, separated completely from Docker and Vagrant.
222
+
223
+ **linux_provision** gem is the set of such shell scripts - they install various components like postgres server, rvm, ruby etc. with the help of thor or rake script. You can see other gems that are providing similar solutions:
224
+ for [Oracle Instant Client][oracle_client_provision] and for [OSX][osx_provision].
225
+
226
+ In order to use gem add this line to your application's Gemfile:
72
227
 
73
228
  ```bash
74
- boot2docker init
229
+ gem 'linux_provision'
230
+ ```
231
+
232
+ And then execute:
233
+
234
+ ```bash
235
+ bundle
236
+ ```
237
+
238
+ Before you can start using **linux_provision** gem within your project, you need to configure it. Do the following:
239
+
240
+ * Create configuration file (e.g. **.linux\_provision.json**) in json format at the root of your project. It will define your environment:
241
+
242
+ ```json
243
+ {
244
+ "node": {
245
+ ...
246
+ },
247
+
248
+ "project": {
249
+ "home": "#{node.home}/demo",
250
+ "ruby_version": "1.9.3",
251
+ "gemset": "linux_provision_demo"
252
+ },
253
+
254
+ "postgres": {
255
+ "hostname": "localhost", "user": "postgres", "password": "postgres",
256
+ "app_user": "pg_user", "app_password": "pg_password",
257
+ "app_schemas": [ "my_project_test", "my_project_dev", "my_project_prod"]
258
+ }
259
+ }
75
260
  ```
76
261
 
77
- Update .bash_profile file:
262
+ Variables defined in this file are used by underlying shell scripts provided by the gem.
263
+
264
+ In **node** section you describe destination computer where you want to install this provision.
265
+
266
+ In **project** section you keep project-related info, like project **home**, project **gemset name** and **ruby version**.
267
+
268
+ Last **postgres** section contains information about your postgres server.
269
+
270
+ * Provide execution script
271
+
272
+ Library itself if written in ruby, but for launching its code it's more convenient to use **rake** or **thor** tool. Here I provide thor script as an example:
273
+
274
+ ```ruby
275
+ # thor/linux_install.thor
276
+
277
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
278
+
279
+ require 'linux_provision'
280
+
281
+ class LinuxInstall < Thor
282
+ @installer = LinuxProvision.new self, ".linux_provision.json"
283
+
284
+ class << self
285
+ attr_reader :installer
286
+ end
287
+
288
+ desc "general", "Installs general packages"
289
+ def general
290
+ invoke :prepare
291
+
292
+ invoke :rvm
293
+ invoke :ruby
78
294
 
295
+ invoke :postgres
296
+ invoke :mysql
297
+ end
298
+ end
299
+ ```
300
+
301
+ You can execute separate commands from script directly with **invoke** thor command. Below is fragment of such script:
79
302
 
80
303
  ```bash
81
- export DOCKER_HOST=tcp://127.0.0.1:4243
304
+ #!/bin/sh
305
+
306
+ #######################################
307
+ [prepare]
308
+ # Updates linux core packages
309
+
310
+ sudo apt-get update
311
+
312
+ sudo apt-get install -y curl
313
+ sudo apt-get install -y g++
314
+ sudo apt-get install -y subversion
315
+ sudo apt-get install -y git
316
+
317
+ #######################################
318
+ [rvm]
319
+ # Installs rvm
320
+
321
+ curl -L https://get.rvm.io | bash
322
+
323
+ #sudo chown -R vagrant /opt/vagrant_ruby
324
+
325
+ #######################################
326
+ [ruby]
327
+ # Installs ruby
328
+
329
+ USER_HOME="#{node.home}"
330
+
331
+ source $USER_HOME/.rvm/scripts/rvm
332
+
333
+ rvm install ruby-1.9.3
82
334
  ```
83
335
 
84
- Start the docker daemon:
336
+ You can add your own scripts (e.g. demo_scripts.sh):
337
+
338
+ ```ruby
339
+ class LinuxInstall < Thor
340
+ @installer = LinuxProvision.new self,
341
+ ".linux_provision.json",
342
+ [File.expand_path("demo_scripts.sh", File.dirname(__FILE__))]
343
+ ...
344
+ end
345
+ ```
346
+
347
+ We defined 2 new commands in demo_script.sh:
85
348
 
86
349
  ```bash
87
- boot2docker up
350
+ #!/bin/sh
351
+
352
+ ##############################
353
+ [project]
354
+ # Installs demo sinatra project
355
+
356
+ USER_HOME="#{node.home}"
357
+
358
+ APP_HOME="#{project.home}"
359
+
360
+ cd $APP_HOME
361
+
362
+ source $USER_HOME/.rvm/scripts/rvm
363
+
364
+ rvm use #{project.ruby_version}@#{project.gemset} --create
365
+
366
+ bundle
367
+
368
+ rake db:migrate
369
+
370
+
371
+ ##############################
372
+ [rackup]
373
+ # Starts sinatra demo application
374
+
375
+ USER_HOME="#{node.home}"
376
+
377
+ APP_HOME="#{project.home}"
378
+
379
+ cd $APP_HOME
380
+
381
+ source $USER_HOME/.rvm/scripts/rvm
382
+
383
+ rvm use #{project.ruby_version}@#{project.gemset}
384
+
385
+ rackup
386
+ ```
387
+
388
+ ## Demo application with Vagrant
389
+
390
+
391
+ For testing purposes we have created demo web application (in **demo** folder) based on [sinatra][sinatra] framework.
392
+
393
+ First, we need to inform Vagrant about the location of this application within virtual machine:
394
+
395
+ ```ruby
396
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
397
+ config.vm.synced_folder "./demo", "/home/vagrant/demo"
398
+ end
88
399
  ```
89
400
 
90
- or down:
401
+ Second, we need to configure linux_provision gem to point to right domain/port and use correct user name/password:
402
+
403
+ ```json
404
+ {
405
+ "node": {
406
+ "domain": "22.22.22.22", # remote host, see "config.vm.synced_folder"
407
+ "port": "22", # default ssh port
408
+ "user": "vagrant", # vagrant user name
409
+ "password": "vagrant", #
410
+ "home": "/home/vagrant", # vagrant user password
411
+ "remote": true
412
+ }
413
+ }
414
+ ```
415
+
416
+ Start your base box:
91
417
 
92
418
  ```bash
93
- boot2docker down
419
+ vagrant up
94
420
  ```
95
421
 
96
- ssh it:
422
+ Access linux box and find out this demo application's home:
97
423
 
98
424
  ```bash
99
- boot2docker ssh
425
+ ssh vagrant@22.22.22.22
426
+
427
+ pwd # /home/vagrant
428
+
429
+ ls # demo
100
430
 
101
- # User: docker
102
- # Pwd: tcuser
431
+ cd demo
432
+
433
+ ls # content of demo folder
103
434
  ```
104
435
 
105
- Download the small base image named busybox:
436
+ These commands from **linux_provision** gem will build your environment for the demo project (install rvm, ruby, postgres, postgres user and posters tables):
106
437
 
107
438
  ```bash
108
- docker pull busybox
109
- docker pull ubuntu
110
- docker pull centos
439
+ thor linux_install:prepare
440
+ thor linux_install:rvm
441
+ thor linux_install:ruby
442
+
443
+ thor linux_install:postgres
444
+
445
+ thor linux_install:postgres_create_user
446
+ thor linux_install:postgres_create_schemas
447
+ ```
448
+
449
+ Initialize demo project and run sinatra application:
450
+
451
+ ```bash
452
+ thor linux_install:project
453
+
454
+ thor linux_install:rackup
111
455
  ```
112
456
 
113
- Run and test as separate command:
457
+ Now you can access application from your favorite browser:
114
458
 
115
459
  ```bash
116
- docker run -t -i ubuntu /bin/bash
460
+ open http://22.22.22.22:9292
117
461
  ```
118
462
 
119
- and interactively:
463
+ ## Demo application with Docker
464
+
465
+ You need to do very similar steps as with Vagrant. The only difference is in **linux\_provision.json** file you have to point to different host, port and user:
466
+
467
+ ```json
468
+ {
469
+ "node": {
470
+ "domain": "192.168.59.103", # remote host, see boot2docker ip
471
+ "port": "42222", # ssh port in docker
472
+ "user": "vagrant", # vagrant user name
473
+ "password": "vagrant", #
474
+ "home": "/home/vagrant", # vagrant user password
475
+ "remote": true
476
+ }
477
+ }
478
+ ```
479
+
480
+ Our Dockerfile is responsible for the following base steps:
481
+
482
+ * Install Ubuntu 14.4.
483
+
484
+ * Install sshd (for enabling ssh).
485
+
486
+ * Create vagrant user (just to in-synch with Vagrant example).
487
+
488
+ * Reveal project home as /home/vagrant/demo.
489
+
490
+ * Expose port 9292 (our sinatra application).
491
+
492
+ Here is example:
493
+
494
+ ```txt
495
+ FROM ubuntu:14.04
496
+
497
+ MAINTAINER Alexander Shvets "alexander.shvets@gmail.com"
120
498
 
499
+ # 1. Update system
500
+ RUN sudo apt-get update
501
+ RUN sudo locale-gen en_US.UTF-8
502
+
503
+ # 2. Install sshd
504
+
505
+ RUN sudo apt-get install -y openssh-server
506
+ RUN mkdir /var/run/sshd
507
+ RUN echo 'root:root' |chpasswd
508
+ RUN sed --in-place=.bak 's/without-password/yes/' /etc/ssh/sshd_config
509
+
510
+ EXPOSE 22
511
+
512
+ CMD /usr/sbin/sshd -D
513
+
514
+ # 3. Create vagrant user
515
+ RUN groupadd vagrant
516
+ RUN useradd -d /home/vagrant -g vagrant -m -s /bin/bash vagrant
517
+ RUN sudo sed -i '$a vagrant ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
518
+ RUN echo vagrant:vagrant | chpasswd
519
+ RUN sudo chown -R vagrant /home/vagrant
520
+
521
+ # 4. Prepare directories for the project
522
+
523
+ # Add project dir to docker
524
+
525
+ ADD . /home/vagrant/demo
526
+ WORKDIR /home/vagrant/demo
527
+
528
+ EXPOSE 9292
529
+ ```
530
+
531
+ Build docker image and run it:
121
532
 
122
533
  ```bash
123
- docker run -t -i ubuntu /bin/bash
534
+ docker build -t demo demo
535
+ docker run -d -p 42222:22 -p 9292:9292 --name demo demo
124
536
  ```
125
537
 
538
+ As you can see, we map port 22 inside docker to port 42222 outside. It means that when we hit port 42222 with regular telnet tool, we'll hit service inside the docker.
539
+
540
+ You can access virtual machine via ssh:
541
+
126
542
  ```bash
127
- docker build -t demo docker/demo
543
+ ssh vagrant@192.168.59.103 -p 42222
128
544
  ```
129
545
 
546
+ Now you can do your provision - it's exactly the same as with Vagrant example:
547
+
548
+ ```bash
549
+ thor linux_install:prepare
550
+ thor linux_install:rvm
551
+ thor linux_install:ruby
552
+
553
+ thor linux_install:postgres
554
+
555
+ thor linux_install:postgres_create_user
556
+ thor linux_install:postgres_create_schemas
557
+
558
+ thor linux_install:project
559
+
560
+ thor linux_install:rackup
561
+ ```
562
+
563
+ After provisioning and starting server try to access your application from the browser:
564
+
130
565
  ```bash
131
- docker run -p 49160:8080 -d busybox
566
+ open http://192.168.59.103:9292
132
567
  ```
568
+
569
+ ## Contributing
570
+
571
+ 1. Fork it
572
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
573
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
574
+ 4. Push to the branch (`git push origin my-new-feature`)
575
+ 5. Create new Pull Request
576
+
577
+ [VirtualBox]: https://www.virtualbox.org/wiki/Downloads
578
+ [Vagrant]: http://www.vagrantup.com
579
+ [boot2docker]: http://boot2docker.io
580
+ [oracle_client_provision]: https://github.com/shvets/oracle_client_provision
581
+ [osx_provision]: https://github.com/shvets/osx_provision
582
+ [sinatra]: http://www.sinatrarb.com
data/Vagrantfile CHANGED
@@ -93,7 +93,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
93
93
  # the path on the guest to mount the folder. And the optional third
94
94
  # argument is a set of non-required options.
95
95
  # config.vm.synced_folder "../data", "/vagrant_data"
96
- config.vm.synced_folder "../linux_provision/demo", "/home/vagrant/demo"
96
+ config.vm.synced_folder "demo", "/home/vagrant/demo"
97
97
 
98
98
  # Provider-specific configuration so you can fine-tune various
99
99
  # backing providers for Vagrant. These expose provider-specific options.
@@ -142,7 +142,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
142
142
  #
143
143
  # config.vm.provision "puppet" do |puppet|
144
144
  # puppet.manifests_path = "manifests"
145
- # puppet.manifest_file = "site.pp"
145
+ # puppet.manifest_file = "default.pp"
146
146
  # end
147
147
 
148
148
  # Enable provisioning with chef solo, specifying a cookbooks path, roles
data/demo/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-1.9.3
1
+ 1.9.3
@@ -72,52 +72,27 @@ sudo apt-get install -y postgresql
72
72
 
73
73
  sudo service postgresql restart
74
74
 
75
-
76
75
  #######################################
77
76
  [postgres_remote_access]
78
77
 
79
78
  sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/9.1/main/postgresql.conf
80
79
  sudo sed -i '$a host all all 0.0.0.0/0 md5' /etc/postgresql/9.1/main/pg_hba.conf
81
80
 
82
-
83
- #######################################
84
- [mysql]
85
- # Installs mysql server
86
-
87
- PATH=$PATH:/usr/local/bin
88
-
89
- MYSQL_USER='#{mysql.user}'
90
- MYSQL_PASSWORD='#{mysql.password}'
91
- MYSQL_SERVER_VERSION='5.5'
92
-
93
- sudo apt-get install -y libmysqlclient-dev ruby-dev
94
-
95
- sudo apt-get install debconf-utils
96
- sudo apt-get install -y mysql-client
97
-
98
- sudo debconf-set-selections <<< "mysql-server-$MYSQL_SERVER_VERSION mysql-server/root_password password $MYSQL_PASSWORD"
99
- sudo debconf-set-selections <<< "mysql-server-$MYSQL_SERVER_VERSION mysql-server/root_password_again password $MYSQL_PASSWORD"
100
-
101
- sudo apt-get -y install mysql-server
102
-
103
- sudo service mysql restart
104
-
105
- #sudo mysqladmin -u$MYSQL_USER password $MYSQL_PASSWORD
106
-
107
-
108
81
  #######################################
109
82
  [postgres_create_user]
83
+ # Creates postgres user
110
84
 
111
85
  PATH=$PATH:/usr/local/bin
112
86
 
113
87
  APP_USER='#{postgres.app_user}'
114
88
  APP_PASSWORD='#{postgres.app_password}'
115
89
 
116
- sudo -u postgres psql -c "CREATE USER $APP_USER WITH PASSWORD '$APP_USER'"
90
+ sudo -u postgres psql -c "CREATE USER $APP_USER WITH PASSWORD '$APP_PASSWORD'"
117
91
 
118
92
 
119
93
  #######################################
120
94
  [postgres_drop_user]
95
+ # Drops postgres user
121
96
 
122
97
  PATH=$PATH:/usr/local/bin
123
98
 
@@ -128,6 +103,7 @@ sudo -u postgres psql -c "DROP USER $APP_USER"
128
103
 
129
104
  #######################################
130
105
  [postgres_create_schema]
106
+ # Creates postgres schema
131
107
 
132
108
  SCHEMA='#{schema}'
133
109
 
@@ -142,6 +118,7 @@ sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $SCHEMA to $APP_USER"
142
118
 
143
119
  #######################################
144
120
  [postgres_drop_schema]
121
+ # Drops postgres schema
145
122
 
146
123
  PATH=$PATH:/usr/local/bin
147
124
 
@@ -149,9 +126,34 @@ SCHEMA='#{schema}'
149
126
 
150
127
  sudo -u postgres psql -c "DROP DATABASE $SCHEMA"
151
128
 
129
+ #######################################
130
+ [mysql]
131
+ # Installs mysql server
132
+
133
+ PATH=$PATH:/usr/local/bin
134
+
135
+ MYSQL_USER='#{mysql.user}'
136
+ MYSQL_PASSWORD='#{mysql.password}'
137
+ MYSQL_SERVER_VERSION='5.5'
138
+
139
+ sudo apt-get install -y libmysqlclient-dev ruby-dev
140
+
141
+ sudo apt-get install debconf-utils
142
+ sudo apt-get install -y mysql-client
143
+
144
+ sudo debconf-set-selections <<< "mysql-server-$MYSQL_SERVER_VERSION mysql-server/root_password password $MYSQL_PASSWORD"
145
+ sudo debconf-set-selections <<< "mysql-server-$MYSQL_SERVER_VERSION mysql-server/root_password_again password $MYSQL_PASSWORD"
146
+
147
+ sudo apt-get -y install mysql-server
148
+
149
+ sudo service mysql restart
150
+
151
+ #sudo mysqladmin -u$MYSQL_USER password $MYSQL_PASSWORD
152
+
152
153
 
153
154
  #######################################
154
155
  [mysql_create_user]
156
+ # Creates mysql user
155
157
 
156
158
  PATH=$PATH:/usr/local/bin
157
159
 
@@ -166,6 +168,7 @@ mysql -h $HOST_NAME -u$MYSQL_USER -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON
166
168
 
167
169
  #######################################
168
170
  [mysql_drop_user]
171
+ # Drops mysql user
169
172
 
170
173
  APP_USER='#{mysql.app_user}'
171
174
  HOST_NAME='#{mysql.hostname}'
@@ -178,6 +181,7 @@ mysql -h $HOST_NAME -u $MYSQL_USER -p"$MYSQL_PASSWORD" -e "DROP USER '$APP_USER
178
181
 
179
182
  #######################################
180
183
  [mysql_create_schema]
184
+ # Creates mysql schema
181
185
 
182
186
  PATH=$PATH:/usr/local/bin
183
187
 
@@ -192,6 +196,7 @@ mysql -h $HOST_NAME -u$MYSQL_USER -p$MYSQL_PASSWORD -e "create database $SCHEMA;
192
196
 
193
197
  #######################################
194
198
  [mysql_drop_schema]
199
+ # Drops mysql schema
195
200
 
196
201
  PATH=$PATH:/usr/local/bin
197
202
 
@@ -1,3 +1,3 @@
1
1
  class LinuxProvision
2
- VERSION = "0.9.8"
2
+ VERSION = "0.9.10"
3
3
  end
@@ -16,30 +16,30 @@
16
16
  * We are **working on multiple projects** on same workstation. As a result, suddenly your computer has "hidden",
17
17
  hard-to-discover inter-project dependencies or different versions of same library.
18
18
 
19
- * To overcome **It "works on my machine!"** syndrome - development environment is different from production environment.
19
+ * To overcome **It works on my machine!** syndrome - development environment is different from production environment.
20
20
 
21
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.
22
+ was broken for almost two years on OSX >= 10.7.
23
23
 
24
24
  * **Development for PAAS**, such as Heroku, Engine Yard etc. You can find/build virtualization that is pretty close to
25
25
  your platform.
26
26
 
27
27
 
28
-
29
28
  !SLIDE content transition=cover
30
29
 
31
30
  # Vagrant
32
31
 
33
32
  >
34
33
 
35
- ![vagrant](vagrant.jpg)
34
+ ![vagrant](../images/vagrant.jpg)
36
35
 
37
36
  !SLIDE title-and-content transition=cover
38
37
 
39
38
  # What is it?
40
39
 
41
- * It is ruby gem.
42
- * it helps to provide easy to configure, reproducible, and portable work environments.
40
+ * It is wrapper around virtual box.
41
+ * It is an tool for managing virtual machines via a simple to use command line interface.
42
+ * With vagrant you can work in a clean environment based on a standard template (base box).
43
43
 
44
44
 
45
45
 
@@ -50,23 +50,8 @@ your platform.
50
50
  * Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads). Download it from dedicated web site and install
51
51
  it as native program. You can use it in UI mode, but it's not required.
52
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
- ```
53
+ * Install [Vagrant](http://www.vagrantup.com). Before it was distributed as ruby gem, now it's done as
54
+ native application. Once installed, it will be accessible from command line as **vagrant** command.
70
55
 
71
56
 
72
57
 
@@ -252,7 +237,7 @@ vagrant ssh node2
252
237
  * It will have already preinstalled and configured ruby/rvm/mysql/postgres etc.:
253
238
 
254
239
  ```bash
255
- vagrant package --vagrantfile Vagrantfile --output proteus.box
240
+ vagrant package --vagrantfile Vagrantfile --output new_linux_box.box
256
241
  ```
257
242
 
258
243
 
@@ -261,7 +246,8 @@ vagrant package --vagrantfile Vagrantfile --output proteus.box
261
246
 
262
247
  # What's next?
263
248
 
264
- * Once you install Vagrant with some provision (script, chef-solo or puppet), you can use it in same way as your worksation:
249
+ * Once you install Vagrant with some provision (script, chef-solo or puppet), you can use it in same way
250
+ as your workstation:
265
251
 
266
252
  ```bash
267
253
  vagrant ssh
@@ -275,10 +261,10 @@ rspec
275
261
  ASSET_HOST=http://22.22.22.22:3000 rails s
276
262
  ```
277
263
 
278
- * and then access it from the browser within [host computer](http://22.22.22.22:3000/triton):
264
+ * and then access it from the browser within [host computer](http://22.22.22.22:3000/app):
279
265
 
280
266
  ```
281
- open http://22.22.22.22:3000/triton
267
+ open http://22.22.22.22:3000/app
282
268
  ```
283
269
 
284
270
 
@@ -40,7 +40,7 @@ unified, easy to replicate virtual platform with same characteristics for all de
40
40
 
41
41
  >
42
42
 
43
- ![chef](chef.jpg)
43
+ ![chef](../images/chef.jpg)
44
44
 
45
45
 
46
46
 
@@ -28,7 +28,7 @@ You can’t run a VM on top of another. You can run Docker on a VM because Docke
28
28
 
29
29
  ## How it works?
30
30
 
31
- * Docker needs to be run with root privelege.
31
+ * Docker needs to be run with root privilege.
32
32
 
33
33
  Docker DOESN’T write into the image. Instead, it creates a layer with each Dockerfile line on top of the existing image,
34
34
  which contains the modifications you made to the filesystem. Migrating from a previous state of filesystem to
@@ -15,9 +15,9 @@
15
15
  "lax_spacing": true
16
16
  },
17
17
  "sections": [
18
- // {"section":"01-vagrant"},
19
- // {"section":"02-provision"},
20
- {"section":"03-docker"}
21
- // {"section":"04-conclusion"}
18
+ {"section":"01-vagrant"},
19
+ {"section":"02-provision"},
20
+ {"section":"03-docker"},
21
+ {"section":"04-conclusion"}
22
22
  ]
23
23
  }
@@ -28,22 +28,30 @@ class LinuxInstall < Thor
28
28
  # invoke :selenium
29
29
  end
30
30
 
31
- desc "app", "Installs app"
32
- def app
31
+ desc "create_env", "Installs environment"
32
+ def create_env
33
33
  invoke :postgres_create_user
34
34
  invoke :postgres_create_schemas
35
35
 
36
36
  invoke :mysql_create_user
37
37
  invoke :mysql_create_schemas
38
+ end
38
39
 
39
- invoke :project
40
+ desc "delete_env", "Deletes environment"
41
+ def delete_env
42
+ invoke :postgres_drop_schemas
43
+ invoke :postgres_drop_user
44
+
45
+ invoke :mysql_drop_schemas
46
+ invoke :mysql_drop_user
40
47
  end
41
48
 
42
49
  desc "all", "Installs all required packages"
43
50
  def all
44
51
  invoke :general
45
52
  invoke :special
46
- invoke :app
53
+ invoke :create_env
54
+ invoke :project
47
55
  end
48
56
 
49
57
  desc "postgres_create_schemas", "Initializes postgres schemas"
data/thor/showoff.thor ADDED
@@ -0,0 +1,15 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'script_executor/executable'
4
+
5
+ class Showoff < Thor
6
+ include Executable
7
+
8
+ desc "all", "Runs showoff"
9
+ def all
10
+ execute <<-CODE
11
+ cd presentation/virtualization
12
+ showoff serve
13
+ CODE
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_provision
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: text-interpolator
@@ -137,8 +137,6 @@ files:
137
137
  - demo/views/layout.erb
138
138
  - demo/views/new.erb
139
139
  - demo/views/note.erb
140
- - docker/postgres/Dockerfile
141
- - docker/postgres/bin/create_db.sh
142
140
  - lib/linux_provision.rb
143
141
  - lib/linux_provision/bin/selenium
144
142
  - lib/linux_provision/bin/xvfb
@@ -161,10 +159,10 @@ files:
161
159
  - spec/linux_install_spec.rb
162
160
  - spec/linux_provision_spec.rb
163
161
  - spec/spec_helper.rb
164
- - stats/viewstats.json
165
162
  - thor/demo_scripts.sh
166
163
  - thor/docker.thor
167
164
  - thor/linux_install.thor
165
+ - thor/showoff.thor
168
166
  - thor/ssh.thor
169
167
  homepage: http://github.com/shvets/linux_provision
170
168
  licenses:
@@ -1,61 +0,0 @@
1
- # https://docs.docker.com/examples/postgresql_service/
2
-
3
- FROM ubuntu
4
- MAINTAINER SvenDowideit@docker.com
5
-
6
- # Add the PostgreSQL PGP key to verify their Debian packages.
7
- # It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc
8
- RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
9
-
10
- # Add PostgreSQL's repository. It contains the most recent stable release
11
- # of PostgreSQL, ``9.3``.
12
- RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
13
-
14
- # Update the Ubuntu and PostgreSQL repository indexes
15
- RUN apt-get update
16
-
17
- # Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3
18
- # There are some warnings (in red) that show up during the build. You can hide
19
- # them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive
20
- RUN apt-get -y -q install python-software-properties software-properties-common
21
- RUN apt-get -y -q install postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
22
-
23
- # Note: The official Debian and Ubuntu images automatically ``apt-get clean``
24
- # after each ``apt-get``
25
-
26
- # Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed``
27
- USER postgres
28
-
29
- # Create a PostgreSQL role named ``docker`` with ``docker`` as the password and
30
- # then create a database `docker` owned by the ``docker`` role.
31
- # Note: here we use ``&&\`` to run commands one after the other - the ``\``
32
- # allows the RUN command to span multiple lines.
33
- #RUN /etc/init.d/postgresql start &&\
34
- # psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
35
- # createdb -O docker docker
36
-
37
- ADD bin/create_db.sh /src/
38
- RUN /src/create_db.sh
39
-
40
-
41
- # Adjust PostgreSQL configuration so that remote connections to the
42
- # database are possible.
43
- RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf
44
-
45
- # And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf``
46
- RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf
47
-
48
- # Expose the PostgreSQL port
49
- EXPOSE 5432
50
-
51
- # Add VOLUMEs to allow backup of config, logs and databases
52
- VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
53
-
54
- # Set the default command to run when starting the container
55
- CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
56
-
57
- # docker stop postgres
58
- # docker rm postgres
59
- # docker build -t postgres docker/postgres
60
- # docker run -d -p 5432:5432 --name postgres postgres
61
-
@@ -1,14 +0,0 @@
1
- #!/bin/sh
2
-
3
- /etc/init.d/postgresql start
4
-
5
- psql --command "CREATE USER ruby_dev WITH SUPERUSER PASSWORD 'ruby_dev';"
6
-
7
- createdb -O ruby_dev ruby_dev_test
8
- createdb -O ruby_dev ruby_dev_dev
9
- createdb -O ruby_dev ruby_dev_prod
10
-
11
- psql -l
12
-
13
- /etc/init.d/postgresql stop
14
-
data/stats/viewstats.json DELETED
@@ -1 +0,0 @@
1
- {}