dockerify 0.0.1
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 +7 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +7 -0
- data/bin/dockerify +4 -0
- data/dockerify.gemspec +27 -0
- data/lib/dockerify.rb +3 -0
- data/lib/dockerify/cli.rb +52 -0
- data/lib/dockerify/dockerify.rb +89 -0
- data/lib/dockerify/templates/.env.erb +4 -0
- data/lib/dockerify/templates/Dockerfile.erb +38 -0
- data/lib/dockerify/templates/docker-compose.yml.erb +12 -0
- data/lib/dockerify/templates/rails-env.conf.erb +4 -0
- data/lib/dockerify/version.rb +3 -0
- data/test/lib/dockerify/dockerify_test.rb +17 -0
- data/test/test_helper.rb +5 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a47945152534059212987f4f01853c0e3970f0f
|
4
|
+
data.tar.gz: 2fe2407b6219c1c684c1c0f4d64d3cfa8ffb6e81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f925bd6c52f0f195a21e517e7e296e4c2ffde2579d944c1b9ecd8399e15d29a5300760156b5fc26c3722920cbb10407af2c007668921829c4a62630f9bbbd4db
|
7
|
+
data.tar.gz: dabdc6e07d0b09ae1f2f479ceb1f00c5d21d4ec8fbeb0352e4501ef3e93d819bd0c4bbdc7ed818fccd6d7bbad01dc0bb31abbc15996f94835f1049b78ee30017
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Chris Butcher
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Dockerify
|
2
|
+
|
3
|
+
A Ruby gem to generate Docker configuration files based on Phusion's Passenger Docker containers
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dockerify'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dockerify
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```bash
|
24
|
+
dockerify new # to create Docker configuration files
|
25
|
+
dockerify remove # to remove them
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it ( https://github.com/[my-github-username]/dockerify/fork )
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create a new Pull Request
|
35
|
+
|
36
|
+
# Thanks
|
37
|
+
* http://www.michaelrigart.be/en/blog/a-simple-ruby-command-line-tool.html
|
data/Rakefile
ADDED
data/bin/dockerify
ADDED
data/dockerify.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dockerify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dockerify"
|
8
|
+
spec.version = Dockerify::VERSION
|
9
|
+
spec.authors = ["Christopher Butcher"]
|
10
|
+
spec.email = ["cbutcher@gmail.com"]
|
11
|
+
spec.summary = %q{A Ruby gem to generate Docker and Docker Compose configuration files to utilize Phusion's Passenger Docker containers}
|
12
|
+
spec.description = %q{This gem is intended to help you generate Docker and Docker Compose configuration files, to simply host web apps using Phusion's Passenger Docker containers}
|
13
|
+
spec.homepage = "https://github.com/chrisbutcher/dockerify"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'thor', "~> 0.19"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency 'minitest', "~> 5"
|
26
|
+
spec.add_development_dependency 'mocha', "1.1"
|
27
|
+
end
|
data/lib/dockerify.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Dockerify
|
4
|
+
class Cli < Thor
|
5
|
+
|
6
|
+
desc 'new PATH', 'Generates a Dockerfile and associated files TODO'
|
7
|
+
def new(path = '.')
|
8
|
+
result = runner.build(path)
|
9
|
+
unless result.compact.empty?
|
10
|
+
puts result
|
11
|
+
puts production_db_instruction
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'remove PATH', 'Removes the Dockerfile and associated files (requires confirmation) TODO'
|
16
|
+
def remove(path = '.')
|
17
|
+
puts "This command will remove the files: Dockerfile, etc."
|
18
|
+
result = yes?("Are you sure?")
|
19
|
+
if result
|
20
|
+
result = runner.remove(path)
|
21
|
+
if result.compact.empty?
|
22
|
+
puts "No Dockerify-related files found."
|
23
|
+
else
|
24
|
+
puts result
|
25
|
+
end
|
26
|
+
else
|
27
|
+
puts "Aborting"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def runner
|
34
|
+
Dockerify::Runner.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def production_db_instruction
|
38
|
+
<<-EOF
|
39
|
+
Copy the following values to your config/database.yml file.
|
40
|
+
|
41
|
+
production:
|
42
|
+
adapter: postgresql
|
43
|
+
encoding: unicode
|
44
|
+
database: postgres
|
45
|
+
pool: 5
|
46
|
+
username: postgres
|
47
|
+
password:
|
48
|
+
host: db
|
49
|
+
EOF
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'erb'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Dockerify
|
6
|
+
class Runner
|
7
|
+
DOCKERIFY_CONFIGS = [
|
8
|
+
{
|
9
|
+
filename: 'Dockerfile',
|
10
|
+
default_args: {
|
11
|
+
passenger_ruby_version: 'ruby22',
|
12
|
+
passenger_container_version: 'latest',
|
13
|
+
passenger_port_number: '80',
|
14
|
+
passenger_app_path: '/home/app/webapp'
|
15
|
+
}
|
16
|
+
},
|
17
|
+
{
|
18
|
+
filename: 'docker-compose.yml',
|
19
|
+
default_args: {
|
20
|
+
docker_compose_port: '80',
|
21
|
+
docker_compose_database_image: 'postgres'
|
22
|
+
}
|
23
|
+
},
|
24
|
+
{
|
25
|
+
filename: '.env',
|
26
|
+
default_args: {
|
27
|
+
env_secret_key_base: 'TODO'
|
28
|
+
}
|
29
|
+
},
|
30
|
+
{
|
31
|
+
filename: 'rails-env.conf',
|
32
|
+
default_args: {}
|
33
|
+
}
|
34
|
+
].freeze
|
35
|
+
|
36
|
+
def build(path)
|
37
|
+
absolute_path = full_path(path)
|
38
|
+
|
39
|
+
DOCKERIFY_CONFIGS.map do |dockerify_config|
|
40
|
+
file_path = "#{absolute_path}/#{dockerify_config[:filename]}"
|
41
|
+
|
42
|
+
if File.exists?(file_path)
|
43
|
+
puts "Skipping #{file_path}. File already exists"
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
raw_template = load_template(dockerify_config[:filename])
|
48
|
+
erb_args = dockerify_config[:default_args].merge({})
|
49
|
+
|
50
|
+
rendered_template = render_erb(raw_template, erb_args)
|
51
|
+
write_file(file_path, rendered_template)
|
52
|
+
"Creating #{dockerify_config[:filename]} etc in #{file_path}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def remove(path)
|
57
|
+
absolute_path = full_path(path)
|
58
|
+
|
59
|
+
DOCKERIFY_CONFIGS.map do |dockerify_config|
|
60
|
+
file_path = "#{absolute_path}/#{dockerify_config[:filename]}"
|
61
|
+
next unless File.exists?(file_path)
|
62
|
+
File.delete(file_path)
|
63
|
+
"Deleting #{dockerify_config[:filename]} etc in #{file_path}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def render_erb(template, vars)
|
70
|
+
renderer = ERB.new(template)
|
71
|
+
renderer.result(OpenStruct.new(vars).instance_eval { binding })
|
72
|
+
end
|
73
|
+
|
74
|
+
def load_template(template_name)
|
75
|
+
filename = File.dirname(__FILE__) + "/templates/#{template_name}.erb"
|
76
|
+
File.read(filename)
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_file(filepath, contents)
|
80
|
+
File.open(filepath, 'w') do |f|
|
81
|
+
f.write(contents)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def full_path(relative_path)
|
86
|
+
File.expand_path(relative_path)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
FROM phusion/passenger-<%= passenger_ruby_version %>:<%= passenger_container_version %>
|
2
|
+
|
3
|
+
# Set correct environment variables.
|
4
|
+
ENV HOME /root
|
5
|
+
|
6
|
+
# Use baseimage-docker's init system.
|
7
|
+
CMD ["/sbin/my_init"]
|
8
|
+
|
9
|
+
# Expose Nginx HTTP service
|
10
|
+
EXPOSE <%= passenger_port_number %>
|
11
|
+
|
12
|
+
# Start Nginx / Passenger
|
13
|
+
RUN rm -f /etc/service/nginx/down
|
14
|
+
|
15
|
+
# Remove the default site
|
16
|
+
RUN rm /etc/nginx/sites-enabled/default
|
17
|
+
|
18
|
+
# Add the nginx site and config
|
19
|
+
ADD nginx.conf /etc/nginx/sites-enabled/webapp.conf
|
20
|
+
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
|
21
|
+
|
22
|
+
# Install bundle of gems
|
23
|
+
WORKDIR /tmp
|
24
|
+
ADD Gemfile /tmp/
|
25
|
+
ADD Gemfile.lock /tmp/
|
26
|
+
RUN bundle install
|
27
|
+
|
28
|
+
# Add the Rails app
|
29
|
+
ENV APP_HOME <%= passenger_app_path %>
|
30
|
+
RUN mkdir $APP_HOME
|
31
|
+
WORKDIR $APP_HOME
|
32
|
+
ADD . $APP_HOME
|
33
|
+
|
34
|
+
# Rails-specific setup
|
35
|
+
RUN rake assets:precompile
|
36
|
+
|
37
|
+
# Clean up APT and bundler when done.
|
38
|
+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DockerifyTest < MiniTest::Test
|
4
|
+
def test_do_build
|
5
|
+
File.stubs(exists?: false)
|
6
|
+
Dockerify::Runner.any_instance.stubs(:write_file)
|
7
|
+
|
8
|
+
expected_output = [
|
9
|
+
"Creating Dockerfile etc in /tmp/Dockerfile",
|
10
|
+
"Creating docker-compose.yml etc in /tmp/docker-compose.yml",
|
11
|
+
"Creating .env etc in /tmp/.env",
|
12
|
+
"Creating rails-env.conf etc in /tmp/rails-env.conf"
|
13
|
+
]
|
14
|
+
|
15
|
+
assert_equal expected_output, Dockerify::Runner.new.build('/tmp')
|
16
|
+
end
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dockerify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Butcher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.19'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.19'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
description: This gem is intended to help you generate Docker and Docker Compose configuration
|
84
|
+
files, to simply host web apps using Phusion's Passenger Docker containers
|
85
|
+
email:
|
86
|
+
- cbutcher@gmail.com
|
87
|
+
executables:
|
88
|
+
- dockerify
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/dockerify
|
98
|
+
- dockerify.gemspec
|
99
|
+
- lib/dockerify.rb
|
100
|
+
- lib/dockerify/cli.rb
|
101
|
+
- lib/dockerify/dockerify.rb
|
102
|
+
- lib/dockerify/templates/.env.erb
|
103
|
+
- lib/dockerify/templates/Dockerfile.erb
|
104
|
+
- lib/dockerify/templates/docker-compose.yml.erb
|
105
|
+
- lib/dockerify/templates/rails-env.conf.erb
|
106
|
+
- lib/dockerify/version.rb
|
107
|
+
- test/lib/dockerify/dockerify_test.rb
|
108
|
+
- test/test_helper.rb
|
109
|
+
homepage: https://github.com/chrisbutcher/dockerify
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.4.5
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: A Ruby gem to generate Docker and Docker Compose configuration files to utilize
|
133
|
+
Phusion's Passenger Docker containers
|
134
|
+
test_files:
|
135
|
+
- test/lib/dockerify/dockerify_test.rb
|
136
|
+
- test/test_helper.rb
|