dckerize 0.2.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e327ff0b2bc1abdea3a2386231b0077c5ef83ec9
4
+ data.tar.gz: 9f3c06125564f73841992c9ad1ce5f36f4f3985e
5
+ SHA512:
6
+ metadata.gz: 76d90d00c9a4af403648924777ef400e3ff095006bfd72ee9ff50ffaa84a0586eaafca8e8f6bf154f5f5e9ec79c3106132a38b66f51e29cd692027cedfef2784
7
+ data.tar.gz: 32e6e46e2834254a71e77b9e43efcccff72df9a98755b8f4aeaeaf34e95b86eeed51a8a962e6a7f090ae4873835675abc8e71a879f7a284377f6557b7425512f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dckerize.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Pablo Acuña
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Dckerize
2
+ [![Gem Version](https://badge.fury.io/rb/dckerize.svg)](http://badge.fury.io/rb/dckerize)
3
+
4
+ Supercharged Rails development using Docker and Vagrant
5
+
6
+ ## Description
7
+
8
+ This gem gives you a good starting point for developing your Rails application using containers managed by Docker
9
+ inside of a VM managed by Vagrant (video demo at the end of the readme).
10
+
11
+ You'll get
12
+
13
+ - An ubuntu trusty image already provisioned with Docker and Docker Compose.
14
+ - An nginx/passenger container environment for serving your application and all the necessary configurations.
15
+ - A separate container running MySQL/postgres for your DB.
16
+ - A separate container for keeping your data using the data-only container pattern.
17
+
18
+ ## Requirements
19
+
20
+ - Ruby and Bundler
21
+ - Vagrant >= 1.6
22
+
23
+ ## Installation
24
+
25
+ $ gem install dckerize
26
+
27
+ ## Usage
28
+
29
+ You need to have a Rails application already created.
30
+
31
+ In the root of your application run:
32
+
33
+ $ dckerize up APP_NAME --database=[mysql|postgres]
34
+
35
+ Where APP_NAME should be the same name of your application and you must specify the database
36
+ that you want to use.
37
+
38
+ ### Generated Structure
39
+
40
+ Dckerize will generate:
41
+
42
+ - A Vagrant folder, which contains a Vagrantfile and a docker-compose-installer bash script for provisioning.
43
+ - A conf folder containing an nginx configuration file for your site and an environment definition file for passing
44
+ the necessary environment variables to passenger. Any extra environment variables passed to your Rails application
45
+ should be declared in this file.
46
+ - A Dockerfile for building your application.
47
+ - A docker-compose.yml file for starting your entire enviroment inside the VM.
48
+
49
+ ### DB configuration
50
+
51
+ ## MySQL
52
+ In your config/database.yml add these lines to your configuration:
53
+
54
+ username: root
55
+ password: <%= ENV['MYSQL_ENV_MYSQL_ROOT_PASSWORD'] %>
56
+ host: mysql
57
+
58
+ ## Postgres
59
+ In your config/database.yml add these lines to your configuration:
60
+
61
+ user: postgres
62
+ password: <%= ENV['POSTGRES_ENV_POSTGRES_PASSWORD'] %>
63
+ host: postgres
64
+
65
+ ### Developing
66
+
67
+ Go inside the generated vagrant folder and run
68
+
69
+ $ vagrant up
70
+
71
+ Vagrant will pull the ubuntu trusty image, the necessary docker images and set the shared folder for
72
+ development.
73
+
74
+ Once finished, run
75
+
76
+ $ vagrant ssh
77
+ $ cd /APP_NAME
78
+ $ sudo docker-compose up -d
79
+
80
+ Since the folder is being shared with the virtual machine, you can run docker-compose using the docker-compose.yml file.
81
+ This will build the container for your application, the db and the links between the containers.
82
+
83
+ The application folder will also be mounted inside the container, so you can work as you normally do locally and see the changes
84
+ reflected immediately inside the container.
85
+
86
+ Now you can go inside the container and run the typical Rails commands for interacting with your application.
87
+
88
+ To get the app container's name run:
89
+
90
+ $ docker ps
91
+
92
+ This will show you all the running containers. Choose the one that's running your app and go inside by executing:
93
+
94
+ $ docker exec -it CONTAINER_NAME bash
95
+
96
+ Now you can interact with your application
97
+
98
+ $ rake db:create
99
+ $ rake db:migrate
100
+ $ rails c
101
+
102
+ And etc.
103
+
104
+ The nginx container is mapping its port 80 with the port 80 of the guest host, and since we're declaring a private network in our Vagranfile
105
+ you can access your application by visiting http://192.168.50.4.
106
+
107
+ ## Video demo
108
+
109
+ [![Dckerize](http://img.youtube.com/vi/X8IVAoBUtbs/0.jpg)](http://www.youtube.com/watch?v=X8IVAoBUtbs)
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it ( https://github.com/pacuna/dckerize/fork )
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Push to the branch (`git push origin my-new-feature`)
117
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dckerize"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/dckerize.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dckerize/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dckerize"
8
+ spec.version = Dckerize::VERSION
9
+ spec.authors = ["Pablo Acuña"]
10
+ spec.email = ["pabloacuna88@gmail.com"]
11
+
12
+ spec.summary = %q{Supercharged Rails environment using Docker and Vagrant.}
13
+ spec.homepage = "https://github.com/pacuna/dckerize"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib", "templates"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.8"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
data/exe/dckerize ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "dckerize"
4
+
5
+ up_command = ARGV[0]
6
+ app_name = ARGV[1]
7
+ db_name = ARGV[2]
8
+
9
+ if up_command.to_s != 'up' || app_name.to_s == '' || db_name.to_s == ''
10
+ puts 'Usage: dckerize up APP_NAME --database==[postgres|mysql]'
11
+ exit 0;
12
+ end
13
+
14
+ if db_name == '--database=postgres'
15
+ generator = Dckerize::Generator.new(app_name, 'postgres')
16
+ elsif db_name == '--database=mysql'
17
+ generator = Dckerize::Generator.new(app_name, 'mysql')
18
+ else
19
+ puts 'Usage: dckerize up APP_NAME --database==[postgres|mysql]'
20
+ exit 0;
21
+ end
22
+ generator.up
23
+
24
+
@@ -0,0 +1,3 @@
1
+ module Dckerize
2
+ VERSION = "0.2.3"
3
+ end
data/lib/dckerize.rb ADDED
@@ -0,0 +1,63 @@
1
+ require "dckerize/version"
2
+ require 'erb'
3
+ require 'fileutils'
4
+
5
+ module Dckerize
6
+ def self.root
7
+ File.dirname __dir__
8
+ end
9
+
10
+ def self.templates
11
+ File.join root, 'templates'
12
+ end
13
+
14
+ class Generator
15
+ attr_accessor :name, :db
16
+ def initialize(name, db)
17
+ if db == 'mysql'
18
+ @db = 'mysql:5.7'
19
+ @db_password = 'MYSQL_ROOT_PASSWORD'
20
+ @db_password_env = 'MYSQL_ENV_MYSQL_ROOT_PASSWORD'
21
+ @db_host_env = 'MYSQL_PORT_3306_TCP_ADDR'
22
+ @db_name_for_data_volume = 'mysql'
23
+ @db_service_name = 'mysql'
24
+ elsif db == 'postgres'
25
+ @db = 'postgres'
26
+ @db_password = 'POSTGRES_PASSWORD'
27
+ @db_password_env = 'POSTGRES_ENV_POSTGRES_PASSWORD'
28
+ @db_host_env = 'POSTGRES_PORT_5432_TCP_ADDR'
29
+ @db_name_for_data_volume = 'postgresql'
30
+ @db_service_name = 'postgres'
31
+ end
32
+ @name = name
33
+ end
34
+
35
+ def get_binding
36
+ binding
37
+ end
38
+
39
+ def templates
40
+ Dckerize.templates
41
+ end
42
+
43
+ def up
44
+ FileUtils.mkdir_p('conf')
45
+ FileUtils.mkdir_p('vagrant')
46
+
47
+ create_from_template('Vagrantfile.erb', 'vagrant/Vagrantfile')
48
+ create_from_template('Dockerfile.erb', 'Dockerfile')
49
+ create_from_template('site.conf.erb', "conf/#{@name}.conf")
50
+ create_from_template('env.conf.erb', "conf/env.conf")
51
+ create_from_template('docker-compose.yml.erb', "docker-compose.yml")
52
+ create_from_template('docker-compose-installer.sh.erb', "vagrant/docker-compose-installer.sh")
53
+ end
54
+
55
+ private
56
+ def create_from_template(template_name, output_file)
57
+ template = ERB.new(File.read("#{templates}/#{template_name}"))
58
+ result = template.result(binding)
59
+ File.open("#{output_file}", 'w') { |file| file.write(result) }
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,35 @@
1
+ FROM phusion/passenger-ruby22:0.9.15
2
+
3
+ # Set correct environment variables.
4
+ ENV HOME /root
5
+
6
+ # Use baseimage-docker's init process.
7
+ CMD ["/sbin/my_init"]
8
+
9
+
10
+ # Clean up APT when done.
11
+ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
12
+
13
+ # Active nginx
14
+ RUN rm -f /etc/service/nginx/down
15
+
16
+ # Copy the nginx template for configuration and preserve environment variables
17
+ RUN rm /etc/nginx/sites-enabled/default
18
+ ADD conf/<%= @name %>.conf /etc/nginx/sites-enabled/<%= @name %>.conf
19
+ ADD conf/env.conf /etc/nginx/main.d/env.conf
20
+
21
+ # Create the folder for the project and set the workdir
22
+ RUN mkdir /home/app/<%= @name %>
23
+ WORKDIR /home/app/<%= @name %>
24
+
25
+ # Copy the project inside the container and run bundle install
26
+ COPY Gemfile /home/app/<%= @name %>/
27
+ COPY Gemfile.lock /home/app/<%= @name %>/
28
+ RUN bundle install
29
+ COPY . /home/app/<%= @name %>
30
+
31
+ # Set permissions for the passenger user for this app
32
+ RUN chown -R app:app /home/app/<%= @name %>
33
+
34
+ # Expose the port
35
+ EXPOSE 80
@@ -0,0 +1,25 @@
1
+ VAGRANTFILE_API_VERSION = "2"
2
+
3
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
4
+
5
+ config.vm.box = "trusty"
6
+ config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
7
+
8
+ config.vm.provider :virtualbox do |vb|
9
+ vb.customize ["modifyvm", :id, "--memory", "2048"]
10
+ end
11
+
12
+ config.vm.synced_folder "../", "/<%= @name %>", :mount_options => ["uid=9999,gid=9999"]
13
+
14
+ config.vm.network :private_network, ip: "192.168.50.4"
15
+
16
+ config.vm.provision :shell, :inline => 'apt-get update'
17
+ config.vm.provision :shell, path: "docker-compose-installer.sh"
18
+
19
+ config.vm.provision "docker" do |d|
20
+ d.pull_images "<%= @db %>"
21
+ d.pull_images "phusion/passenger-ruby22:0.9.15"
22
+ end
23
+
24
+
25
+ end
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ if which docker-compose >/dev/null; then
3
+ echo docker-compose already installed
4
+ else
5
+ echo Installing docker-compose...
6
+ sudo -i
7
+ curl -L https://github.com/docker/compose/releases/download/1.3.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
8
+ chmod +x /usr/local/bin/docker-compose
9
+ exit
10
+ fi
@@ -0,0 +1,26 @@
1
+ data:
2
+ image: <%= @db %>
3
+ name: <%= @name %>-data
4
+ environment:
5
+ - <%= @db_password %>=secretpassword
6
+ volumes:
7
+ - /var/lib/<%= @db_name_for_data_volume %>
8
+ command: true
9
+ <%= @db_service_name %>:
10
+ image: <%= @db %>
11
+ name: <%= @name %>-db
12
+ environment:
13
+ - <%= @db_password %>=secretpassword
14
+ volumes_from:
15
+ - data
16
+ webapp:
17
+ build: .
18
+ name: <%= @name %>
19
+ ports:
20
+ - "80:80"
21
+ environment:
22
+ - PASSENGER_APP_ENV=development
23
+ links:
24
+ - <%= @db_service_name %>:<%= @db_service_name %>
25
+ volumes:
26
+ - /<%= @name %>:/home/app/<%= @name %>
@@ -0,0 +1,2 @@
1
+ env <%= @db_password_env %>;
2
+ env <%= @db_host_env %>;
@@ -0,0 +1,10 @@
1
+ server {
2
+ listen 80;
3
+ server_name www.<%= @name %>.com;
4
+ root /home/app/<%= @name %>/public;
5
+
6
+ passenger_enabled on;
7
+ passenger_user app;
8
+
9
+ passenger_ruby /usr/bin/ruby2.2;
10
+ }
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dckerize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Pablo Acuña
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - pabloacuna88@gmail.com
58
+ executables:
59
+ - dckerize
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - dckerize.gemspec
73
+ - exe/dckerize
74
+ - lib/dckerize.rb
75
+ - lib/dckerize/version.rb
76
+ - templates/Dockerfile.erb
77
+ - templates/Vagrantfile.erb
78
+ - templates/docker-compose-installer.sh.erb
79
+ - templates/docker-compose.yml.erb
80
+ - templates/env.conf.erb
81
+ - templates/site.conf.erb
82
+ homepage: https://github.com/pacuna/dckerize
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ - templates
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.6
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Supercharged Rails environment using Docker and Vagrant.
107
+ test_files: []