dockerize-stack 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87574780f266391e269351522bcb8014e0ede375bdee86b340dc1bc43e1ac405
4
- data.tar.gz: 8b206957467b456ffacc59612c7a15845cac8fca5e8234a673c016601ad96146
3
+ metadata.gz: 463c73cd30ce0f03ffbdeeffa99db4a7eedda9ac3611bd5c9e7ac8d477cc3d97
4
+ data.tar.gz: 7ec780a8f81ba600fc3e29a10456c8412c0cdaf8784dd99cb6476c3f86a7db5c
5
5
  SHA512:
6
- metadata.gz: e6cd4e4e84de9ef3e8042f016af769246d3926ce17657a7d77c9c9bf79a42f6dc6fd1d451118d8a4a843208f8f42f8e8d03a282edb145c31d924bd17461c8777
7
- data.tar.gz: 26c5b75ea1dca073fc4683ce4923779a503e4050cb6ab683ac9b75de3563803ce5ca3dc7f4341021eee45979305ec543f71fac0916df7945df4af0a075fd82be
6
+ metadata.gz: 5927bd9855ff172132ae13ded16c2b0a77ab46f7d8e5b81cee01fc0e81ca558ad2685ff6691e1b11246b4db8f4d6934bd2113384dd20b7d5137f80c9466489c1
7
+ data.tar.gz: 7572551ff734743ba341b0b0ea7408018571bacaf502b7e92c2cb341130535e8c58bb36623b446a15c24efd1d8c67103307a657135e3a6f7b75c1628979ff5e7
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
- # Dockerize Stack for development
1
+ # Dockerize Stack
2
2
 
3
- This it's a generator for generate Dockerfile and docker-compose for your application for development
3
+ This it's a generator for generate Dockerfile and docker-compose for your application for development and production
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
+ - Help to configure multiple applications using the same templates.
8
8
 
9
- This generator help you to have a basic template for your stack; focusing on develepment enviroment.
9
+ - 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...
10
+
11
+ - For deploy to kubernetes you need first Dockerfile for your application, this templates help to build optimize docker image for productions enviroments.
12
+
13
+ - Using templates is more easy customize docker build process (Dockerfile, docker-compose).
10
14
 
11
15
  ## Install
12
16
 
@@ -32,31 +36,29 @@ or use docker image
32
36
  docker run --user $(id -u) -it -v $(pwd):/usr/src devmasx/dockerize-stack rails
33
37
  ```
34
38
 
35
- This script ask you:
39
+ ## Rails Templates
40
+
41
+ [rails example](./examples/rails)
42
+
43
+ By default the Dockerfile config is for production enviroment; using docker multistage feature and ARG (Build arguments) at the build time this Dockerfile is the same for development and production.
36
44
 
37
- - Ruby version
38
- - Database type
45
+ See all options:
46
+
47
+ ```
48
+ dockerize-stack help rails
49
+ ```
39
50
 
40
- example files generate:
51
+ Build a docker image for development enviroment:
41
52
 
42
53
  ```
43
- /docker
44
- --development
45
- ----Dockerfile
46
- ----entrypoint.sh
47
- --production
48
- ----rails
49
- ------Dockerfile
50
- ------entrypoint.sh
51
- ----nginx
52
- ------Dockerfile
53
- ------entrypoint.sh
54
- /.dockerignore
55
- /docker-compose.yml
56
- /config/database-docker.yml
54
+ docker build -t rails-example \
55
+ --build-arg=BUNDLE_DEPLOYMENT="false" \
56
+ --build-arg=BUNDLE_WITHOUT="" \
57
+ --build-arg=NODE_ENV="" \
58
+ .
57
59
  ```
58
60
 
59
61
  ## TODO
60
62
 
61
63
  - [ ] Add integrations with all database types rails new supported ([mysql/postgresql/sqlite3/oracle/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc])
62
- - [x] Integrate Build with private repositorys
64
+ - [x] Integrate Build with private repositories
data/lib/config.yml ADDED
@@ -0,0 +1,28 @@
1
+ rails:
2
+ defaults:
3
+ ruby_version: "2.5.6"
4
+ nodejs_version: "10.16.3"
5
+ yarn_version: "1.17.3"
6
+ javascrit_package_manager:
7
+ - asset_pipeline
8
+ - yarn
9
+ - npm
10
+ database:
11
+ - postgresql
12
+ - mysql
13
+ rails_worker: true
14
+ github_private: false
15
+ kubernetes: false
16
+ questions:
17
+ ruby_version: "Ruby Version (default 2.5.6):"
18
+ javascrit_package_manager: What is your Javascript package manager?
19
+ database: What is your Database?
20
+ rails_worker: You need workers with sidekiq? y/n, (default y)
21
+ github_private: You need github token for private gems? y/n (default no)
22
+ kubernetes: You want generate docker-stack for kubernetes? y/n (default no)'
23
+
24
+ react:
25
+ defaults:
26
+ nodejs_version: "10.16.3"
27
+ questions:
28
+ nodejs_version: "Nodejs version (default 10.16.3):"
@@ -6,17 +6,57 @@ require_relative './dockerize_stack/rails.rb'
6
6
  module DockerizeStack
7
7
  class Command < Thor
8
8
  include Thor::Actions
9
+ include ThorActionsExtend
10
+ RAILS_CONFIG_DEFAULTS = CONFIG.dig(:rails, :defaults)
11
+
12
+ option :template_folder,
13
+ aliases: 't',
14
+ desc: 'Template folder path'
15
+ option :output_folder,
16
+ default: '.',
17
+ aliases: 'o',
18
+ desc: 'Output folder'
19
+ option :ruby_version,
20
+ banner: RAILS_CONFIG_DEFAULTS[:ruby_version],
21
+ desc: 'Ruby version'
22
+ option :javascrit_package_manager,
23
+ banner: 'npm',
24
+ enum: RAILS_CONFIG_DEFAULTS[:javascrit_package_manager]
25
+ option :nodejs_version,
26
+ banner: RAILS_CONFIG_DEFAULTS[:nodejs_version],
27
+ desc: 'Nodejs version'
28
+ option :yarn_version,
29
+ banner: RAILS_CONFIG_DEFAULTS[:yarn_version],
30
+ desc: 'Yarn version'
31
+ option :database,
32
+ banner: 'postgresql',
33
+ enum: RAILS_CONFIG_DEFAULTS[:database],
34
+ desc: 'Database type'
35
+ option :rails_worker,
36
+ type: :boolean,
37
+ banner: RAILS_CONFIG_DEFAULTS[:rails_worker],
38
+ desc: 'Rails sidekiq examples in docker-compose.yml'
39
+ option :github_private,
40
+ type: :boolean,
41
+ banner: RAILS_CONFIG_DEFAULTS[:github_private],
42
+ desc: 'Set GITHUB_USERNAME and GITHUB_TOKEN in dockerfile bundle config'
43
+ option :kubernetes,
44
+ type: :boolean,
45
+ banner: RAILS_CONFIG_DEFAULTS[:kubernetes],
46
+ desc: 'Basic examples for kubernetes config (minikube)'
9
47
 
10
- option :path
11
48
  desc 'rails', 'generate docker files for rails application'
12
49
  def rails
13
- DockerizeStack::Rails.new.generate_files(path: options[:path])
50
+ DockerizeStack::Rails.new.run(options)
14
51
  end
15
52
 
16
- option :path
53
+ option :template_folder, aliases: 't', desc: 'Template folder path'
54
+ option :output_folder, default: '.', aliases: 'o', desc: 'Output folder'
55
+ option :nodejs_version, banner: '10.16.3', dec: 'Nodejs version'
56
+
17
57
  desc 'react', 'generate docker files for create react app'
18
58
  def react
19
- DockerizeStack::React.new.generate_files(path: options[:path])
59
+ DockerizeStack::React.new.run(options)
20
60
  end
21
61
  end
22
62
  end
@@ -4,27 +4,30 @@ module DockerizeStack
4
4
  include Thor::Actions
5
5
  include ThorActionsExtend
6
6
 
7
- attr_accessor :ruby_version, :nodejs_version, :yarn_version,
8
- :database, :github_private, :kubernetes, :workdir
9
-
10
- def self.source_root
11
- "#{File.dirname(__FILE__)}/../../templates/rails"
12
- end
7
+ attr_accessor :ruby_version, :javascrit_package_manager, :nodejs_version,
8
+ :yarn_version, :database, :github_private, :kubernetes, :output_folder
13
9
 
14
10
  no_commands do
15
- def generate_files(path:)
16
- @workdir = path || '.'
17
- @nodejs_version = '10.16.3'
18
- @yarn_version = '1.17.3'
19
-
20
- @ruby_version = ask_with_default('Ruby Version (default 2.5.6):', '2.5.6')
21
- @database = ask('What is your Database?', limited_to: ['postgresql', 'mysql'])
22
- @rails_worker = ask_with_default('You need worker service (sidekiq example) (default yes):', 'yes')
23
- @github_private = ask_with_default('You need github token for private gems? (default no):', 'no')
24
- @kubernetes = ask_with_default('You want generate docker-stack for kubernetes? y/n', 'n')
25
-
26
- render_templates
27
- render_kubernetes_templates unless ['n', 'no', ''].include?(@kubernetes)
11
+ def template_type
12
+ :rails
13
+ end
14
+
15
+ def run(options)
16
+ super(options)
17
+ render_kubernetes_templates if @kubernetes
18
+ end
19
+
20
+ def fetch_template_variables
21
+ @output_folder = with_default(:output_folder)
22
+ @nodejs_version = with_default(:nodejs_version)
23
+ @yarn_version = with_default(:yarn_version)
24
+
25
+ @ruby_version = ask_with_default(:ruby_version)
26
+ @javascrit_package_manager = ask_with_options(:javascrit_package_manager)
27
+ @database = ask_with_options(:database)
28
+ @rails_worker = ask_with_default_boolean(:rails_worker)
29
+ @github_private = ask_with_default_boolean(:github_private)
30
+ @kubernetes = ask_with_default_boolean(:kubernetes)
28
31
  end
29
32
 
30
33
  def render_templates
@@ -38,7 +41,7 @@ module DockerizeStack
38
41
  end
39
42
 
40
43
  def render_kubernetes_templates
41
- directory 'kubernetes', "#{@workdir}/kubernetes"
44
+ directory 'kubernetes', "#{@output_folder}/kubernetes"
42
45
  end
43
46
  end
44
47
  end
@@ -6,25 +6,23 @@ module DockerizeStack
6
6
  include Thor::Actions
7
7
  include ThorActionsExtend
8
8
 
9
- attr_accessor :nodejs_version, :workdir
10
-
11
- def self.source_root
12
- "#{File.dirname(__FILE__)}/../../templates/react"
13
- end
9
+ attr_accessor :nodejs_version, :output_folder
14
10
 
15
11
  no_commands do
16
- def generate_files(path: '.')
17
- @workdir = path
18
- @nodejs_version = ask_with_default('Nodejs Version (default 10):', '10')
12
+ def template_type
13
+ :react
14
+ end
19
15
 
20
- render_templates
16
+ def fetch_template_variables
17
+ @output_folder = with_default(:output_folder)
18
+ @nodejs_version = ask_with_default(:nodejs_version)
21
19
  end
22
20
 
23
21
  def render_templates
24
22
  render_template 'Dockerfile.erb'
25
- render_template '.dockerignore.erb'
23
+ render_template 'dockerignore.erb', '.dockerignore'
26
24
 
27
- directory 'nginx', "#{@workdir}/nginx"
25
+ directory 'nginx', "#{@output_folder}/nginx"
28
26
  end
29
27
  end
30
28
  end
data/lib/thor_extend.rb CHANGED
@@ -1,14 +1,63 @@
1
+ require 'yaml'
2
+ require 'json'
3
+
1
4
  module ThorActionsExtend
2
5
  include Thor::Actions
3
6
 
7
+ CONFIG = JSON.parse(
8
+ JSON.dump(YAML.load_file("#{File.dirname(__FILE__)}/config.yml")),
9
+ symbolize_names: true
10
+ )
11
+ def run(options)
12
+ @template_type = template_type
13
+ @options = options
14
+ @config = CONFIG[@template_type]
15
+ self.class.source_root(template_folder(@template_type.to_s))
16
+
17
+ fetch_template_variables
18
+ render_templates
19
+ end
20
+
4
21
  private
22
+
23
+ def template_folder(template_type)
24
+ @options[:template_folder] || "#{File.dirname(__FILE__)}/../templates/#{template_type}"
25
+ end
26
+
5
27
  def render_template(path, target_path = path)
6
- template path, "#{@workdir}/#{target_path.gsub('.erb', '')}"
28
+ template path, "#{@output_folder}/#{target_path.gsub('.erb', '')}"
29
+ end
30
+
31
+ def with_default(option)
32
+ return @config[:defaults][option] if @options[option].nil?
33
+
34
+ @options[option]
7
35
  end
8
36
 
9
- def ask_with_default(question = '', default = '')
10
- result = ask(question)
11
- result != '' ? result : default
37
+ def ask_with_default(option, default = nil)
38
+ return @options[option] unless @options[option].nil?
39
+
40
+ default = @config[:defaults][option] if default.nil?
41
+ result = ask(@config[:questions][option])
42
+
43
+ result == '' ? default : result
44
+ end
45
+
46
+ def ask_with_options(option, limited_to = nil)
47
+ return @options[option] if @options[option]
48
+
49
+ limited_to = @config[:defaults][option] if limited_to.nil?
50
+ ask(@config[:questions][option], limited_to: limited_to)
51
+ end
52
+
53
+ def ask_with_default_boolean(option)
54
+ return @options[option] unless @options[option].nil?
55
+
56
+ result = ask(@config[:questions][option])
57
+ default = @config[:defaults][option] if default.nil?
58
+ return default if result == ''
59
+
60
+ %w[yes y true].include?(result) ? true : false
12
61
  end
13
62
 
14
63
  def append_or_create(file_path, file_content)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DockerizeStack
2
- VERSION = "0.5.2"
2
+ VERSION = '0.6.0'
3
3
  end
@@ -1,9 +1,9 @@
1
1
  # ****************************
2
2
  # ******Build base stage******
3
3
  # ****************************
4
-
4
+ <% if javascrit_package_manager != "asset_pipeline" %>
5
5
  FROM node:<%= nodejs_version %>-slim as nodejs
6
-
6
+ <% end %>
7
7
  FROM ruby:<%= ruby_version %>-slim as builder
8
8
 
9
9
  # Install common libs
@@ -16,12 +16,18 @@ RUN apt-get install -y mysql-client libmysqlclient-dev
16
16
  # Install Postgresql
17
17
  RUN apt-get install -y postgresql-client libpq-dev
18
18
  <% end %>
19
- # Install Nodejs and Yarn
19
+ # Install Nodejs<% if javascrit_package_manager == "asset_pipeline" %>
20
+ RUN apt-get install -y nodejs npm
21
+ <% elsif javascrit_package_manager == "yarn" %>
20
22
  ENV NODE_VERSION=<%= nodejs_version %> YARN_VERSION=<%= yarn_version %>
21
23
  COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
22
24
  COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
23
25
  COPY --from=nodejs /opt/yarn-v<%= yarn_version %>/ /opt/yarn-v<%= yarn_version %>/
24
-
26
+ <% elsif javascrit_package_manager == "npm" %>
27
+ ENV NODE_VERSION=<%= nodejs_version %>
28
+ COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
29
+ COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
30
+ <% end %>
25
31
  WORKDIR /app
26
32
  <% if @github_private == 'yes' %>
27
33
  # Private repository
@@ -29,7 +35,6 @@ ARG GITHUB_TOKEN
29
35
  ARG GITHUB_USERNAME
30
36
  RUN bundle config github.com ${GITHUB_USERNAME}:${GITHUB_TOKEN}
31
37
  <% end %>
32
-
33
38
  # Production config
34
39
  ARG BUNDLE_DEPLOYMENT=true
35
40
  ARG BUNDLE_WITHOUT="development test staging"
@@ -41,11 +46,16 @@ ENV NODE_ENV=$NODE_ENV
41
46
  # Gems cache layer
42
47
  COPY Gemfile Gemfile.lock /app/
43
48
  RUN bundle install -j 4
44
-
49
+ <% if javascrit_package_manager == "yarn" %>
45
50
  # Node modules cache layer
46
51
  COPY package.json yarn.lock /app/
47
52
  RUN yarn install --pure-lockfile
48
-
53
+ <% elsif javascrit_package_manager == "npm" %>
54
+ # Node modules cache layer
55
+ COPY package.json package-lock.json /app/
56
+ RUN npm ci
57
+ <% elsif javascrit_package_manager == "asset_pipeline" %>
58
+ <% end %>
49
59
  COPY . .
50
60
  CMD "./entrypoint.sh"
51
61
 
@@ -57,8 +67,9 @@ FROM builder as production-builder
57
67
 
58
68
  # Build production assets
59
69
  RUN bundle exec rails assets:precompile
70
+ <% if javascrit_package_manager != "asset_pipeline" %>
60
71
  RUN rm -r node_modules
61
-
72
+ <% end %>
62
73
  # **********************************
63
74
  # ******Final production Stage******
64
75
  # **********************************
@@ -68,11 +79,18 @@ FROM ruby:<%= ruby_version %>-slim
68
79
  ENV NODE_ENV=production RAILS_ENV=production RAILS_LOG_TO_STDOUT=true
69
80
 
70
81
  # Install system dependencies
82
+ <% if javascrit_package_manager != "asset_pipeline" %>
71
83
  COPY --from=nodejs /usr/local/ /usr/local/
84
+ <% end %><% if javascrit_package_manager == "asset_pipeline" %>
72
85
  RUN apt-get update -qq && apt-get install -y \
73
86
  libpq-dev \
87
+ nodejs \
74
88
  && apt-get clean && rm -rf /var/lib/apt/lists/*
75
-
89
+ <% else %>
90
+ RUN apt-get update -qq && apt-get install -y \
91
+ libpq-dev \
92
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
93
+ <% end %>
76
94
  WORKDIR /app
77
95
 
78
96
  RUN groupadd -r deploy && useradd -r -g deploy deploy
@@ -1,5 +1,7 @@
1
1
  bundle check || bundle install
2
2
  rake db:create db:migrate
3
3
  rm -f tmp/pids/server.pid
4
+ <% if javascrit_package_manager == "asset_pipeline" %>
4
5
  rm -rf public/packs/* || true && bin/webpack-dev-server &
6
+ <% end %>
5
7
  bundle exec rails server -p 3000 -b 0.0.0.0
@@ -0,0 +1,27 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+ # echo .git > .dockerignore && cat .gitignore >> .dockerignore
3
+
4
+ .git
5
+ Dockerfile
6
+
7
+ # dependencies
8
+ /node_modules
9
+ /.pnp
10
+ .pnp.js
11
+
12
+ # testing
13
+ /coverage
14
+
15
+ # production
16
+ /build
17
+
18
+ # misc
19
+ .DS_Store
20
+ .env.local
21
+ .env.development.local
22
+ .env.test.local
23
+ .env.production.local
24
+
25
+ npm-debug.log*
26
+ yarn-debug.log*
27
+ yarn-error.log*
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.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Savignano
@@ -34,6 +34,7 @@ files:
34
34
  - LICENSE
35
35
  - README.md
36
36
  - bin/dockerize-stack
37
+ - lib/config.yml
37
38
  - lib/dockerize_stack.rb
38
39
  - lib/dockerize_stack/rails.rb
39
40
  - lib/dockerize_stack/react.rb
@@ -60,6 +61,7 @@ files:
60
61
  - templates/rails/nginx/etc/nginx/conf.d/default.conf
61
62
  - templates/rails/nginx/etc/nginx/nginx.conf
62
63
  - templates/react/Dockerfile.erb
64
+ - templates/react/dockerignore.erb
63
65
  - templates/react/nginx/conf.d/default.conf.template
64
66
  homepage: https://github.com/MiguelSavignano/dockerize-stack
65
67
  licenses:
@@ -80,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  - !ruby/object:Gem::Version
81
83
  version: '0'
82
84
  requirements: []
83
- rubyforge_project:
84
- rubygems_version: 2.7.9
85
+ rubygems_version: 3.0.3
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: DockerizeStack