dockerize-stack 0.2.0 → 0.3.0

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: 7b14e1b24576d14cc0369d810fef3f45c6f1b1bf
4
- data.tar.gz: a4a2b169b1142db89fb3b966dc4c1e2527e9eb20
3
+ metadata.gz: 7d4d2f8c94a2b073521130e3b820f3b7359b5f28
4
+ data.tar.gz: bfbe602636915cb7b2737449ee11a1961dca069e
5
5
  SHA512:
6
- metadata.gz: 6c0180e7f0245a6b92d75f765343126dd99de7626baa94fd725fc275b6002876e88ac5c26efc724a02bf87f61fe1363e14ba1fbe3714f92b182bef2d9a389dd6
7
- data.tar.gz: 9bca13913d4da030c5579834cc0cec3973b23ad45ab47f847c4e37e9aeeaae866273686923b677d68dd194b62eb18c34c45fd6516d1f6451e49014fceb26a86c
6
+ metadata.gz: 9fb191ef3ab134fd2f7d620273bfc3ba79def5461f11bea7584110f72f4575605e2743755024fb8b3f0b98ab222ff97470057604565ab8c88b189167ff167c05
7
+ data.tar.gz: 3265b9ffbac7b88caaaf5f336a20c0ce49a9774a58e0140d944c27d04d663378d5dd4965ab46216b476481a83675a9886f3b142951b0a88bcc6513174cbd9cea
data/README.md CHANGED
@@ -3,53 +3,60 @@
3
3
  This it's a generator for generate Dockerfile and docker-compose for your application for development
4
4
 
5
5
  ## Why?
6
+
6
7
  For build a quick stack for your development enviroment docker is the best tool you can use, but you need to configure the Dockerfile docker-compose, persisted database data, set the entrypoint...
7
8
 
8
9
  This generator help you to have a basic template for your stack; focusing on develepment enviroment.
9
10
 
10
11
  ## Install
12
+
11
13
  ```
12
14
  gem install dockerize-stack
13
15
  ```
16
+
14
17
  or
18
+
15
19
  ```
16
20
  docker pull devmasx/dockerize-stack
17
21
  ```
18
22
 
19
- ## Stacks available
20
-
21
- - [x] Rails 5.1 (Ruby)
22
- - [ ] Symfony (PHP)
23
- - [ ] Phoenixframework (Elixir)
24
- - [ ] Django (Python)
25
- - [ ] Express (Node)
26
-
27
23
  ## Usage
24
+
28
25
  ```sh
29
26
  dockerize-stack rails
30
27
  ```
28
+
31
29
  or use docker image
30
+
32
31
  ```
33
32
  docker run --user $(id -u) -it -v $(pwd):/usr/src devmasx/dockerize-stack rails
34
33
  ```
35
34
 
36
35
  This script ask you:
36
+
37
37
  - Ruby version
38
38
  - Database type
39
39
 
40
40
  example files generate:
41
+
41
42
  ```
42
43
  /docker
43
44
  --development
44
45
  ----Dockerfile
45
46
  ----entrypoint.sh
47
+ --production
48
+ ----rails
49
+ ------Dockerfile
50
+ ------entrypoint.sh
51
+ ----nginx
52
+ ------Dockerfile
53
+ ------entrypoint.sh
46
54
  /.dockerignore
47
55
  /docker-compose.yml
48
56
  /config/database-docker.yml
49
57
  ```
50
58
 
51
59
  ## TODO
52
- - [ ] Add phoenix generator
53
- - [ ] Solve use rails generator in container
60
+
54
61
  - [ ] Add integrations with all database types rails new supported ([mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc])
55
- - [x] Integrate Build with private repository in the generator
62
+ - [x] Integrate Build with private repositorys
@@ -2,7 +2,7 @@ require 'thor'
2
2
  # Ask variables and render templates
3
3
  class DockerizeRails < Thor
4
4
  include Thor::Actions
5
- attr_accessor :ruby_version, :database, :id_rsa
5
+ attr_accessor :ruby_version, :database, :github_private, :docker_production
6
6
 
7
7
  WORKDIR = ".".freeze
8
8
 
@@ -12,56 +12,40 @@ class DockerizeRails < Thor
12
12
 
13
13
  desc 'generate_files', 'generate docker files for rails application'
14
14
  def generate_files
15
- ruby_version = ask('Ruby Version (default 2.5.1):')
16
- ruby_version = '2.5.1-slim' if ruby_version == ''
17
- database = ask('What is your Database?', limited_to: ['postgresql', 'mysql'])
18
- id_rsa = ask('Would you need your id_rsa file to connect with GitHub? Type yes or no (default no):')
19
- id_rsa = 'no' if id_rsa == ''
20
- render_templates(ruby_version: ruby_version, database: database, id_rsa: id_rsa)
21
- render_production_templates(ruby_version: ruby_version, database: database, id_rsa: id_rsa)
15
+ @ruby_version = ask_with_default('Ruby Version (default 2.5.1):', '2.5.1')
16
+ @database = ask('What is your Database?', limited_to: ['postgresql', 'mysql'])
17
+ @github_private = ask_with_default('You need github token for private gems? (default no):', 'no')
18
+ @docker_production = ask_with_default("You want generate docker-stack for production? y/n", 'n')
22
19
 
23
- puts 'Update your database.yml based in database-docker.yml'
20
+ render_templates
21
+ render_production_templates if @docker_production != 'n' || @docker_production != 'no'
24
22
  end
25
23
 
26
24
  no_commands do
27
- def render_templates(ruby_version: '2.5.1-slim', database: 'postgresql', id_rsa: 'no')
28
- @ruby_version = ruby_version
29
- @database = database
30
- @id_rsa = id_rsa
31
-
25
+ def render_templates
32
26
  template 'templates/docker/development/Dockerfile.erb', "#{WORKDIR}/docker/development/Dockerfile"
33
27
  template 'templates/docker/development/entrypoint.sh.erb', "#{WORKDIR}/docker/development/entrypoint.sh"
34
28
  template 'templates/docker-compose.yml.erb', "#{WORKDIR}/docker-compose.yml"
35
29
  template 'templates/config/database-docker.yml.erb', "#{WORKDIR}/config/database-docker.yml"
36
30
  template 'templates/dockerignore.erb', "#{WORKDIR}/.dockerignore"
37
- append_or_create "#{WORKDIR}/.gitignore", '
38
- volumes'
39
- if @id_rsa == 'yes'
40
- template 'templates/id_rsa.sample', "#{WORKDIR}/id_rsa.sample"
41
- append_or_create "#{WORKDIR}/.gitignore", '
42
- id_rsa
43
- id_rsa.sample
44
- '
45
- end
46
31
  puts 'Update your database.yml based in database-docker.yml'
47
32
  end
48
33
 
49
- def render_production_templates(ruby_version: '2.5.1-slim', database: 'postgresql', id_rsa: 'no')
50
- response = ask("You want generate docker-stack for production?")
51
- return false unless response
52
- @ruby_version = ruby_version
53
- @database = database
54
- @id_rsa = id_rsa
55
-
34
+ def render_production_templates
56
35
  directory 'templates/docker/production', "#{WORKDIR}/docker/production"
57
36
  directory 'templates/docker/kubernetes', "#{WORKDIR}/docker/kubernetes"
58
37
 
59
- template 'templates/docker/Dockerfile.production.erb', "#{WORKDIR}/docker/production/rails/Dockerfile"
38
+ template 'templates/docker/production/rails/Dockerfile.erb', "#{WORKDIR}/docker/production/rails/Dockerfile"
60
39
  end
61
40
  end
62
41
 
63
42
  private
64
43
 
44
+ def ask_with_default(question = '', default = '')
45
+ result = ask(question)
46
+ result != '' ? result : default
47
+ end
48
+
65
49
  def append_or_create(file_path, file_content)
66
50
  if File.exist?(file_path)
67
51
  append_to_file file_path, file_content
@@ -1,50 +1,37 @@
1
- FROM ruby:<%= ruby_version %>
1
+ FROM node:10.13.0-slim as nodejs
2
+
3
+ # ******Multi stage ********
4
+ FROM ruby:<%= ruby_version %>-slim
2
5
 
3
6
  # install common dev libs
4
7
  RUN apt-get update -qq && apt-get install -y \
5
- build-essential \
6
- libpq-dev \
7
- git
8
-
9
- # install editors
10
- RUN apt-get install -y \
11
- nano \
12
- vim
13
-
14
- # http libs for download
15
- RUN apt-get install -y \
16
- curl \
17
- ca-certificates \
18
- openssl \
19
- apt-transport-https \
20
- gnupg2
21
-
8
+ build-essential vim git
22
9
  <% if database == "mysql" %>
23
- # install mysql
10
+ # install Mysql
24
11
  RUN apt-get install -y mysql-client libmysqlclient-dev
25
12
  <% elsif database == "postgresql" %>
26
- # install postgresql
27
- RUN apt-get install -y postgresql-client
13
+ # install Postgresql
14
+ RUN apt-get install -y postgresql-client libpq-dev
28
15
  <% end %>
16
+ # install Nodejs 10.13.0 and Yarn 1.10.1
17
+ ENV NODE_VERSION=10.13.0 YARN_VERSION=1.10.1
18
+ COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
19
+ COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
20
+ COPY --from=nodejs /opt/yarn-v1.10.1/ /opt/yarn-v1.10.1/
29
21
 
30
- # install node 8.9.1 LTS
31
- RUN curl -sL https://deb.nodesource.com/setup_8.x | bin/bash -
32
- RUN apt-get update && apt-get install -y nodejs
33
-
34
- # install yarn
35
- RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
36
- RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
37
- RUN apt-get update && apt-get install yarn
38
-
39
- RUN mkdir /app
40
22
  WORKDIR /app
41
- COPY . /app
42
-
43
- <% if @id_rsa == 'yes' %>
44
- RUN mkdir /root/.ssh
45
- RUN cp id_rsa /root/.ssh/id_rsa
46
- # RUN chmod 0644 /root/.ssh/id_rsa
47
- RUN touch /root/.ssh/known_hosts
48
- RUN eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa && ssh-add -l && ssh-add -L && echo "Host github.com\n\tIdentityFile ~/.ssh/id_rsa" >> /root/.ssh/config
49
- RUN ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts
23
+ <% if @github_private == 'yes' %>
24
+ # Private repository
25
+ ARG GITHUB_TOKEN
26
+ ARG GITHUB_USERNAME
27
+ RUN bundle config github.com ${GITHUB_USERNAME}:${GITHUB_TOKEN}
50
28
  <% end %>
29
+ # gems cache layer
30
+ COPY Gemfile Gemfile.lock /app/
31
+ RUN bundle install -j 4
32
+
33
+ # node_modules cache layer
34
+ COPY package.json yarn.lock /app/
35
+ RUN yarn install --pure-lockfile
36
+
37
+ COPY . .
@@ -1,5 +1,4 @@
1
1
  bundle check || bundle install
2
- yarn install --pure-lockfile
3
2
 
4
3
  rake db:create db:migrate
5
4
  rm -f tmp/pids/server.pid
@@ -0,0 +1,75 @@
1
+ FROM node:10.13.0-slim as nodejs
2
+
3
+ # ******Multi stage ********
4
+ FROM ruby:<%= ruby_version %>-slim as builder
5
+
6
+ ENV RAILS_ENV=production NODE_ENV=production
7
+
8
+ # install common dev libs
9
+ RUN apt-get update -qq && apt-get install -y \
10
+ build-essential git
11
+ <% if database == "mysql" %>
12
+ # install mysql
13
+ RUN apt-get update -qq && apt-get install -y libmysqlclient-dev mysql-client
14
+ <% elsif database == "postgresql" %>
15
+ # install postgresql
16
+ RUN apt-get update -qq && apt-get install -y libpq-dev postgresql-client
17
+ <% end %>
18
+ # install Nodejs 10.13.0 and Yarn 1.10.1
19
+ ENV NODE_VERSION=10.13.0 YARN_VERSION=1.10.1
20
+ COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
21
+ COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
22
+ COPY --from=nodejs /opt/yarn-v1.10.1/ /opt/yarn-v1.10.1/
23
+
24
+ WORKDIR /app
25
+ <% if @github_private == 'yes' %>
26
+ # private repository
27
+ ARG GITHUB_TOKEN
28
+ ARG GITHUB_USERNAME
29
+ RUN bundle config github.com ${GITHUB_USERNAME}:${GITHUB_TOKEN}
30
+ <% end %>
31
+ # gems cache layer
32
+ COPY Gemfile Gemfile.lock /app/
33
+ RUN bundle install -j 4 --without development test staging --deployment
34
+
35
+ # node_modules cache layer
36
+ COPY package.json yarn.lock /app/
37
+ RUN yarn install --pure-lockfile
38
+
39
+ COPY . .
40
+
41
+ RUN rails assets:precompile
42
+
43
+ # remove unnecessary files
44
+ RUN rm -r node_modules
45
+
46
+ # *******************************************
47
+ # ************* Multi Stage *****************
48
+ # *******************************************
49
+ FROM ruby:<%= ruby_version %>
50
+
51
+ ENV RAILS_ENV=production NODE_ENV=production
52
+
53
+ <% if database == "mysql" %>
54
+ # install mysql
55
+ RUN apt-get update -qq && apt-get install -y mysql-client \
56
+ && apt-get clean \
57
+ && rm -rf /var/lib/apt/lists/*
58
+ <% elsif database == "postgresql" %>
59
+ # install postgresql
60
+ RUN apt-get update -qq && apt-get install -y postgresql-client \
61
+ && apt-get clean \
62
+ && rm -rf /var/lib/apt/lists/*
63
+ <% end %>
64
+ # install Nodejs 10.13.0 and Yarn 1.10.1
65
+ ENV NODE_VERSION=10.13.0 YARN_VERSION=1.10.1
66
+ COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
67
+ COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
68
+ COPY --from=nodejs /opt/yarn-v1.10.1/ /opt/yarn-v1.10.1/
69
+
70
+ WORKDIR /app
71
+
72
+ COPY --from=builder /usr/local/bundle /usr/local/bundle
73
+ COPY --from=builder /app/ /app/
74
+
75
+ CMD [ "sh", "-c", "bundle exec rake db:create db:migrate && bundle exec rails server -b 0.0.0.0" ]
@@ -4,13 +4,18 @@ services:
4
4
  build:
5
5
  dockerfile: ./docker/development/Dockerfile
6
6
  context: ./
7
+ <% if @github_private == 'yes' %>
8
+ args:
9
+ - GITHUB_TOKEN=${GITHUB_TOKEN}
10
+ - GITHUB_USERNAME=${GITHUB_USERNAME}
11
+ <% end %>
7
12
  container_name: web
8
13
  stdin_open: true
9
14
  tty: true
10
15
  command: "bash ./docker/development/entrypoint.sh"
11
16
  volumes:
12
17
  - .:/app
13
- - ./volumes/bundle:/usr/local/bundle
18
+ - gems:/usr/local/bundle
14
19
  ports:
15
20
  - "3000:3000"
16
21
  depends_on:
@@ -25,14 +30,14 @@ services:
25
30
  environment:
26
31
  MYSQL_ROOT_PASSWORD: password
27
32
  volumes:
28
- - ./volumes/mysql:/var/lib/mysql
33
+ - database:/var/lib/mysql
29
34
  <% elsif database == "postgresql" %>
30
35
  db:
31
36
  image: postgres:9.6
32
37
  # ports:
33
38
  # - "5432:5432"
34
39
  volumes:
35
- - ./volumes/postgresql:/var/lib/postgresql/data
40
+ - database:/var/lib/postgresql/data
36
41
  <% end %>
37
42
  # redis:
38
43
  # image: redis
@@ -44,13 +49,17 @@ services:
44
49
  # - 1025:1025
45
50
  # - 1080:1080
46
51
 
52
+ volumes:
53
+ gems:
54
+ database:
55
+
47
56
  # USAGE
48
57
 
49
- # execute a container for run rails console or rake tasks
58
+ # Execute a container for run rails console or rake tasks
50
59
  # docker-compose run --rm web bash
51
60
 
52
- # attach the container when use binding.pry
61
+ # Attach the container when use binding.pry
53
62
  # docker attach web
54
63
 
55
- # when run rails generator you need to run
56
- # sudo chown -R $USER:$USER $(ls | grep -v volumes)
64
+ # When run rails generator you need to run
65
+ # sudo chown -R $USER:$USER .
@@ -1,11 +1,12 @@
1
- # Ignore all logfiles and tempfiles.
1
+ # Ignore all files from .gitignore
2
+ # cat .gitignore > .dockerignore && cat .gitignore >> .dockerignore
3
+
2
4
  /log/*
3
5
  /tmp/*
4
6
 
5
7
  .byebug_history
6
8
 
7
9
  volumes
8
- .git
9
10
 
10
11
  public/packs
11
12
  public/packs-test
@@ -15,3 +16,4 @@ node_modules
15
16
  coverage
16
17
  yarn-error.log
17
18
  .DS_Store
19
+ .git
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DockerizeStack
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerize-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Savignano
@@ -38,7 +38,6 @@ files:
38
38
  - lib/rails/dockerize_rails.rb
39
39
  - lib/rails/templates/config/database-docker.yml.erb
40
40
  - lib/rails/templates/docker-compose.yml.erb
41
- - lib/rails/templates/docker/Dockerfile.production.erb
42
41
  - lib/rails/templates/docker/development/Dockerfile.erb
43
42
  - lib/rails/templates/docker/development/entrypoint.sh.erb
44
43
  - lib/rails/templates/docker/kubernetes/scripts/deploy.sh
@@ -57,9 +56,9 @@ files:
57
56
  - lib/rails/templates/docker/production/nginx/entrypoint.sh
58
57
  - lib/rails/templates/docker/production/nginx/etc/nginx/conf.d/default.conf
59
58
  - lib/rails/templates/docker/production/nginx/etc/nginx/nginx.conf
59
+ - lib/rails/templates/docker/production/rails/Dockerfile.erb
60
60
  - lib/rails/templates/docker/production/rails/entrypoint.sh
61
61
  - lib/rails/templates/dockerignore.erb
62
- - lib/rails/templates/id_rsa.sample
63
62
  - lib/version.rb
64
63
  homepage: https://github.com/MiguelSavignano/dockerize-stack
65
64
  licenses:
@@ -1,89 +0,0 @@
1
- FROM ruby:<%= ruby_version %> as builder
2
-
3
- ENV RAILS_ENV=production
4
- ENV NODE_ENV=production
5
-
6
- # install common dev libs
7
- RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y \
8
- build-essential \
9
- apt-transport-https \
10
- git \
11
- curl
12
- <% if database == "mysql" %>
13
- # install mysql
14
- RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y libmysqlclient-dev mysql-client
15
- <% elsif database == "postgresql" %>
16
- # install postgresql
17
- RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y libpq-dev postgresql-client
18
- <% end %>
19
- # install node 8.9.1 LTS
20
- RUN curl -sL https://deb.nodesource.com/setup_8.x | bin/bash - \
21
- && apt-get update -qq && apt-get dist-upgrade -y && apt-get update && apt-get install -y nodejs
22
-
23
- # install yarn
24
- RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
25
- && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
26
- && apt-get update && apt-get dist-upgrade -y && apt-get update && apt-get install yarn
27
-
28
- RUN mkdir /app
29
- WORKDIR /app
30
-
31
- # ************Install Ruby gems***************************
32
- # Invalidate gems cache if change Gemfile or Gemfile.lock
33
- COPY Gemfile Gemfile.lock /app/
34
- RUN bundle install -j 4 --without development test staging --deployment
35
- # ******************************************************
36
-
37
- # ********Install Node packages************************
38
- # Invalidate node_modules cache if yarn.lock change
39
- COPY package.json yarn.lock /app/
40
- RUN yarn install --pure-lockfile --production
41
- # ****************************************************
42
-
43
- COPY . /app
44
- RUN rails assets:precompile
45
-
46
- # *******************************************
47
- # **************** Multi Stage **************
48
- # *******************************************
49
- FROM ruby:2.5.0-slim
50
-
51
- ENV RAILS_ENV=production
52
- ENV NODE_ENV=production
53
-
54
- <% if database == "mysql" %>
55
- # install mysql
56
- RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y mysql-client º
57
- && apt-get clean \
58
- && rm -rf /var/lib/apt/lists/*
59
- <% elsif database == "postgresql" %>
60
- # install postgresql
61
- RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y postgresql-client \
62
- && apt-get clean \
63
- && rm -rf /var/lib/apt/lists/*
64
- <% end %>
65
- # install node 8.9.1 LTS
66
- RUN curl -sL https://deb.nodesource.com/setup_8.x | bin/bash -
67
- RUN apt-get update && apt-get install -y nodejs \
68
- && apt-get clean \
69
- && rm -rf /var/lib/apt/lists/*
70
-
71
- RUN mkdir /app
72
- WORKDIR /app
73
-
74
- # ************Copy only Rails app, prevent copy unnecessary files (.dockerignore don't work)***************************
75
- COPY --from=builder /app/app /app/app
76
- COPY --from=builder /app/config /app/config
77
- COPY --from=builder /app/bin /app/bin
78
- COPY --from=builder /app/db /app/db
79
- COPY --from=builder /app/lib /app/lib
80
- COPY --from=builder /app/public /app/public
81
- COPY --from=builder /app/vendor /app/vendor
82
- COPY --from=builder /app/config.ru app/Gemfile app/Gemfile.lock app/Rakefile /app/
83
- # *********************************************************************************************************************
84
-
85
- COPY --from=builder /usr/local/bundle /usr/local/bundle
86
-
87
- COPY --from=builder /app/docker/production/rails/entrypoint.sh /app/docker/production/rails/entrypoint.sh
88
-
89
- CMD ["/app/docker/production/rails/entrypoint.sh"]
@@ -1 +0,0 @@
1
- Replace this file with your id_rsa.pub file