dckerize 0.7.1 → 0.8.2
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 +4 -4
- data/README.md +17 -42
- data/exe/dckerize +0 -0
- data/lib/dckerize/generator.rb +4 -26
- data/lib/dckerize/runner.rb +3 -34
- data/lib/dckerize/version.rb +1 -1
- data/lib/dckerize.rb +0 -1
- data/templates/Dockerfile.erb +11 -16
- data/templates/docker-compose.yml.erb +20 -26
- data/templates/rails-env.conf.erb +1 -3
- data/templates/wait-for-postgres.sh.erb +16 -0
- data/templates/webapp.conf.erb +1 -1
- metadata +4 -5
- data/lib/dckerize/extra.rb +0 -49
- data/templates/setup.sh.erb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b4da294caa9baac416d7e578b9b712e6b6df473
|
4
|
+
data.tar.gz: 6e3dd74200892ad7e97f05c681ecc1fe4dcaa3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bbd9674d965becef33a74915f442a1d296a97801493954e81f64fa94e19a5af61db44ad5d260151a0a91604214ad8624acbf6490d42d91c182a959eda14200a
|
7
|
+
data.tar.gz: 2600a22c7515c1a2d2fe2a137c4455e0937fe86e0adfb0e19c6e72d0f1b2018f853bda6aca7d67fb87be7190a456d1d38f1af18b73a8268395fcfa0ac8c21270
|
data/README.md
CHANGED
@@ -10,15 +10,14 @@ This gem gives you a good starting point to containerize your Rails 5 applicatio
|
|
10
10
|
|
11
11
|
You'll get
|
12
12
|
|
13
|
-
- An nginx/passenger container environment for
|
14
|
-
- A separate container running
|
13
|
+
- An nginx/passenger container environment for your application and all the necessary configurations. It also mounts the application into the container so you can make development changes and not having to rebuild the image.
|
14
|
+
- A separate container running PostgreSQL
|
15
15
|
- A separate container for keeping your data using the data-only container pattern.
|
16
|
-
- Extras (elasticsearch, redis and memcached for now)
|
17
16
|
|
18
17
|
## Requirements
|
19
18
|
|
20
|
-
- Docker >= 1.
|
21
|
-
- Docker Compose >= 1.
|
19
|
+
- Docker >= 1.13
|
20
|
+
- Docker Compose >= 1.13
|
22
21
|
|
23
22
|
## Installation
|
24
23
|
|
@@ -26,54 +25,30 @@ You'll get
|
|
26
25
|
|
27
26
|
## Usage
|
28
27
|
|
29
|
-
|
30
|
-
create your app using the `--database` flag so you can have the driver already configured.
|
28
|
+
### Quickstart
|
31
29
|
|
32
|
-
|
30
|
+
$ rails new myapp --database=postgresql
|
31
|
+
$ cd myapp
|
32
|
+
$ dckerize up myapp
|
33
33
|
|
34
|
-
|
34
|
+
Configure your database credentials (you can check these in your docker compose file):
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
$ dckerize up APP_NAME --database=mysql
|
39
|
-
|
40
|
-
Or
|
41
|
-
|
42
|
-
$ dckerize up APP_NAME --database=postgres
|
43
|
-
|
44
|
-
Or
|
45
|
-
|
46
|
-
$ dckerize up APP_NAME --database=postgres --extras=elasticsearch,redis
|
47
|
-
|
48
|
-
Where APP_NAME should be the same name of your application and you must specify the database
|
49
|
-
that you want to use.
|
50
|
-
|
51
|
-
## Database Configuration
|
52
|
-
|
53
|
-
After running the `up` command you have to configure your database credentials
|
54
|
-
in the following way:
|
55
|
-
|
56
|
-
### MySQL
|
57
|
-
In your config/database.yml add these lines to your configuration:
|
58
|
-
|
59
|
-
username: root
|
36
|
+
username: myapp
|
60
37
|
password: mysecretpassword
|
61
|
-
host:
|
62
|
-
|
63
|
-
### Postgres
|
64
|
-
In your config/database.yml add these lines to your configuration:
|
65
|
-
|
66
|
-
username: postgres
|
67
|
-
password: mysecretpassword
|
68
|
-
host: postgres
|
38
|
+
host: myapp-db
|
69
39
|
|
40
|
+
Dckerize will use the name of your application to create the database host and user names.
|
41
|
+
It also will create the development database by default (myapp_development in this case).
|
70
42
|
|
71
43
|
Once you have your database configured, you can run:
|
72
44
|
|
73
45
|
```
|
74
|
-
$ docker-compose
|
46
|
+
$ docker-compose build
|
47
|
+
$ docker-compose up
|
75
48
|
```
|
76
49
|
|
50
|
+
And that's it. Now you can go to localhost and see your dockerized Rails application.
|
51
|
+
|
77
52
|
## Contributing
|
78
53
|
|
79
54
|
1. Fork it ( https://github.com/pacuna/dckerize/fork )
|
data/exe/dckerize
CHANGED
File without changes
|
data/lib/dckerize/generator.rb
CHANGED
@@ -1,30 +1,8 @@
|
|
1
1
|
module Dckerize
|
2
2
|
class Generator
|
3
|
-
attr_accessor :name
|
4
|
-
def initialize(name
|
5
|
-
if db == 'mysql'
|
6
|
-
@db = 'mysql:5.7'
|
7
|
-
@db_password = 'MYSQL_ROOT_PASSWORD=mysecretpassword'
|
8
|
-
@db_user = 'MYSQL_USER=root'
|
9
|
-
@db_name = "MYSQL_DATABASE=#{name}_development"
|
10
|
-
@data_volume_dir = '/var/lib/mysql'
|
11
|
-
@db_service_name = 'mysql'
|
12
|
-
@db_port = 3306
|
13
|
-
elsif db == 'postgres'
|
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"
|
18
|
-
@data_volume_dir = '/var/lib/postgresql'
|
19
|
-
@db_service_name = 'postgres'
|
20
|
-
@db_port = 5432
|
21
|
-
end
|
3
|
+
attr_accessor :name
|
4
|
+
def initialize(name)
|
22
5
|
@name = name
|
23
|
-
|
24
|
-
@extras = Array.new
|
25
|
-
extras.each do |extra|
|
26
|
-
@extras << Dckerize::Extra.new(extra)
|
27
|
-
end
|
28
6
|
end
|
29
7
|
|
30
8
|
def get_binding
|
@@ -42,7 +20,7 @@ module Dckerize
|
|
42
20
|
|
43
21
|
create_from_template('Dockerfile.erb', 'Dockerfile.development')
|
44
22
|
create_from_template('webapp.conf.erb', "webapp.conf")
|
45
|
-
create_from_template('
|
23
|
+
create_from_template('wait-for-postgres.sh.erb', "wait-for-postgres.sh")
|
46
24
|
create_from_template('rails-env.conf.erb', "rails-env.conf")
|
47
25
|
create_from_template('docker-compose.yml.erb', "docker-compose.yml")
|
48
26
|
end
|
@@ -54,7 +32,7 @@ module Dckerize
|
|
54
32
|
File.open("#{output_file}", 'w') { |file| file.write(result) }
|
55
33
|
|
56
34
|
# add execution permissions for setup.sh
|
57
|
-
system "chmod +x #{output_file}" if output_file == '
|
35
|
+
system "chmod +x #{output_file}" if output_file == 'wait-for-postgres.sh'
|
58
36
|
end
|
59
37
|
|
60
38
|
end
|
data/lib/dckerize/runner.rb
CHANGED
@@ -1,53 +1,22 @@
|
|
1
1
|
module Dckerize
|
2
2
|
class Runner
|
3
3
|
|
4
|
-
|
5
|
-
VALID_EXTRAS = ['elasticsearch', 'redis', 'memcached']
|
6
|
-
ERROR_MESSAGE = 'USAGE: dckerize up APP_NAME --database=<mysql|postgres|mongo> [--extras=elasticsearch,redis,memcached]'
|
7
|
-
VAGRANT_FOLDER_EXISTS = 'ERROR: vagrant folder already exists.'
|
4
|
+
ERROR_MESSAGE = 'USAGE: dckerize up APP_NAME'
|
8
5
|
CONF_FOLDER_EXISTS = 'ERROR: conf folder already exists.'
|
9
|
-
DOCKERFILE_EXISTS = 'ERROR: Dockerfile already exists.'
|
6
|
+
DOCKERFILE_EXISTS = 'ERROR: Dockerfile.development already exists.'
|
10
7
|
DOCKERCOMPOSE_EXISTS = 'ERROR: docker-compose already exists.'
|
11
8
|
def initialize(options)
|
12
9
|
@options = options
|
13
10
|
end
|
14
11
|
|
15
12
|
def execute
|
16
|
-
extras = []
|
17
|
-
db = ''
|
18
13
|
raise ERROR_MESSAGE unless valid?
|
19
|
-
@options[
|
20
|
-
splitted_option = option.split('=')
|
21
|
-
if splitted_option[0] == '--database'
|
22
|
-
db = splitted_option[1]
|
23
|
-
elsif splitted_option[0] == '--extras'
|
24
|
-
extras << splitted_option[1].split(',')
|
25
|
-
else
|
26
|
-
raise_error ERROR_MESSAGE
|
27
|
-
end
|
28
|
-
end
|
29
|
-
Dckerize::Generator.new(@options[1], db, extras.flatten).up
|
14
|
+
Dckerize::Generator.new(@options[1]).up
|
30
15
|
end
|
31
16
|
|
32
17
|
def valid?
|
33
18
|
# first option should always be up
|
34
19
|
return false if @options[0] != 'up'
|
35
|
-
# db is mandatory
|
36
|
-
return false unless @options.grep(/--database=/).any?
|
37
|
-
|
38
|
-
# only valid options allowed
|
39
|
-
# for dbs and extras
|
40
|
-
@options[2..-1].each do |option|
|
41
|
-
if option.split('=')[0] == '--database'
|
42
|
-
return false unless VALID_DBS.include?(option.split('=')[1])
|
43
|
-
elsif option.split('=')[0] == '--extras'
|
44
|
-
(option.split('=')[1]).split(',').each do |extra|
|
45
|
-
return false unless VALID_EXTRAS.include?(extra)
|
46
|
-
end
|
47
|
-
else
|
48
|
-
return false
|
49
|
-
end
|
50
|
-
end
|
51
20
|
true
|
52
21
|
end
|
53
22
|
end
|
data/lib/dckerize/version.rb
CHANGED
data/lib/dckerize.rb
CHANGED
data/templates/Dockerfile.erb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
FROM phusion/passenger-
|
1
|
+
FROM phusion/passenger-ruby24:0.9.21
|
2
2
|
|
3
3
|
# Set correct environment variables.
|
4
4
|
ENV HOME /root
|
@@ -6,23 +6,12 @@ ENV HOME /root
|
|
6
6
|
# Use baseimage-docker's init process.
|
7
7
|
CMD ["/sbin/my_init"]
|
8
8
|
|
9
|
-
# Additional packages
|
10
|
-
|
11
|
-
RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" netcat
|
9
|
+
# Additional packages
|
10
|
+
RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" postgresql-client
|
12
11
|
|
13
12
|
# Enable Nginx and Passenger
|
14
13
|
RUN rm -f /etc/service/nginx/down
|
15
14
|
|
16
|
-
# Add virtual host entry for the application. Make sure
|
17
|
-
# the file is in the correct path
|
18
|
-
RUN rm /etc/nginx/sites-enabled/default
|
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
|
24
|
-
|
25
|
-
|
26
15
|
ENV LANG en_US.UTF-8
|
27
16
|
ENV LANGUAGE en_US.UTF-8
|
28
17
|
ENV LC_ALL en_US.UTF-8
|
@@ -32,7 +21,14 @@ ENV LC_ALL en_US.UTF-8
|
|
32
21
|
WORKDIR /tmp
|
33
22
|
ADD Gemfile /tmp/
|
34
23
|
ADD Gemfile.lock /tmp/
|
35
|
-
RUN bundle install
|
24
|
+
RUN bundle install --jobs 4 --retry 3
|
25
|
+
|
26
|
+
# Add virtual host entry for the application
|
27
|
+
RUN rm /etc/nginx/sites-enabled/default
|
28
|
+
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf
|
29
|
+
|
30
|
+
# In case we need some environmental variables in Nginx
|
31
|
+
ADD rails-env.conf /etc/nginx/main.d/rails-env.conf
|
36
32
|
|
37
33
|
# Copy application into the container and use right permissions: passenger
|
38
34
|
# uses the app user for running the application
|
@@ -42,6 +38,5 @@ RUN usermod -u 1000 app
|
|
42
38
|
RUN chown -R app:app /home/app/webapp
|
43
39
|
WORKDIR /home/app/webapp
|
44
40
|
|
45
|
-
|
46
41
|
# Clean up APT when done.
|
47
42
|
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
@@ -1,44 +1,38 @@
|
|
1
1
|
version: '2'
|
2
2
|
services:
|
3
|
-
|
3
|
+
<%= @name %>-db:
|
4
|
+
image: postgres:9.5.3
|
5
|
+
environment:
|
6
|
+
- POSTGRES_PASSWORD=mysecretpassword
|
7
|
+
- POSTGRES_USER=<%= @name %>
|
8
|
+
- POSTGRES_DB=<%= @name %>_development
|
9
|
+
volumes_from:
|
10
|
+
- <%= @name %>-data
|
11
|
+
<%= @name %>-data:
|
12
|
+
image: postgres:9.5.3
|
13
|
+
volumes:
|
14
|
+
- /var/lib/postgresql
|
15
|
+
command: "true"
|
16
|
+
<%= @name %>-migrate:
|
4
17
|
build:
|
5
18
|
context: .
|
6
19
|
dockerfile: Dockerfile.development
|
7
20
|
depends_on:
|
8
|
-
- <%= @
|
21
|
+
- <%= @name %>-db
|
9
22
|
environment:
|
10
23
|
- PASSENGER_APP_ENV=development
|
11
|
-
|
12
|
-
|
13
|
-
container_name: <%= @name %>
|
24
|
+
command: ["./wait-for-postgres.sh", "<%= @name %>-db", "bin/rails", "db:migrate"]
|
25
|
+
<%= @name %>:
|
14
26
|
build:
|
15
27
|
context: .
|
16
28
|
dockerfile: Dockerfile.development
|
17
29
|
depends_on:
|
18
|
-
- <%= @
|
19
|
-
-
|
30
|
+
- <%= @name %>-db
|
31
|
+
- <%= @name %>-migrate
|
20
32
|
ports:
|
21
33
|
- "80:80"
|
22
34
|
environment:
|
23
35
|
- PASSENGER_APP_ENV=development
|
36
|
+
- RAILS_LOG_TO_STDOUT=true
|
24
37
|
volumes:
|
25
38
|
- .:/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 %>
|
33
|
-
<%- 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,16 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
host="$1"
|
6
|
+
shift
|
7
|
+
cmd="$@"
|
8
|
+
|
9
|
+
until PGPASSWORD=mysecretpassword psql -h "$host" -U "<%= @name %>" -d "<%= @name %>_development" -c '\l'; do
|
10
|
+
>&2 echo "Postgres is unavailable - sleeping"
|
11
|
+
sleep 1
|
12
|
+
done
|
13
|
+
|
14
|
+
>&2 echo "Postgres is up - executing command"
|
15
|
+
exec $cmd
|
16
|
+
|
data/templates/webapp.conf.erb
CHANGED
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.
|
4
|
+
version: 0.8.2
|
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:
|
11
|
+
date: 2017-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,13 @@ files:
|
|
72
72
|
- dckerize.gemspec
|
73
73
|
- exe/dckerize
|
74
74
|
- lib/dckerize.rb
|
75
|
-
- lib/dckerize/extra.rb
|
76
75
|
- lib/dckerize/generator.rb
|
77
76
|
- lib/dckerize/runner.rb
|
78
77
|
- lib/dckerize/version.rb
|
79
78
|
- templates/Dockerfile.erb
|
80
79
|
- templates/docker-compose.yml.erb
|
81
80
|
- templates/rails-env.conf.erb
|
82
|
-
- templates/
|
81
|
+
- templates/wait-for-postgres.sh.erb
|
83
82
|
- templates/webapp.conf.erb
|
84
83
|
homepage: https://github.com/pacuna/dckerize
|
85
84
|
licenses:
|
@@ -102,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
101
|
version: '0'
|
103
102
|
requirements: []
|
104
103
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.6.11
|
106
105
|
signing_key:
|
107
106
|
specification_version: 4
|
108
107
|
summary: Supercharged Rails development using Docker containers.
|
data/lib/dckerize/extra.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module Dckerize
|
2
|
-
class Extra
|
3
|
-
attr_accessor :name
|
4
|
-
def initialize(name)
|
5
|
-
@name = name
|
6
|
-
end
|
7
|
-
|
8
|
-
def image
|
9
|
-
if name == 'elasticsearch'
|
10
|
-
'elasticsearch'
|
11
|
-
elsif name == 'redis'
|
12
|
-
'redis'
|
13
|
-
elsif name == 'memcached'
|
14
|
-
'memcached'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def service_name
|
19
|
-
if name == 'elasticsearch'
|
20
|
-
'elasticsearch'
|
21
|
-
elsif name == 'redis'
|
22
|
-
'redis'
|
23
|
-
elsif name == 'memcached'
|
24
|
-
'memcached'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def alias
|
29
|
-
if name == 'elasticsearch'
|
30
|
-
'elasticsearch'
|
31
|
-
elsif name == 'redis'
|
32
|
-
'redis'
|
33
|
-
elsif name == 'memcached'
|
34
|
-
'memcached'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def env_variables
|
39
|
-
if name == 'elasticsearch'
|
40
|
-
['ELASTICSEARCH_PORT_9200_TCP_ADDR', 'ELASTICSEARCH_URL']
|
41
|
-
elsif name == 'redis'
|
42
|
-
['REDIS_PORT_6379_TCP_ADDR']
|
43
|
-
elsif name == 'memcached'
|
44
|
-
['MEMCACHED_PORT_11211_TCP_ADDR']
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|