dckerize 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb4d4f7ae8a8b8115230d78b29ca2d76700ed800
4
- data.tar.gz: 872c007c9157dacb8ed329176932d96b6b39ae99
3
+ metadata.gz: 7d53b7321a208a9d47482884b1f44c7879c7ec11
4
+ data.tar.gz: 60868b0d8b361fbc8c48d7f2b21360c35ee821a9
5
5
  SHA512:
6
- metadata.gz: c0286a2f0105092950d4287e9e2f2a915ac2cb5082500e2ca5b54646a82ff81b12aa5537cb7af42dae9afd8f22ba64904b58f984313ef20a4fe825991a976ba9
7
- data.tar.gz: 278e45fbba7eb421a4cc1d2bd63284ce2dc2247b4ece1f1125cf7a5bfabe3d31b54b5dec925b43fd4befa86e6cc46bb8843355fdec4bece0a5ec3bd83817d766
6
+ metadata.gz: 679e303ff733a0d556e039833a002e09417fcf246b75cfb369203f53d226b626ee6d6921377970ead1bd9ae0d4e44dd6d0dd848ee6a518abda697f10559c0d0d
7
+ data.tar.gz: c4d0ca26181ddfba503af8dd19d6263f54808c24b4aa6ae91e1d2cf7413f0d83e5480773a66f0133a6f37366e16854ae3b134d14048c5884e0df55f4724d52ac
data/README.md CHANGED
@@ -2,25 +2,23 @@
2
2
  [![Gem Version](https://badge.fury.io/rb/dckerize.svg)](http://badge.fury.io/rb/dckerize)
3
3
  [![Build Status](https://travis-ci.org/pacuna/dckerize.svg?branch=master)](https://travis-ci.org/pacuna/dckerize)
4
4
 
5
- Supercharged Rails development using Docker and Vagrant
5
+ Supercharged Rails development using Docker
6
6
 
7
7
  ## Description
8
8
 
9
- This gem gives you a good starting point for developing your Rails application using containers managed by Docker
10
- inside of a VM managed by Vagrant (video demo at the end of the readme).
9
+ This gem gives you a good starting point to containerize your Rails 5 applications using Docker.
11
10
 
12
11
  You'll get
13
12
 
14
- - An ubuntu trusty image already provisioned with Docker and Docker Compose.
15
13
  - An nginx/passenger container environment for serving your application and all the necessary configurations.
16
- - A separate container running MySQL/postgres/Mongo for your DB.
14
+ - A separate container running MySQL or PostgreSQL
17
15
  - A separate container for keeping your data using the data-only container pattern.
18
16
  - Extras (elasticsearch, redis and memcached for now)
19
17
 
20
18
  ## Requirements
21
19
 
22
- - Ruby and Bundler
23
- - Vagrant >= 1.6
20
+ - Docker >= 1.12
21
+ - Docker Compose >= 1.8
24
22
 
25
23
  ## Installation
26
24
 
@@ -28,11 +26,12 @@ You'll get
28
26
 
29
27
  ## Usage
30
28
 
31
- You need to have a Rails application already created.
29
+ You need to have a Rails 5 application already created. It can be useful if you
30
+ create your app using the `--database` flag so you can have the driver already configured.
32
31
 
33
32
  General usage:
34
33
 
35
- $ dckerize up APP_NAME --database=<mysql|postgres|mongo> [--extras=elasticsearch,redis,memcached]
34
+ $ dckerize up APP_NAME --database=<mysql|postgres> [--extras=elasticsearch,redis,memcached]
36
35
 
37
36
  So for example in the root of your application run:
38
37
 
@@ -44,131 +43,37 @@ Or
44
43
 
45
44
  Or
46
45
 
47
- $ dckerize up APP_NAME --database=postgres --extras=elasticsearch
48
-
49
- Or
50
-
51
- $ dckerize up APP_NAME --database=mongo --extras=elasticsearch,redis
52
-
46
+ $ dckerize up APP_NAME --database=postgres --extras=elasticsearch,redis
53
47
 
54
48
  Where APP_NAME should be the same name of your application and you must specify the database
55
49
  that you want to use.
56
50
 
57
- ### Generated Structure
58
-
59
- Dckerize will generate:
60
-
61
- - A Vagrant folder, which contains a Vagrantfile and a docker-compose-installer bash script for provisioning.
62
- - A conf folder containing an nginx configuration file for your site and an environment definition file for passing
63
- the necessary environment variables to passenger. Any extra environment variables passed to your Rails application
64
- should be declared in this file.
65
- - A Dockerfile for building your application.
66
- - A docker-compose.yml file for starting your entire enviroment inside the VM.
51
+ ## Database Configuration
67
52
 
68
- ### Environment Variables Configuration
53
+ After running the `up` command you have to configure your database credentials
54
+ in the following way:
69
55
 
70
- ## MySQL
56
+ ### MySQL
71
57
  In your config/database.yml add these lines to your configuration:
72
58
 
73
59
  username: root
74
- password: <%= ENV['MYSQL_ENV_MYSQL_ROOT_PASSWORD'] %>
60
+ password: mysecretpassword
75
61
  host: mysql
76
62
 
77
- ## Postgres
63
+ ### Postgres
78
64
  In your config/database.yml add these lines to your configuration:
79
65
 
80
- user: postgres
81
- password: <%= ENV['POSTGRES_ENV_POSTGRES_PASSWORD'] %>
66
+ username: postgres
67
+ password: mysecretpassword
82
68
  host: postgres
83
69
 
84
- ## Mongo
85
-
86
- Host for Mongo
87
-
88
- ENV['MONGO_PORT_27017_TCP_ADDR']
89
-
90
-
91
- ## Elasticsearch
92
-
93
- Host for elasticsearch
94
-
95
- ENV['ELASTICSEARCH_PORT_9200_TCP_ADDR']
96
-
97
- ## Redis
98
-
99
- Host for redis
100
-
101
- ENV['REDIS_PORT_6379_TCP_ADDR']
102
-
103
- ## Memcached
104
-
105
- Host for memcached
106
-
107
- ENV['MEMCACHED_PORT_11211_TCP_ADDR']
108
-
109
- ### Developing
110
-
111
- Go inside the generated vagrant folder and run
112
-
113
- $ vagrant up
114
70
 
115
- Vagrant will pull the ubuntu trusty image, the necessary docker images and set the shared folder for
116
- development.
117
-
118
- Once finished, run
119
-
120
- $ vagrant ssh
121
- $ cd /APP_NAME
122
- $ sudo docker-compose up -d
123
-
124
- Since the folder is being shared with the virtual machine, you can run docker-compose using the docker-compose.yml file.
125
- This will build the container for your application, the db and the links between the containers.
126
-
127
- The application folder will also be mounted inside the container, so you can work as you normally do locally and see the changes
128
- reflected immediately inside the container.
129
-
130
- Now you can go inside the container and run the typical Rails commands for interacting with your application.
131
-
132
- To get the app container's name run:
133
-
134
- $ docker ps
135
-
136
- This will show you all the running containers. Choose the one that's running your app and go inside by executing:
137
-
138
- $ docker exec -it CONTAINER_NAME bash
139
-
140
- Now you can interact with your application
141
-
142
- $ rake db:create
143
- $ rake db:migrate
144
- $ rails c
145
-
146
- And etc.
147
-
148
- 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
149
- you can access your application by visiting http://192.168.50.4.
150
-
151
- ### Mounting extra files to running containers
152
-
153
- Useful for adding sql dumps to your db container (not the data one). In this case you should have the file in your shared folder and send it from your host in vagrant to your running container. There are several ways to accomplish this, but the simplest way is described [here](http://stackoverflow.com/a/24805696).
154
- The fastest way for a running container:
71
+ Once you have your database configured, you can run:
155
72
 
156
73
  ```
157
- docker exec -i <container_id> bash -c 'cat > /path/to/container/file' < /path/to/host/file/
74
+ $ docker-compose up --build
158
75
  ```
159
76
 
160
- ## TODO
161
-
162
- - [x] Support for more services (redis, elasticsearch)
163
- - Support for other ruby/rails versions
164
- - More workflow examples
165
-
166
-
167
-
168
- ## Video demo
169
-
170
- [![Dckerize](http://img.youtube.com/vi/X8IVAoBUtbs/0.jpg)](http://www.youtube.com/watch?v=X8IVAoBUtbs)
171
-
172
77
  ## Contributing
173
78
 
174
79
  1. Fork it ( https://github.com/pacuna/dckerize/fork )
@@ -4,23 +4,20 @@ module Dckerize
4
4
  def initialize(name, db, extras = [])
5
5
  if db == 'mysql'
6
6
  @db = 'mysql:5.7'
7
- @db_password = 'MYSQL_ROOT_PASSWORD'
8
- @db_password_env = 'MYSQL_ENV_MYSQL_ROOT_PASSWORD'
9
- @db_host_env = 'MYSQL_PORT_3306_TCP_ADDR'
7
+ @db_password = 'MYSQL_ROOT_PASSWORD=mysecretpassword'
8
+ @db_user = 'MYSQL_USER=root'
9
+ @db_name = "MYSQL_DATABASE=#{name}_development"
10
10
  @data_volume_dir = '/var/lib/mysql'
11
11
  @db_service_name = 'mysql'
12
+ @db_port = 3306
12
13
  elsif db == 'postgres'
13
- @db = 'postgres'
14
- @db_password = 'POSTGRES_PASSWORD'
15
- @db_password_env = 'POSTGRES_ENV_POSTGRES_PASSWORD'
16
- @db_host_env = 'POSTGRES_PORT_5432_TCP_ADDR'
14
+ @db = 'postgres:9.5.3'
15
+ @db_password = 'POSTGRES_PASSWORD=mysecretpassword'
16
+ @db_user = "POSTGRES_USER=#{name}"
17
+ @db_name = "POSTGRES_DB=#{name}_development"
17
18
  @data_volume_dir = '/var/lib/postgresql'
18
19
  @db_service_name = 'postgres'
19
- elsif db == 'mongo'
20
- @db = 'mongo'
21
- @db_host_env = 'MONGO_PORT_27017_TCP_ADDR'
22
- @data_volume_dir = '/data/db'
23
- @db_service_name = 'mongo'
20
+ @db_port = 5432
24
21
  end
25
22
  @name = name
26
23
 
@@ -40,20 +37,14 @@ module Dckerize
40
37
 
41
38
  def up
42
39
 
43
- # create vagrant and conf folders only if don't exist
44
- raise Dckerize::Runner::VAGRANT_FOLDER_EXISTS if File.exists?('vagrant')
45
- raise Dckerize::Runner::CONF_FOLDER_EXISTS if File.exists?('conf')
46
- raise Dckerize::Runner::DOCKERFILE_EXISTS if File.exists?('Dockerfile')
40
+ raise Dckerize::Runner::DOCKERFILE_EXISTS if File.exists?('Dockerfile.development')
47
41
  raise Dckerize::Runner::DOCKERCOMPOSE_EXISTS if File.exists?('docker-compose.yml')
48
- FileUtils.mkdir_p('vagrant')
49
- FileUtils.mkdir_p('conf')
50
42
 
51
- create_from_template('Vagrantfile.erb', 'vagrant/Vagrantfile')
52
- create_from_template('Dockerfile.erb', 'Dockerfile')
53
- create_from_template('site.conf.erb', "conf/#{@name}.conf")
54
- create_from_template('env.conf.erb', "conf/env.conf")
43
+ create_from_template('Dockerfile.erb', 'Dockerfile.development')
44
+ create_from_template('webapp.conf.erb', "webapp.conf")
45
+ create_from_template('setup.sh.erb', "setup.sh")
46
+ create_from_template('rails-env.conf.erb', "rails-env.conf")
55
47
  create_from_template('docker-compose.yml.erb', "docker-compose.yml")
56
- create_from_template('docker-compose-installer.sh.erb', "vagrant/docker-compose-installer.sh")
57
48
  end
58
49
 
59
50
  private
@@ -61,6 +52,9 @@ module Dckerize
61
52
  template = ERB.new(File.read("#{templates}/#{template_name}"), nil, '-')
62
53
  result = template.result(binding)
63
54
  File.open("#{output_file}", 'w') { |file| file.write(result) }
55
+
56
+ # add execution permissions for setup.sh
57
+ system "chmod +x #{output_file}" if output_file == 'setup.sh'
64
58
  end
65
59
 
66
60
  end
@@ -1,3 +1,3 @@
1
1
  module Dckerize
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- FROM phusion/passenger-ruby22:0.9.15
1
+ FROM phusion/passenger-ruby23:0.9.19
2
2
 
3
3
  # Set correct environment variables.
4
4
  ENV HOME /root
@@ -6,30 +6,42 @@ ENV HOME /root
6
6
  # Use baseimage-docker's init process.
7
7
  CMD ["/sbin/my_init"]
8
8
 
9
+ # Additional packages: we are adding the netcat package so we can
10
+ # make pings to the database service
11
+ RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" netcat
9
12
 
10
- # Clean up APT when done.
11
- RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
12
-
13
- # Active nginx
13
+ # Enable Nginx and Passenger
14
14
  RUN rm -f /etc/service/nginx/down
15
15
 
16
- # Copy the nginx template for configuration and preserve environment variables
16
+ # Add virtual host entry for the application. Make sure
17
+ # the file is in the correct path
17
18
  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
19
+ ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
20
+
21
+ # In case we need some environmental variables in Nginx. Make sure
22
+ # the file is in the correct path
23
+ ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
20
24
 
21
- # Create the folder for the project and set the workdir
22
- RUN mkdir /home/app/<%= @name %>
23
- WORKDIR /home/app/<%= @name %>
24
25
 
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 %>
26
+ ENV LANG en_US.UTF-8
27
+ ENV LANGUAGE en_US.UTF-8
28
+ ENV LC_ALL en_US.UTF-8
30
29
 
31
- # Set permissions for the passenger user for this app
32
- RUN chown -R app:app /home/app/<%= @name %>
30
+ # Install gems: it's better to build an independent layer for the gems
31
+ # so they are cached during builds unless Gemfile changes
32
+ WORKDIR /tmp
33
+ ADD Gemfile /tmp/
34
+ ADD Gemfile.lock /tmp/
35
+ RUN bundle install -j4
33
36
 
34
- # Expose the port
35
- EXPOSE 80
37
+ # Copy application into the container and use right permissions: passenger
38
+ # uses the app user for running the application
39
+ RUN mkdir /home/app/webapp
40
+ COPY . /home/app/webapp
41
+ RUN usermod -u 1000 app
42
+ RUN chown -R app:app /home/app/webapp
43
+ WORKDIR /home/app/webapp
44
+
45
+
46
+ # Clean up APT when done.
47
+ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
@@ -1,38 +1,44 @@
1
- data:
2
- image: <%= @db %>
3
- name: <%= @name %>-data
4
- <%- if @db_password -%>
5
- environment:
6
- - <%= @db_password %>=secretpassword
7
- <%- end -%>
8
- volumes:
9
- - <%= @data_volume_dir %>
10
- command: "true"
11
- <%= @db_service_name %>:
12
- image: <%= @db %>
13
- name: <%= @name %>-db
14
- <%- if @db_password -%>
15
- environment:
16
- - <%= @db_password %>=secretpassword
17
- <%- end -%>
18
- volumes_from:
19
- - data
20
- webapp:
21
- build: .
22
- name: <%= @name %>
23
- ports:
24
- - "80:80"
25
- environment:
26
- - PASSENGER_APP_ENV=development
27
- links:
28
- - <%= @db_service_name %>:<%= @db_service_name %>
29
- <%- @extras.each do |extra| -%>
30
- - <%= extra.service_name %>:<%= extra.alias %>
1
+ version: '2'
2
+ services:
3
+ webapp_setup:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.development
7
+ depends_on:
8
+ - <%= @db_service_name %>
9
+ environment:
10
+ - PASSENGER_APP_ENV=development
11
+ entrypoint: ./setup.sh
12
+ webapp:
13
+ container_name: <%= @name %>
14
+ build:
15
+ context: .
16
+ dockerfile: Dockerfile.development
17
+ depends_on:
18
+ - <%= @db_service_name %>
19
+ - webapp_setup
20
+ ports:
21
+ - "80:80"
22
+ environment:
23
+ - PASSENGER_APP_ENV=development
24
+ volumes:
25
+ - .:/home/app/webapp
26
+ <%= @db_service_name %>:
27
+ image: <%= @db %>
28
+ <%- if @db_password -%>
29
+ environment:
30
+ - <%= @db_password %>
31
+ - <%= @db_user %>
32
+ - <%= @db_name %>
31
33
  <%- end -%>
32
- volumes:
33
- - /<%= @name %>:/home/app/<%= @name %>
34
- <%- @extras.each do |extra| -%>
35
- <%= extra.service_name %>:
36
- image: <%= extra.image %>
37
- name: <%= @name %>-<%= extra.service_name %>
38
- <%- end -%>
34
+ volumes_from:
35
+ - data
36
+ data:
37
+ image: <%= @db %>
38
+ volumes:
39
+ - <%= @data_volume_dir %>
40
+ command: "true"
41
+ <%- @extras.each do |extra| -%>
42
+ <%= extra.service_name %>:
43
+ image: <%= extra.image %>
44
+ <%- end -%>
@@ -0,0 +1,4 @@
1
+ # example variables
2
+ env SECRET_KEY_BASE;
3
+ env DATABASE_URL;
4
+ env DATABASE_PASSWORD;
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+
3
+ echo "Waiting <%= @db_service_name %> to start..."
4
+
5
+ while ! nc -z <%= @db_service_name %> <%= @db_port %>; do
6
+ sleep 0.1
7
+ done
8
+
9
+ echo "<%= @db_service_name %> started"
10
+
11
+ bin/rails db:migrate
@@ -0,0 +1,10 @@
1
+ server {
2
+ listen 80;
3
+ server_name _;
4
+ root /home/app/webapp/public;
5
+
6
+ passenger_enabled on;
7
+ passenger_user app;
8
+
9
+ passenger_ruby /usr/bin/ruby2.3;
10
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dckerize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Acuña
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,11 +77,10 @@ files:
77
77
  - lib/dckerize/runner.rb
78
78
  - lib/dckerize/version.rb
79
79
  - templates/Dockerfile.erb
80
- - templates/Vagrantfile.erb
81
- - templates/docker-compose-installer.sh.erb
82
80
  - templates/docker-compose.yml.erb
83
- - templates/env.conf.erb
84
- - templates/site.conf.erb
81
+ - templates/rails-env.conf.erb
82
+ - templates/setup.sh.erb
83
+ - templates/webapp.conf.erb
85
84
  homepage: https://github.com/pacuna/dckerize
86
85
  licenses:
87
86
  - MIT
@@ -103,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
102
  version: '0'
104
103
  requirements: []
105
104
  rubyforge_project:
106
- rubygems_version: 2.4.4
105
+ rubygems_version: 2.5.1
107
106
  signing_key:
108
107
  specification_version: 4
109
108
  summary: Supercharged Rails development using Docker containers.
110
109
  test_files: []
111
- has_rdoc:
@@ -1,28 +0,0 @@
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
- <%- @extras.each do |extra| -%>
23
- d.pull_images "<%= extra.image %>"
24
- <%- end -%>
25
- end
26
-
27
-
28
- end
@@ -1,10 +0,0 @@
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
@@ -1,9 +0,0 @@
1
- <%- if @db_password_env -%>
2
- env <%= @db_password_env %>;
3
- <%- end -%>
4
- env <%= @db_host_env %>;
5
- <% @extras.each do |extra| -%>
6
- <% extra.env_variables.each do |env_variable| -%>
7
- env <%= env_variable %>;
8
- <% end -%>
9
- <% end -%>
@@ -1,10 +0,0 @@
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
- }