linux_provision 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.linux_provision.json +3 -3
  3. data/CHANGES +4 -0
  4. data/Gemfile +8 -5
  5. data/Gemfile.lock +57 -9
  6. data/README.md +129 -35
  7. data/Vagrantfile +1 -1
  8. data/demo/.ruby-gemset +1 -0
  9. data/demo/.ruby-version +1 -0
  10. data/demo/Dockerfile +107 -0
  11. data/demo/Gemfile +7 -0
  12. data/demo/Gemfile.lock +45 -0
  13. data/demo/Rakefile +7 -0
  14. data/demo/app.rb +29 -0
  15. data/demo/bin/start-server.sh +7 -0
  16. data/demo/config.ru +3 -0
  17. data/demo/db/migrate/20140610203958_create_notes.rb +14 -0
  18. data/demo/db/migrate/20140610204302_add_notes.rb +7 -0
  19. data/demo/db/schema.rb +26 -0
  20. data/demo/db_setup.rb +11 -0
  21. data/demo/note.rb +2 -0
  22. data/demo/supervisord.conf +8 -0
  23. data/demo/views/index.erb +10 -0
  24. data/demo/views/layout.erb +8 -0
  25. data/demo/views/new.erb +12 -0
  26. data/demo/views/note.erb +3 -0
  27. data/docker/postgres/Dockerfile +61 -0
  28. data/docker/postgres/bin/create_db.sh +14 -0
  29. data/docker/sshd/Dockerfile +28 -0
  30. data/docker/supervisord/Dockerfile +28 -0
  31. data/docker/supervisord/supervisord.conf +8 -0
  32. data/lib/linux_provision/generic_provision.rb +28 -19
  33. data/lib/linux_provision/linux_provision.rb +7 -165
  34. data/lib/linux_provision/linux_provision_scripts.sh +65 -21
  35. data/lib/linux_provision/version.rb +1 -1
  36. data/presentation/virtualization/01-vagrant/slides.md +381 -0
  37. data/presentation/virtualization/02-provision/slides.md +400 -0
  38. data/presentation/virtualization/03-docker/slides.md +208 -0
  39. data/presentation/virtualization/04-conclusion/slides.md +36 -0
  40. data/presentation/virtualization/default.css +59 -0
  41. data/presentation/virtualization/default.tpl +2 -0
  42. data/presentation/virtualization/images/chef.jpg +0 -0
  43. data/presentation/virtualization/images/provisioning.jpg +0 -0
  44. data/presentation/virtualization/images/vagrant.jpg +0 -0
  45. data/presentation/virtualization/showoff.json +23 -0
  46. data/presentation/virtualization/simple.tpl +2 -0
  47. data/spec/linux_install_spec.rb +9 -2
  48. data/spec/linux_provision_spec.rb +1 -1
  49. data/stats/viewstats.json +1 -0
  50. data/thor/demo_scripts.sh +34 -0
  51. data/thor/docker.thor +31 -0
  52. data/thor/linux_install.thor +17 -115
  53. metadata +40 -2
data/demo/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "sinatra"
4
+ gem "pg"
5
+ gem "activerecord"
6
+ gem "sinatra-activerecord"
7
+
data/demo/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activemodel (4.1.1)
5
+ activesupport (= 4.1.1)
6
+ builder (~> 3.1)
7
+ activerecord (4.1.1)
8
+ activemodel (= 4.1.1)
9
+ activesupport (= 4.1.1)
10
+ arel (~> 5.0.0)
11
+ activesupport (4.1.1)
12
+ i18n (~> 0.6, >= 0.6.9)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 1.1)
17
+ arel (5.0.1.20140414130214)
18
+ builder (3.2.2)
19
+ i18n (0.6.9)
20
+ json (1.8.1)
21
+ minitest (5.3.4)
22
+ pg (0.17.1)
23
+ rack (1.5.2)
24
+ rack-protection (1.5.3)
25
+ rack
26
+ sinatra (1.4.5)
27
+ rack (~> 1.4)
28
+ rack-protection (~> 1.4)
29
+ tilt (~> 1.3, >= 1.3.4)
30
+ sinatra-activerecord (2.0.2)
31
+ activerecord (>= 3.2)
32
+ sinatra (~> 1.0)
33
+ thread_safe (0.3.4)
34
+ tilt (1.4.1)
35
+ tzinfo (1.2.1)
36
+ thread_safe (~> 0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ activerecord
43
+ pg
44
+ sinatra
45
+ sinatra-activerecord
data/demo/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+
3
+ include Rake::DSL
4
+
5
+ require "./app"
6
+
7
+ require "sinatra/activerecord/rake"
data/demo/app.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'sinatra'
2
+ require 'sinatra/activerecord'
3
+
4
+ require './note'
5
+ require './db_setup'
6
+
7
+ get "/" do
8
+ @notes = Note.order("created_at DESC")
9
+ redirect "/new" if @notes.empty?
10
+ erb :index
11
+ end
12
+
13
+ get "/new" do
14
+ erb :new
15
+ end
16
+
17
+ post "/new" do
18
+ @note = Note.new(params[:note])
19
+ if @note.save
20
+ redirect "note/#{@note.id}"
21
+ else
22
+ erb :new
23
+ end
24
+ end
25
+
26
+ get "/note/:id" do
27
+ @note = Note.find_by_id(params[:id])
28
+ erb :note
29
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ cd /opt/demo
4
+
5
+ source /etc/profile.d/rvm.sh
6
+
7
+ bundle exec rackup
data/demo/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require './app'
2
+
3
+ run Sinatra::Application
@@ -0,0 +1,14 @@
1
+ class CreateNotes < ActiveRecord::Migration
2
+ def up
3
+ create_table :notes do |t|
4
+ t.string :title
5
+ t.text :body
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def down
12
+ drop_table :notes
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ class AddNotes < ActiveRecord::Migration
2
+ def change
3
+ Note.create :title => "Title 1", :body => "some body 1"
4
+ Note.create :title => "Title 2", :body => "some body 2"
5
+ Note.create :title => "Title 3", :body => "some body 3"
6
+ end
7
+ end
data/demo/db/schema.rb ADDED
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20140610204302) do
15
+
16
+ # These are extensions that must be enabled in order to support this database
17
+ enable_extension "plpgsql"
18
+
19
+ create_table "notes", force: true do |t|
20
+ t.string "title"
21
+ t.text "body"
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ end
data/demo/db_setup.rb ADDED
@@ -0,0 +1,11 @@
1
+ postgresql_host = ENV['POSTGRESQL_HOST'].nil? ? 'localhost' : ENV['POSTGRESQL_HOST']
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ :adapter => 'postgresql',
5
+ :host => postgresql_host,
6
+ :username => 'ruby_dev',
7
+ :password => 'ruby_dev',
8
+ :database => 'ruby_dev_dev',
9
+ :port => "5432",
10
+ :encoding => 'utf8'
11
+ )
data/demo/note.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Note < ActiveRecord::Base
2
+ end
@@ -0,0 +1,8 @@
1
+ [supervisord]
2
+ nodaemon=true
3
+
4
+ [program:sshd]
5
+ command=/usr/sbin/sshd -D
6
+
7
+ [program:rackup]
8
+ command=/bin/bash -c "/opt/demo/bin/start-server.sh"
@@ -0,0 +1,10 @@
1
+ <h1>Notes</h1>
2
+ <ul>
3
+ <% @notes.each do |note| %>
4
+ <li>
5
+ <h2><a href="/note/<%= note.id %>"><%= note.title %></a></h2>
6
+ <p><%= note.body %></p>
7
+ </li>
8
+ <% end %>
9
+ </ul>
10
+ <a href="/new">New note</a>
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>Notes</title>
4
+ </head>
5
+ <body>
6
+ <%= yield %>
7
+ </body>
8
+ </html>
@@ -0,0 +1,12 @@
1
+ <h1>New Note</h1>
2
+ <form action="/new" method="post">
3
+ <label for="title">Title:</label><br />
4
+ <input id="title" name="note[title]" type="text" />
5
+ <br />
6
+
7
+ <label for="body">Body:</label><br />
8
+ <textarea id="body" name="note[body]" rows="10"></textarea>
9
+ <br />
10
+
11
+ <button type="submit">Save</button>
12
+ </form>
@@ -0,0 +1,3 @@
1
+ <h1><%= @note.title %></h1>
2
+ <p><%= @note.body %></p>
3
+ <a href="/">All notes</a>
@@ -0,0 +1,61 @@
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
+
@@ -0,0 +1,14 @@
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
+
@@ -0,0 +1,28 @@
1
+ # https://registry.hub.docker.com/u/dhrp/sshd/
2
+ # http://stackoverflow.com/questions/23014684/how-to-get-ssh-connection-with-docker-container-on-osxboot2docker
3
+
4
+ # sshd
5
+ #
6
+ # VERSION 0.0.1
7
+
8
+ FROM ubuntu
9
+ MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"
10
+
11
+ # make sure the package repository is up to date
12
+ RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
13
+ RUN apt-get update
14
+
15
+ RUN apt-get install -y openssh-server
16
+ RUN mkdir /var/run/sshd
17
+ RUN echo 'root:screencast' |chpasswd
18
+
19
+ EXPOSE 22
20
+
21
+ CMD /usr/sbin/sshd -D
22
+
23
+ # docker build -t sshd docker/sshd
24
+ # docker run -d -P --name sshd sshd
25
+
26
+ # docker port sshd 22
27
+ # boot2docker ip
28
+ # ssh root@192.168.59.104 -p 49153
@@ -0,0 +1,28 @@
1
+ # http://docs.docker.com/examples/using_supervisord/
2
+
3
+ FROM ubuntu:latest
4
+ MAINTAINER examples@docker.io
5
+
6
+ RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
7
+ RUN apt-get update
8
+ RUN apt-get upgrade -y
9
+
10
+ RUN apt-get install -y openssh-server apache2 supervisor
11
+ RUN mkdir -p /var/run/sshd
12
+ RUN mkdir -p /var/log/supervisor
13
+
14
+ RUN echo 'root:screencast' |chpasswd
15
+
16
+ ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
17
+
18
+ EXPOSE 22 80
19
+
20
+ CMD ["/usr/bin/supervisord"]
21
+
22
+
23
+ # docker build -t supervisord docker/supervisord
24
+ # docker run -p 22 -p 80 -t -i --name supervisord supervisord
25
+
26
+ # docker port sshd 22
27
+ # boot2docker ip
28
+ # ssh root@192.168.59.104 -p 49154
@@ -0,0 +1,8 @@
1
+ [supervisord]
2
+ nodaemon=true
3
+
4
+ [program:sshd]
5
+ command=/usr/sbin/sshd -D
6
+
7
+ [program:apache2]
8
+ command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
@@ -10,7 +10,7 @@ class GenericProvision
10
10
 
11
11
  attr_reader :interpolator, :env, :script_list, :server_info
12
12
 
13
- def initialize config_file_name, scripts_file_names
13
+ def initialize parent_class, config_file_name, scripts_file_names
14
14
  @interpolator = TextInterpolator.new
15
15
 
16
16
  @env = read_config(config_file_name)
@@ -21,30 +21,39 @@ class GenericProvision
21
21
  @script_list.merge!(scripts(name))
22
22
  end
23
23
 
24
- # create_script_methods parent, self
24
+ create_script_methods
25
+
26
+ create_thor_methods(parent_class) if parent_class.ancestors.include?(Thor)
25
27
 
26
28
  @server_info = env[:node] ? env[:node] : {}
27
29
  end
28
30
 
29
- # def create_script_methods parent, current
30
- # parent_metaclass = parent.singleton_class
31
- # current_metaclass = current.singleton_class
32
- #
33
- # current.script_list.keys.each do |name|
34
- # # create methods on parent, e.g. thor or rake file
35
- # parent_metaclass.send(:define_method, name.to_sym) do |*args, &block|
36
- # current.send(name, args, block)
37
- # end
38
- #
39
- # # create methods on installer
40
- # current_metaclass.send(:define_method, name.to_sym) do |_, _|
41
- # current.send :run, current.server_info, name.to_s, current.env
42
- # end
43
- # end
44
- # end
45
-
46
31
  protected
47
32
 
33
+ def create_script_methods
34
+ script_list.keys.each do |name|
35
+ singleton_class.send(:define_method, name.to_sym) do
36
+ self.send :run, server_info, name.to_s, env
37
+ end
38
+ end
39
+ end
40
+
41
+ def create_thor_methods parent_class
42
+ provision = self
43
+
44
+ provision.script_list.each do |name, value|
45
+ title = provision.script_title(value)
46
+
47
+ title = title.nil? ? name : title
48
+
49
+ parent_class.send(:desc, name, title) if parent_class.respond_to?(:desc)
50
+
51
+ parent_class.send(:define_method, name.to_sym) do
52
+ provision.send "#{name}".to_sym
53
+ end
54
+ end
55
+ end
56
+
48
57
  def read_config config_file_name
49
58
  hash = JSON.parse(File.read(config_file_name), :symbolize_names => true)
50
59