rbdock 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87ebf65d187e5af4dcec123c8d3939e029e0eb07
4
- data.tar.gz: cec4596d55f0455bebbb3fbfae105b728e34b176
3
+ metadata.gz: 6360827063092435950892991e08acb8e23a1843
4
+ data.tar.gz: 8ca404388d1a24a82901d1fd7f93206cc89c548b
5
5
  SHA512:
6
- metadata.gz: cbf2a52837f3426aef0c82202f899fafd1a7ca01322d4804c521b214bac1613176c6b4cc9a6cb402b1b8489729a2226b335d5e9fe6634d62778d8437660757f1
7
- data.tar.gz: ca929580895d3e9e1261339b56460628c692617de8b31a604f8bfcddab4672dae3f7a1036486d7195ff563b374daedacc44df230a502c7984557b7b980ba859c
6
+ metadata.gz: 6aa31f36757676489cbd1139ba1f98fd1518496c6d6c1a10ce58ad1753053c1949425d2b02c3ba890f2fad9d148afc0045402403bb56047cb9b9e3032ebb84df
7
+ data.tar.gz: 3eb3ebb1d5e6e29d9df8067c4da66c6af825b659f7ed412c61d1d2dee0a1179c39982d2eaac9afc7f00008726d9d6020b9ee1cb30583ed79021978ba09b238da
data/.gitignore CHANGED
@@ -17,4 +17,6 @@ test/version_tmp
17
17
  tmp
18
18
  Dockerfile
19
19
  .vagrant
20
- vendor/
20
+ vendor/
21
+ .rbdock_app
22
+ myapp/
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rbdock.png)](http://badge.fury.io/rb/rbdock)
4
4
 
5
- Generate Dockerfile to build ruby ready image.
5
+ Generate Dockerfile for Ruby or Rails, Sinatra.
6
+
7
+ Dockerfile to prepare ruby is almost common, so generate its common parts. This is still experimetal and under heavy construction.
6
8
 
7
9
  ## Installation
8
10
 
@@ -21,17 +23,46 @@ Or install it yourself as:
21
23
 
22
24
  ## Usage
23
25
 
26
+ ### Create Dockerfile to build ruby
27
+
24
28
  Create `Dockerfile` to build ruby 2.0.0-p353 ready image.
25
29
 
26
30
  ```
27
- $ rbdock create 2.0.0-p353
31
+ $ rbdock 2.1.0
32
+ ```
33
+
34
+ It generates this [Dockerfile](https://gist.github.com/tcnksm/9388685).
35
+
36
+ You can create `Dockerfile` to build multiple versions of ruby by rbenv or rvm.
37
+
38
+ ```
39
+ $ rbdock 2.0.0-p353 1.9.3-p484 -i centos
28
40
  ```
29
41
 
30
- You can create `Dockerfile` to build multiple versions of ruby.
42
+ It generates this [Dockerfile](https://gist.github.com/tcnksm/9388736).
43
+
44
+
45
+ ### Create Dockerfile for rails/sinatra application
46
+
47
+ For example, you can work with rails application developed on local environment.
48
+
49
+ ```
50
+ $ rails new my_rails_app
51
+ $ rbdock 2.1.0 --app my_rails_app --rbenv
52
+ $ docker build -t tcnksm/rails_app .
53
+ $ docker run -i -p 3000:3000 -t tcnksm/rails_app 'rails server'
54
+ ```
55
+
56
+ It generates this [Dockerfile](https://gist.github.com/tcnksm/9389036).
57
+
58
+ You can work with application hosted on remote repository. For example, this is my sinatra application hosted on github.
31
59
 
32
60
  ```
33
- $ rbdock create 2.0.0-p353 1.9.3-p484
61
+ $ rbdock 2.0.0-p353 --app https://github.com/tcnksm/trying-space
62
+ $ docker build -t tcnksm/sinatra_app .
63
+ $ docker run -i -p 8080:8080 -t tcnksm/my_sinatra_app 'rackup -p 8080'
34
64
  ```
65
+ It generates this [Dockerfile](https://gist.github.com/tcnksm/9389116). Your application will be cloned to local directory (`.rbdock_app`) and `ADD` to docker image.
35
66
 
36
67
  ### Options
37
68
 
@@ -40,6 +71,7 @@ $ rbdock create 2.0.0-p353 1.9.3-p484
40
71
  |--image `name`| Set base image. Now `ubuntu` or `cenos` is avalable. Default is `ubuntu`.|
41
72
  |--rbenv| Use [rbenv](https://github.com/sstephenson/rbenv) to manage ruby installation|
42
73
  |--rvm | Use [rvm](https://github.com/wayneeseguin/rvm) to manage ruby installation|
74
+ |--app `url` | Add Rails/Sinatra application. You can set local path or remote host|
43
75
  |--list | List all available ruby versions.|
44
76
 
45
77
 
@@ -1,20 +1,8 @@
1
- # -*- mode: ruby -*-
2
- # vi: set ft=ruby :
3
-
4
- DOCKER_URL = "192.168.50.4"
5
- DOCKER_PORT = 5422
6
-
7
1
  Vagrant.configure("2") do |config|
8
2
  config.vm.box = "precise64"
9
3
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
10
- config.vm.network :private_network, ip: DOCKER_URL
4
+ config.vm.network :private_network, ip: "192.168.50.4"
11
5
  config.vm.provision :docker do |d|
12
6
  d.pull_images "ubuntu"
13
- d.pull_images "centos"
14
- end
15
- config.vm.provision :shell, :inline => <<-PREPARE
16
- sudo sed -i -e 's/DOCKER_OPTS=/DOCKER_OPTS=\"-H 0.0.0.0:#{DOCKER_PORT}\"/g' /etc/init/docker.conf
17
- sudo service docker stop
18
- sudo service docker start
19
- PREPARE
7
+ end
20
8
  end
@@ -2,6 +2,5 @@ require "rbdock/helpers"
2
2
  require "rbdock/version"
3
3
  module Rbdock
4
4
  autoload :Command, "rbdock/command"
5
- # sub commands
6
- autoload :Create, "rbdock/create"
5
+ autoload :Generate, "rbdock/generate"
7
6
  end
@@ -12,13 +12,11 @@ module Rbdock
12
12
  end
13
13
 
14
14
  def execute
15
- options = Options.parse!(@argv)
16
- sub_command = options.delete(:command)
17
-
18
- case sub_command
19
- when 'create'
20
- Rbdock::Create.run(options)
15
+ options = Options.parse!(@argv)
16
+ if options[:app]
17
+ options[:app_path] = Rbdock.clone_app_to_local(options[:app])
21
18
  end
19
+ Rbdock::Generate.run(options)
22
20
  rescue => e
23
21
  abort "Error: #{e.message}"
24
22
  end
@@ -7,96 +7,85 @@ module Rbdock
7
7
  def self.parse!(argv)
8
8
  options = {}
9
9
 
10
- command_parser = create_command_parser
11
- sub_command_parser = create_sub_command_parser(options)
10
+ set_default_value options
11
+ command_parser = create_command_parser options
12
12
 
13
13
  begin
14
- command_parser.order!(argv)
15
- options[:command] = argv.shift
16
- sub_command_parser[options[:command]].parse!(argv)
14
+ command_parser.parse!(argv)
17
15
  ruby_version_perser options, argv
18
16
  rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
19
17
  abort e.message
20
18
  end
21
-
19
+
22
20
  options
23
21
  end
24
22
 
25
- def self.create_command_parser
23
+ def self.set_default_value options
24
+ options[:image] = "ubuntu"
25
+ end
26
+
27
+ def self.create_command_parser options
26
28
  OptionParser.new do |opt|
27
- opt.on_head('-v','--version','Show version') {
28
- opt.version = Rbdock::VERSION
29
- STDERR.puts opt.ver
30
- exit
31
- }
29
+ show_version opt
30
+ show_help opt
32
31
 
33
- opt.banner = "Usage: #{opt.program_name} [-h|--help] [-v|--version] <command> [<args>]"
34
- opt.separator ''
35
- opt.separator "#{opt.program_name} Available Commands:"
36
- sub_command_help.each do |command|
37
- opt.separator [opt.summary_indent, command[:name].ljust(40), command[:summary]].join(' ')
38
- end
39
- opt.on_head('-h','--help','Show this message') {
40
- STDERR.puts opt.help
41
- exit
32
+ opt.on('-i name','--image=name', 'Set image name(ubuntu|centos)') { |v|
33
+ options[:image] = v
34
+ }
35
+ opt.on('--rbenv', desc='Use rbenv') {
36
+ options[:use_rbenv] = true
37
+ }
38
+ opt.on('--rvm', desc='Use rvm') {
39
+ options[:use_rvm] = true
40
+ }
41
+ opt.on('-a path','--app=path', 'Add Rails/Sinatra app') { |path|
42
+ options[:app] = path
42
43
  }
44
+ opt.on('-l','--list', 'List all available ruby versions') {
45
+ list_ruby_versions
46
+ }
43
47
  end
44
48
  end
45
49
 
46
- def self.create_sub_command_parser options
47
- parser = Hash.new do |k,v|
48
- raise ArgumentError, "'#{v}' is not sub command."
49
- end
50
-
51
- parser['create'] = OptionParser.new do |opt|
52
- options[:image] = "ubuntu" # default value
53
- opt.banner = 'Usage: create <ruby-versions> [<args>]'
54
- opt.on('-i name','--image=name', 'Set image name(ubuntu|centos)') { |val|
55
- options[:image] = val
56
- }
57
- opt.on('--rbenv', desc='Use rbenv') {|f| options[:use_rbenv] = true }
58
- opt.on('--rvm', desc='Use rvm') {|f| options[:use_rvm] = true }
59
- opt.on('-l','--list', 'List all available ruby versions') { list_ruby_versions }
60
- opt.on_tail('-h','--help', 'Show this message') { help_sub_command(opt) }
61
- end
62
-
63
- parser
50
+ def self.show_version opt
51
+ opt.on_tail('-v','--version','Show version') {
52
+ opt.version = Rbdock::VERSION
53
+ STDERR.puts opt.ver
54
+ exit
55
+ }
56
+ end
57
+
58
+ def self.show_help opt
59
+ opt.banner = "Usage: #{opt.program_name} <ruby-versions> [<args>]"
60
+ opt.on_tail('-h','--help','Show this message') {
61
+ STDERR.puts opt.help
62
+ exit
63
+ }
64
64
  end
65
65
 
66
66
  def self.ruby_version_perser options, argv
67
- if options[:command] == 'create'
68
- raise ArgumentError, "#{options[:command]} ruby versions not founnd." if argv.empty?
69
- check_version_avaiable argv
70
- options[:ruby_versions] = argv
71
- end
67
+ raise ArgumentError, "#{options[:command]} ruby versions not found." if argv.empty?
68
+ check_version_avaiable argv
69
+ options[:ruby_versions] = argv
72
70
  options
73
71
  end
74
72
 
75
73
  def self.check_version_avaiable argv
76
74
  argv.each do |v|
77
- if not Rbdock::Create.ruby_versions.include? v
78
- raise ArgumentError, "Definition not found: #{v} \n\nYou can list all available ruby versions with `rbdock create --list'."
75
+ if not Rbdock::Generate.ruby_versions.include? v
76
+ raise ArgumentError, "Definition not found: #{v} \n\nYou can list all available ruby versions with `rbdock --list'."
79
77
  end
80
78
  end
81
79
  end
82
80
 
83
81
  def self.list_ruby_versions
84
82
  STDERR.print "Available versions:\n "
85
- STDERR.print Rbdock::Create.ruby_versions.join("\n ")
83
+ STDERR.print Rbdock::Generate.ruby_versions.join("\n ")
86
84
  STDERR.puts
87
85
  exit
88
86
  end
89
-
90
- def self.help_sub_command parser
91
- STDERR.puts parser.help
92
- exit
93
- end
94
-
95
- def self.sub_command_help
96
- [
97
- {name: 'create <ruby-versions> -i <image>', summary: 'Generate Dockerfile which installs <ruby-versions>'}
98
- ]
99
- end
87
+
100
88
  end
101
89
  end
102
90
  end
91
+
@@ -2,10 +2,10 @@ require "erubis"
2
2
 
3
3
  module Rbdock
4
4
 
5
- class Create
5
+ class Generate
6
6
 
7
7
  def self.run options
8
- new(options).generate
8
+ new(options).execute
9
9
  end
10
10
 
11
11
  def initialize options
@@ -13,15 +13,15 @@ module Rbdock
13
13
  @ruby_versions = options[:ruby_versions]
14
14
  @use_rbenv = options[:use_rbenv]
15
15
  @use_rvm = options[:use_rvm]
16
+ @app_path = options[:app_path]
16
17
  end
17
18
 
18
- def generate
19
+ def execute
19
20
  if @use_rbenv
20
21
  safe_write rbenv_template
21
22
  elsif @use_rvm
22
23
  safe_write rvm_template
23
24
  elsif mutiple_rubies?
24
- # Use rbenv for default installing multiple rubies
25
25
  safe_write rbenv_template
26
26
  else
27
27
  safe_write default_template
@@ -51,37 +51,35 @@ module Rbdock
51
51
  @ruby_versions.length > 1
52
52
  end
53
53
 
54
+ def erubis template_path
55
+ Erubis::Eruby.new(template_path.read, trim: true).result(binding)
56
+ end
57
+
58
+ def base_package_template
59
+ erubis Rbdock.source_root.join("templates/base_package/#{@image}.erb")
60
+ end
61
+
54
62
  def default_template
55
- template_path = Rbdock.source_root.join("templates/#{@image}_base_packages.erb")
56
- template = Erubis::Eruby.new(template_path.read, trim: true).result(binding)
57
-
58
- template_path = Rbdock.source_root.join("templates/ruby.erb")
59
- template << Erubis::Eruby.new(template_path.read, trim: true).result(binding)
60
-
61
- template_path = Rbdock.source_root.join("templates/bundler.erb")
62
- template << Erubis::Eruby.new(template_path.read, trim: true).result(binding)
63
+ template = base_package_template
64
+ template << erubis(Rbdock.source_root.join("templates/default/ruby.erb"))
65
+ template << erubis(Rbdock.source_root.join("templates/default/bundler.erb"))
66
+ template << erubis(Rbdock.source_root.join("templates/default/app.erb")) if @app_path
67
+ template
63
68
  end
64
69
 
65
70
  def rbenv_template
66
- template_path = Rbdock.source_root.join("templates/#{@image}_base_packages.erb")
67
- template = Erubis::Eruby.new(template_path.read, trim: true).result(binding)
68
-
69
- template_path = Rbdock.source_root.join("templates/rbenv_ruby.erb")
70
- template << Erubis::Eruby.new(template_path.read, trim: true).result(binding)
71
-
72
- template_path = Rbdock.source_root.join("templates/rbenv_bundler.erb")
73
- template << Erubis::Eruby.new(template_path.read, trim: true).result(binding)
71
+ template = base_package_template
72
+ template << erubis(Rbdock.source_root.join("templates/rbenv/ruby.erb"))
73
+ template << erubis(Rbdock.source_root.join("templates/rbenv/bundler.erb"))
74
+ template << erubis(Rbdock.source_root.join("templates/rbenv/app.erb")) if @app_path
75
+ template
74
76
  end
75
77
 
76
78
  def rvm_template
77
- template_path = Rbdock.source_root.join("templates/#{@image}_base_packages.erb")
78
- template = Erubis::Eruby.new(template_path.read, trim: true).result(binding)
79
-
80
- template_path = Rbdock.source_root.join("templates/rvm_ruby.erb")
81
- template << Erubis::Eruby.new(template_path.read, trim: true).result(binding)
82
-
83
- template_path = Rbdock.source_root.join("templates/rvm_bundler.erb")
84
- template << Erubis::Eruby.new(template_path.read, trim: true).result(binding)
79
+ template = base_package_template
80
+ template << erubis(Rbdock.source_root.join("templates/rvm/ruby.erb"))
81
+ template << erubis(Rbdock.source_root.join("templates/rvm/bundler.erb"))
82
+ template << erubis(Rbdock.source_root.join("templates/rvm/app.erb")) if @app_path
85
83
  end
86
84
 
87
85
  def self.ruby_versions
@@ -1,7 +1,76 @@
1
1
  require "pathname"
2
+ require "uri"
2
3
 
3
4
  module Rbdock
4
- def self.source_root
5
- @source_root ||= Pathname.new(File.expand_path('../../../', __FILE__))
6
- end
5
+
6
+ class << self
7
+
8
+ def source_root
9
+ @source_root ||= Pathname.new(File.expand_path('../../../', __FILE__))
10
+ end
11
+
12
+ def clone_app_to_local url
13
+ raise StandardError, "command git not found." if `which git`.empty?
14
+
15
+ if local? url
16
+ if not File.exist?(File.join(source_root, url))
17
+ raise StandardError, "#{url} is not exit"
18
+ end
19
+
20
+ return url
21
+ end
22
+
23
+ if not already_cloned?
24
+ return exec_clone url
25
+ end
26
+
27
+ if already_cloned? and same_app?(url)
28
+ return update_app url
29
+ end
30
+
31
+ return replace_app url
32
+ end
33
+
34
+ def default_app_path
35
+ '.rbdock_app'
36
+ end
37
+
38
+ private
39
+
40
+ def local? url
41
+ not URI.regexp =~ url
42
+ end
43
+
44
+ def exec_clone url
45
+ if not system("git clone -q #{url} #{default_app_path}")
46
+ raise StandardError, "clone #{url} is failed. Check url."
47
+ end
48
+ STDERR.puts "Clone #{url} to #{default_app_path}/"
49
+ default_app_path
50
+ end
51
+
52
+ def replace_app url
53
+ system("rm -fr #{default_app_path}")
54
+ exec_clone url
55
+ STDERR.puts "Delete old app and clone #{url} to #{default_app_path}/"
56
+ default_app_path
57
+ end
58
+
59
+ def update_app url
60
+ if not system("cd #{default_app_path}; git pull -q")
61
+ raise StandardError, "clone #{url} is failed. Check url."
62
+ end
63
+ STDERR.puts "Update #{url}"
64
+ default_app_path
65
+ end
66
+
67
+ def already_cloned?
68
+ File.exist? default_app_path
69
+ end
70
+
71
+ def same_app? url
72
+ url == `git --git-dir=.rbdock_app/.git config --get remote.origin.url`.chomp
73
+ end
74
+
75
+ end
7
76
  end
@@ -1,3 +1,3 @@
1
1
  module Rbdock
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -5,6 +5,6 @@ RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.
5
5
  RUN yum -y update
6
6
  RUN yum install -y make gcc gcc-c++ wget curl git
7
7
  RUN yum install -y openssl-devel zlib-devel readline-devel libffi-devel httpd-devel libyaml-devel
8
- RUN yum install -y bzip2 autoconf automake libtool bison iconv-devel
8
+ RUN yum install -y bzip2 autoconf automake libtool bison iconv-devel ruby-devel
9
9
  RUN yum --enablerepo=epel -y install libyaml-devel
10
10
 
@@ -4,6 +4,6 @@ FROM ubuntu
4
4
  RUN apt-get update
5
5
  RUN apt-get install -y build-essential wget curl git
6
6
  RUN apt-get install -y zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev
7
- RUN apt-get install sqlite3 libsqlite3-dev
7
+ RUN apt-get install -y sqlite3 libsqlite3-dev
8
8
  RUN apt-get clean
9
9
 
@@ -0,0 +1,9 @@
1
+ # Add application
2
+ RUN mkdir /myapp
3
+ WORKDIR /myapp
4
+ ADD <%= @app_path %>/Gemfile /myapp/Gemfile
5
+ RUN bundle install
6
+ ADD <%= @app_path %> /myapp
7
+
8
+ ENTRYPOINT ["bash", "-l", "-c"]
9
+
@@ -1,3 +1,4 @@
1
1
  # Install bundler
2
2
  RUN gem update --system
3
3
  RUN gem install bundler --no-rdoc --no-ri
4
+
@@ -0,0 +1,8 @@
1
+ # Install ruby-build
2
+ RUN git clone https://github.com/sstephenson/ruby-build.git .ruby-build
3
+ RUN .ruby-build/install.sh
4
+ RUN rm -fr .ruby-build
5
+
6
+ # Install ruby-<%=@ruby_versions[0] %>
7
+ RUN ruby-build <%= @ruby_versions[0] %> /usr/local
8
+
@@ -0,0 +1,8 @@
1
+ # Add Application
2
+ RUN mkdir /myapp
3
+ WORKDIR /myapp
4
+ ADD <%= @app_path %>/Gemfile /myapp/Gemfile
5
+ RUN bash -l -c 'bundle install'
6
+ ADD <%= @app_path %> /myapp
7
+
8
+ ENTRYPOINT ["bash", "-l", "-c"]
@@ -0,0 +1,8 @@
1
+ # Add Application
2
+ RUN mkdir /myapp
3
+ WORKDIR /myapp
4
+ ADD <%= @app_path %>/Gemfile /myapp/Gemfile
5
+ RUN bash -l -c 'bundle install'
6
+ ADD <%= @app_path %> /myapp
7
+
8
+ ENTRYPOINT ["bash", "-l", "-c"]
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbdock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tcnksm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -128,19 +128,22 @@ files:
128
128
  - lib/rbdock.rb
129
129
  - lib/rbdock/command.rb
130
130
  - lib/rbdock/command/options.rb
131
- - lib/rbdock/create.rb
131
+ - lib/rbdock/generate.rb
132
132
  - lib/rbdock/helpers.rb
133
133
  - lib/rbdock/version.rb
134
134
  - rbdock.gemspec
135
135
  - spec/spec_helper.rb
136
- - templates/bundler.erb
137
- - templates/centos_base_packages.erb
138
- - templates/rbenv_bundler.erb
139
- - templates/rbenv_ruby.erb
140
- - templates/ruby.erb
141
- - templates/rvm_bundler.erb
142
- - templates/rvm_ruby.erb
143
- - templates/ubuntu_base_packages.erb
136
+ - templates/base_package/centos.erb
137
+ - templates/base_package/ubuntu.erb
138
+ - templates/default/app.erb
139
+ - templates/default/bundler.erb
140
+ - templates/default/ruby.erb
141
+ - templates/rbenv/app.erb
142
+ - templates/rbenv/bundler.erb
143
+ - templates/rbenv/ruby.erb
144
+ - templates/rvm/app.erb
145
+ - templates/rvm/bundler.erb
146
+ - templates/rvm/ruby.erb
144
147
  homepage: https://github.com/tcnksm/rbdock
145
148
  licenses:
146
149
  - MIT
@@ -1,5 +0,0 @@
1
- # Install ruby
2
- RUN wget -P /root/src ftp://ftp.ruby-lang.org/pub/ruby/ruby-<%= @ruby_versions[0] %>.tar.gz
3
- RUN cd /root/src; tar xvf ruby-<%= @ruby_versions[0] %>.tar.gz
4
- RUN cd /root/src/ruby-<%= @ruby_versions[0] %>; ./configure --disable-install-doc; make install
5
-