dockerize-stack 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/bin/dockerize-stack +2 -3
  3. data/lib/dockerize_stack/rails.rb +45 -0
  4. data/lib/dockerize_stack/react.rb +31 -0
  5. data/lib/dockerize_stack.rb +7 -4
  6. data/lib/thor_extend.rb +21 -0
  7. data/lib/version.rb +1 -1
  8. data/templates/rails/Dockerfile.erb +84 -0
  9. data/templates/rails/config/database-docker.yml.erb +14 -13
  10. data/templates/rails/docker-compose.yml.erb +73 -38
  11. data/templates/rails/{docker/development/entrypoint.sh.erb → entrypoint.sh.erb} +1 -2
  12. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/deploy.sh +0 -0
  13. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/get-secrets.sh +0 -0
  14. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/remoteconsole.sh +0 -0
  15. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/set-config-map.sh +0 -0
  16. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/set-secrets.sh +0 -0
  17. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/set-services.sh +0 -0
  18. data/templates/rails/{docker/kubernetes → kubernetes}/scripts/set-workloads.sh +0 -0
  19. data/templates/rails/{docker/kubernetes → kubernetes}/services/cloudsql-proxy.yaml +0 -0
  20. data/templates/rails/{docker/kubernetes → kubernetes}/services/rails-nginx.yaml +0 -0
  21. data/templates/rails/{docker/kubernetes → kubernetes}/workloads/cloudsql-proxy.yaml +0 -0
  22. data/templates/rails/{docker/kubernetes → kubernetes}/workloads/rails-nginx.yaml +0 -0
  23. data/templates/rails/{docker/production/nginx → nginx}/Dockerfile +0 -0
  24. data/templates/rails/{docker/production/nginx → nginx}/entrypoint.sh +0 -0
  25. data/templates/rails/{docker/production/nginx → nginx}/etc/nginx/conf.d/default.conf +0 -0
  26. data/templates/rails/{docker/production/nginx → nginx}/etc/nginx/nginx.conf +0 -0
  27. data/templates/react/{docker/Dockerfile.erb → Dockerfile.erb} +0 -0
  28. data/templates/react/{docker/nginx → nginx}/conf.d/default.conf.template +0 -0
  29. metadata +24 -28
  30. data/lib/rails/dockerize_rails.rb +0 -56
  31. data/lib/react/dockerize_react.rb +0 -42
  32. data/templates/rails/docker/development/Dockerfile.erb +0 -37
  33. data/templates/rails/docker/production/dockerbuild.sh +0 -41
  34. data/templates/rails/docker/production/rails/Dockerfile.erb +0 -75
  35. data/templates/rails/docker/production/rails/entrypoint.sh +0 -7
  36. data/templates/rails/dockerignore.erb +0 -19
  37. data/templates/react/dockerignore.erb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cfe36dfc76fc4f7a14199e2497c973eb97b7b47b
4
- data.tar.gz: fbf1d1c97d0b81fea077fb21082449154f1c46d8
2
+ SHA256:
3
+ metadata.gz: 3e82ca81b46c88bfa939a33e3c44e8a9c04778bd924979bc62e7def00a638f37
4
+ data.tar.gz: 0d2e31d131f2286ce3ef35b1e7d8c56e6941d7ec6f3279c157f19fbdc1a0c2dc
5
5
  SHA512:
6
- metadata.gz: b63a77f1af76cd2286ca344da387021cdb3e460c2c2596793d900298b92c8dee8de1842256a646dcdb956cd4a141dd6d45ec115e8deb3231c383f54aeb87bb46
7
- data.tar.gz: a0395469e6bb265c984657cf64df357949f323d59e182e69e4db2e4d55b5f7937f607b0d082aa54db82eb32bc7b2465b2f4b2fcf76ce1b4bec45a08d8f7e1432
6
+ metadata.gz: 441dbcb2139baebc88be23fdfe8a98aaed0f3f691a20e06ab39c4a5a8155814724bacdcedb8f3aa9d1615091c9105d878e3032aea5d1cd102bb81bd54b079b00
7
+ data.tar.gz: 8f40e9c13e84abbf500e7ffa607c345badfb4cd86f3cbef1dc42099750d99a7dd1149f8bd2b6e9e77ab11a02adc8c9a9dd0b29632b7e8c00a2d6cddc1f30832b
data/bin/dockerize-stack CHANGED
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- require 'dockerize_stack'
3
-
4
- DockerizeStack::Command.start
2
+ require_relative '../lib/dockerize_stack'
3
+ DockerizeStack::Command.start(ARGV)
@@ -0,0 +1,45 @@
1
+ module DockerizeStack
2
+ # Ask variables and render templates
3
+ class Rails < Thor
4
+ include Thor::Actions
5
+ include ThorActionsExtend
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
13
+
14
+ 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)
28
+ end
29
+
30
+ def render_templates
31
+ render_template 'Dockerfile.erb'
32
+ render_template 'entrypoint.sh.erb'
33
+ render_template 'docker-compose.yml.erb'
34
+ render_template 'config/database-docker.yml.erb'
35
+ render_template '.dockerignore.erb'
36
+
37
+ puts 'Update your database.yml based in database-docker.yml'
38
+ end
39
+
40
+ def render_kubernetes_templates
41
+ directory 'kubernetes', "#{@workdir}/kubernetes"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ require 'thor'
2
+ # Ask variables and render templates
3
+ module DockerizeStack
4
+ # Ask variables and render templates
5
+ class React < Thor
6
+ include Thor::Actions
7
+ include ThorActionsExtend
8
+
9
+ attr_accessor :nodejs_version, :workdir
10
+
11
+ def self.source_root
12
+ "#{File.dirname(__FILE__)}/../../templates/react"
13
+ end
14
+
15
+ no_commands do
16
+ def generate_files(path: '.')
17
+ @workdir = path
18
+ @nodejs_version = ask_with_default('Nodejs Version (default 10):', '10')
19
+
20
+ render_templates
21
+ end
22
+
23
+ def render_templates
24
+ render_template 'Dockerfile.erb'
25
+ render_template '.dockerignore.erb'
26
+
27
+ directory 'nginx', "#{@workdir}/nginx"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,19 +1,22 @@
1
1
  require 'thor'
2
- require 'rails/dockerize_rails'
3
- require 'react/dockerize_react'
2
+ require_relative './thor_extend.rb'
3
+ require_relative './dockerize_stack/react.rb'
4
+ require_relative './dockerize_stack/rails.rb'
4
5
 
5
6
  module DockerizeStack
6
7
  class Command < Thor
7
8
  include Thor::Actions
8
9
 
10
+ option :path
9
11
  desc 'rails', 'generate docker files for rails application'
10
12
  def rails
11
- DockerizeRails.new.generate_files
13
+ DockerizeStack::Rails.new.generate_files(path: options[:path])
12
14
  end
13
15
 
16
+ option :path
14
17
  desc 'react', 'generate docker files for create react app'
15
18
  def react
16
- DockerizeReact.new.generate_files
19
+ DockerizeStack::React.new.generate_files(path: options[:path])
17
20
  end
18
21
  end
19
22
  end
@@ -0,0 +1,21 @@
1
+ module ThorActionsExtend
2
+ include Thor::Actions
3
+
4
+ private
5
+ def render_template(path)
6
+ template path, "#{@workdir}/#{path.gsub('.erb', '')}"
7
+ end
8
+
9
+ def ask_with_default(question = '', default = '')
10
+ result = ask(question)
11
+ result != '' ? result : default
12
+ end
13
+
14
+ def append_or_create(file_path, file_content)
15
+ if File.exist?(file_path)
16
+ append_to_file file_path, file_content
17
+ else
18
+ create_file file_path, file_content
19
+ end
20
+ end
21
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DockerizeStack
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,84 @@
1
+ # ****************************
2
+ # ******Build base stage******
3
+ # ****************************
4
+
5
+ FROM node:<%= nodejs_version %>-slim as nodejs
6
+
7
+ FROM ruby:<%= ruby_version %>-slim
8
+
9
+ # Install common dev libs
10
+ RUN apt-get update -qq && apt-get install -y \
11
+ build-essential vim git
12
+ <% if database == "mysql" %>
13
+ # Install Mysql
14
+ RUN apt-get install -y mysql-client libmysqlclient-dev
15
+ <% elsif database == "postgresql" %>
16
+ # Install Postgresql
17
+ RUN apt-get install -y postgresql-client libpq-dev
18
+ <% end %>
19
+ # Install Nodejs and Yarn
20
+ ENV NODE_VERSION=<%= nodejs_version %> YARN_VERSION=<%= yarn_version %>
21
+ COPY --from=nodejs /usr/local/bin/ /usr/local/bin/
22
+ COPY --from=nodejs /usr/local/lib/ /usr/local/lib/
23
+ COPY --from=nodejs /opt/yarn-v<%= yarn_version %>/ /opt/yarn-v<%= yarn_version %>/
24
+
25
+ WORKDIR /app
26
+ <% if @github_private == 'yes' %>
27
+ # Private repository
28
+ ARG GITHUB_TOKEN
29
+ ARG GITHUB_USERNAME
30
+ RUN bundle config github.com ${GITHUB_USERNAME}:${GITHUB_TOKEN}
31
+ <% end %>
32
+
33
+ # Production config
34
+ ARG BUNDLE_DEPLOYMENT=true
35
+ ARG BUNDLE_WITHOUT="development test staging"
36
+ ARG NODE_ENV=production
37
+
38
+ ENV BUNDLE_DEPLOYMENT=$BUNDLE_DEPLOYMENT BUNDLE_WITHOUT=$BUNDLE_WITHOUT
39
+ ENV NODE_ENV=$NODE_ENV
40
+
41
+ # Gems cache layer
42
+ COPY Gemfile Gemfile.lock /app/
43
+ RUN bundle install -j 4
44
+
45
+ # Node modules cache layer
46
+ COPY package.json yarn.lock /app/
47
+ RUN yarn install --pure-lockfile
48
+
49
+ COPY . .
50
+ CMD "./entrypoint.sh"
51
+
52
+ # ****************************
53
+ # ******Production stage******
54
+ # ****************************
55
+
56
+ FROM builder as production-builder
57
+
58
+ # Build production assets
59
+ RUN bundle exec rails assets:precompile
60
+ RUN rm -r node_modules
61
+
62
+ # **********************************
63
+ # ******Final production Stage******
64
+ # **********************************
65
+
66
+ FROM ruby:<%= ruby_version %>-slim
67
+
68
+ ENV NODE_ENV=production RAILS_ENV=production RAILS_LOG_TO_STDOUT=true
69
+
70
+ # Install system dependencies
71
+ COPY --from=nodejs /usr/local/ /usr/local/
72
+ RUN apt-get update -qq && apt-get install -y \
73
+ libpq-dev \
74
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
75
+
76
+ WORKDIR /app
77
+
78
+ RUN groupadd -r deploy && useradd -r -g deploy deploy
79
+ USER deploy
80
+
81
+ COPY --from=production-builder --chown=deploy:deploy /usr/local/bundle /usr/local/bundle
82
+ COPY --from=production-builder --chown=deploy:deploy /app /app
83
+
84
+ CMD [ "sh", "-c", "bundle exec rake db:create db:migrate && bundle exec rails server -b 0.0.0.0" ]
@@ -6,11 +6,13 @@
6
6
 
7
7
  default: &default
8
8
  adapter: postgresql
9
- pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
- encoding: utf8
11
- host: db
12
- username: postgres
13
- password:
9
+ encoding: unicode
10
+ # For details on connection pooling, see Rails configuration guide
11
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
12
+ host: <%%= ENV.fetch("DATABASE_HOST") { "127.0.0.1" } %>
13
+ username: <%%= ENV.fetch("DATABASE_USERNAME") { "postgres" } %>
14
+ password: <%%= ENV.fetch("DATABASE_PASSWORD") { "" } %>
15
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
14
16
 
15
17
  <% elsif database == "mysql" %>
16
18
  # Install the MySQL driver
@@ -19,10 +21,12 @@ default: &default
19
21
  default: &default
20
22
  adapter: mysql2
21
23
  encoding: utf8
22
- pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
23
- host: db
24
- username: root
25
- password: password
24
+ # For details on connection pooling, see Rails configuration guide
25
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
26
+ host: <%%= ENV.fetch("DATABASE_HOST") { "127.0.0.1" } %>
27
+ username: <%%= ENV.fetch("DATABASE_USERNAME") { "root" } %>
28
+ password: <%%= ENV.fetch("DATABASE_PASSWORD") { "password" } %>
29
+ pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
26
30
 
27
31
  <% end %>
28
32
  development:
@@ -35,7 +39,4 @@ test:
35
39
 
36
40
  production:
37
41
  <<: *default
38
- host: <%= ENV["DATABASE_HOST"] %>
39
- database: <%= ENV["DATABASE_NAME"] %>
40
- username: <%= ENV["DATABASE_USERNAME"] %>
41
- password: <%= ENV["DATABASE_PASSWORD"] %>
42
+ database: <%%= ENV.fetch("DATABASE_NAME") { "myapp_production" } %>
@@ -1,65 +1,100 @@
1
- version: '3'
1
+ version: "3.4"
2
2
  services:
3
3
  web:
4
4
  build:
5
- dockerfile: ./docker/development/Dockerfile
6
- context: ./
7
- <% if @github_private == 'yes' %>
8
5
  args:
9
- - GITHUB_TOKEN=${GITHUB_TOKEN}
10
- - GITHUB_USERNAME=${GITHUB_USERNAME}
11
- <% end %>
6
+ BUNDLE_DEPLOYMENT: "false"
7
+ BUNDLE_WITHOUT: ""
8
+ NODE_ENV: development
9
+ target: builder
10
+ context: ./
11
+ dockerfile: ./Dockerfile
12
+ image: dockerize-rails
12
13
  container_name: web
13
14
  stdin_open: true
14
15
  tty: true
15
- command: "bash ./docker/development/entrypoint.sh"
16
16
  volumes:
17
- - .:/app
18
- - gems:/usr/local/bundle
17
+ - .:/app:delegated
18
+ - bundle:/usr/local/bundle:delegated
19
+ - node_modules:/app/node_modules:delegated
19
20
  ports:
20
21
  - "3000:3000"
21
22
  depends_on:
22
23
  - db
23
- # env_file:
24
- # - web.env
25
- <% if database == "mysql" %>
26
- db:
27
- image: 'mysql:5.7'
28
- # ports:
29
- # - "3306:3306"
30
24
  environment:
31
- MYSQL_ROOT_PASSWORD: password
25
+ DATABASE_HOST: db
26
+ # sidekiq redis
27
+ # https://github.com/mperham/sidekiq/wiki/Using-Redis
28
+ REDIS_PROVIDER: REDISGREEN_URL
29
+ REDISGREEN_URL: redis://redis:6379/0
30
+
31
+ worker:
32
+ image: dockerize-rails
33
+ container_name: worker
34
+ stdin_open: true
35
+ tty: true
36
+ command: bundle exec sidekiq -q default -q mailers
32
37
  volumes:
33
- - database:/var/lib/mysql
34
- <% elsif database == "postgresql" %>
38
+ - .:/app:delegated
39
+ - bundle:/usr/local/bundle:delegated
40
+ - node_modules:/app/node_modules:delegated
41
+ depends_on:
42
+ - db
43
+ environment:
44
+ RAILS_MASTER_KEY: ea3aaacc43f832b6e9049e61211561dc
45
+ # sidekiq redis
46
+ # https://github.com/mperham/sidekiq/wiki/Using-Redis
47
+ REDIS_PROVIDER: REDISGREEN_URL
48
+ REDISGREEN_URL: redis://redis:6379/0
49
+
35
50
  db:
36
- image: postgres:9.6
51
+ image: postgres:9.5.9
37
52
  # ports:
38
53
  # - "5432:5432"
39
54
  volumes:
40
- - database:/var/lib/postgresql/data
41
- <% end %>
42
- # redis:
43
- # image: redis
44
- # ports:
45
- # - "6379:6379"
46
- # mailcatcher:
47
- # image: schickling/mailcatcher
48
- # ports:
49
- # - 1025:1025
50
- # - 1080:1080
55
+ - postgresql:/var/lib/postgresql/data:delegated
51
56
 
52
- volumes:
53
- gems:
54
- database:
57
+ redis:
58
+ image: redis
59
+ # ports:
60
+ # - "6379:6379"
55
61
 
62
+ mailcatcher:
63
+ image: schickling/mailcatcher
64
+ ports:
65
+ - 1025:1025
66
+ - 1080:1080
67
+
68
+ volumes:
69
+ postgresql:
70
+ bundle:
71
+ node_modules:
56
72
  # USAGE
57
73
 
58
- # Execute a container for run rails console or rake tasks
74
+ # ************************************
75
+ # **Start only external services (web service use local environment)**
76
+ # ************************************
77
+
78
+ # docker-compose up db redis mailcatcher
79
+ # bundle exec rails server
80
+ # bundle exec bundle exec sidekiq -q default -q mailers
81
+ # bin/webpack-dev-server
82
+
83
+ # ************************************
84
+ # **Development on ruby docker image**
85
+ # ************************************
86
+
87
+ # docker-compose buid web
88
+ # docker-compose up
89
+
90
+ # Run rails console
91
+ # docker-compose run --rm web rails console
92
+
93
+ # Enter in the container for run rails console or rake tasks
59
94
  # docker-compose run --rm web bash
60
95
 
61
- # Attach the container when use binding.pry
96
+ # Attach the container when use byebug or binding.pry
62
97
  # docker attach web
63
98
 
64
- # When run rails generator you need to run
99
+ # When run rails generator then you must run
65
100
  # sudo chown -R $USER:$USER .
@@ -1,6 +1,5 @@
1
1
  bundle check || bundle install
2
-
3
2
  rake db:create db:migrate
4
3
  rm -f tmp/pids/server.pid
5
- # rm -rf public/packs/* || true && bin/webpack-dev-server &
4
+ rm -rf public/packs/* || true && bin/webpack-dev-server &
6
5
  bundle exec rails server -p 3000 -b 0.0.0.0
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Savignano
@@ -35,35 +35,31 @@ files:
35
35
  - README.md
36
36
  - bin/dockerize-stack
37
37
  - lib/dockerize_stack.rb
38
- - lib/rails/dockerize_rails.rb
39
- - lib/react/dockerize_react.rb
38
+ - lib/dockerize_stack/rails.rb
39
+ - lib/dockerize_stack/react.rb
40
+ - lib/thor_extend.rb
40
41
  - lib/version.rb
42
+ - templates/rails/Dockerfile.erb
41
43
  - templates/rails/config/database-docker.yml.erb
42
44
  - templates/rails/docker-compose.yml.erb
43
- - templates/rails/docker/development/Dockerfile.erb
44
- - templates/rails/docker/development/entrypoint.sh.erb
45
- - templates/rails/docker/kubernetes/scripts/deploy.sh
46
- - templates/rails/docker/kubernetes/scripts/get-secrets.sh
47
- - templates/rails/docker/kubernetes/scripts/remoteconsole.sh
48
- - templates/rails/docker/kubernetes/scripts/set-config-map.sh
49
- - templates/rails/docker/kubernetes/scripts/set-secrets.sh
50
- - templates/rails/docker/kubernetes/scripts/set-services.sh
51
- - templates/rails/docker/kubernetes/scripts/set-workloads.sh
52
- - templates/rails/docker/kubernetes/services/cloudsql-proxy.yaml
53
- - templates/rails/docker/kubernetes/services/rails-nginx.yaml
54
- - templates/rails/docker/kubernetes/workloads/cloudsql-proxy.yaml
55
- - templates/rails/docker/kubernetes/workloads/rails-nginx.yaml
56
- - templates/rails/docker/production/dockerbuild.sh
57
- - templates/rails/docker/production/nginx/Dockerfile
58
- - templates/rails/docker/production/nginx/entrypoint.sh
59
- - templates/rails/docker/production/nginx/etc/nginx/conf.d/default.conf
60
- - templates/rails/docker/production/nginx/etc/nginx/nginx.conf
61
- - templates/rails/docker/production/rails/Dockerfile.erb
62
- - templates/rails/docker/production/rails/entrypoint.sh
63
- - templates/rails/dockerignore.erb
64
- - templates/react/docker/Dockerfile.erb
65
- - templates/react/docker/nginx/conf.d/default.conf.template
66
- - templates/react/dockerignore.erb
45
+ - templates/rails/entrypoint.sh.erb
46
+ - templates/rails/kubernetes/scripts/deploy.sh
47
+ - templates/rails/kubernetes/scripts/get-secrets.sh
48
+ - templates/rails/kubernetes/scripts/remoteconsole.sh
49
+ - templates/rails/kubernetes/scripts/set-config-map.sh
50
+ - templates/rails/kubernetes/scripts/set-secrets.sh
51
+ - templates/rails/kubernetes/scripts/set-services.sh
52
+ - templates/rails/kubernetes/scripts/set-workloads.sh
53
+ - templates/rails/kubernetes/services/cloudsql-proxy.yaml
54
+ - templates/rails/kubernetes/services/rails-nginx.yaml
55
+ - templates/rails/kubernetes/workloads/cloudsql-proxy.yaml
56
+ - templates/rails/kubernetes/workloads/rails-nginx.yaml
57
+ - templates/rails/nginx/Dockerfile
58
+ - templates/rails/nginx/entrypoint.sh
59
+ - templates/rails/nginx/etc/nginx/conf.d/default.conf
60
+ - templates/rails/nginx/etc/nginx/nginx.conf
61
+ - templates/react/Dockerfile.erb
62
+ - templates/react/nginx/conf.d/default.conf.template
67
63
  homepage: https://github.com/MiguelSavignano/dockerize-stack
68
64
  licenses:
69
65
  - MIT
@@ -84,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
80
  version: '0'
85
81
  requirements: []
86
82
  rubyforge_project:
87
- rubygems_version: 2.6.14
83
+ rubygems_version: 2.7.9
88
84
  signing_key:
89
85
  specification_version: 4
90
86
  summary: DockerizeStack
@@ -1,56 +0,0 @@
1
- require 'thor'
2
- # Ask variables and render templates
3
- class DockerizeRails < Thor
4
- include Thor::Actions
5
- attr_accessor :ruby_version, :database, :github_private, :docker_production
6
-
7
- WORKDIR = ".".freeze
8
-
9
- def self.source_root
10
- "#{File.dirname(__FILE__)}/../../templates"
11
- end
12
-
13
- desc 'generate_files', 'generate docker files for rails application'
14
- def generate_files
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')
19
-
20
- render_templates
21
- render_production_templates if @docker_production != 'n' || @docker_production != 'no'
22
- end
23
-
24
- no_commands do
25
- def render_templates
26
- template 'rails/docker/development/Dockerfile.erb', "#{WORKDIR}/docker/development/Dockerfile"
27
- template 'rails/docker/development/entrypoint.sh.erb', "#{WORKDIR}/docker/development/entrypoint.sh"
28
- template 'rails/docker-compose.yml.erb', "#{WORKDIR}/docker-compose.yml"
29
- template 'rails/config/database-docker.yml.erb', "#{WORKDIR}/config/database-docker.yml"
30
- template 'rails/dockerignore.erb', "#{WORKDIR}/.dockerignore"
31
- puts 'Update your database.yml based in database-docker.yml'
32
- end
33
-
34
- def render_production_templates
35
- directory 'rails/docker/production', "#{WORKDIR}/docker/production"
36
- directory 'rails/docker/kubernetes', "#{WORKDIR}/docker/kubernetes"
37
-
38
- template 'rails/docker/production/rails/Dockerfile.erb', "#{WORKDIR}/docker/production/rails/Dockerfile"
39
- end
40
- end
41
-
42
- private
43
-
44
- def ask_with_default(question = '', default = '')
45
- result = ask(question)
46
- result != '' ? result : default
47
- end
48
-
49
- def append_or_create(file_path, file_content)
50
- if File.exist?(file_path)
51
- append_to_file file_path, file_content
52
- else
53
- create_file file_path, file_content
54
- end
55
- end
56
- end
@@ -1,42 +0,0 @@
1
- require 'thor'
2
- # Ask variables and render templates
3
- class DockerizeReact < Thor
4
- include Thor::Actions
5
- attr_accessor :nodejs_version
6
-
7
- WORKDIR = ".".freeze
8
-
9
- def self.source_root
10
- "#{File.dirname(__FILE__)}/../../templates"
11
- end
12
-
13
- desc 'generate_files', 'generate docker files for react create app'
14
- def generate_files
15
- @nodejs_version = ask_with_default('Nodejs Version (default 10):', '10')
16
-
17
- render_templates
18
- end
19
-
20
- no_commands do
21
- def render_templates
22
- template 'react/docker/Dockerfile.erb', "#{WORKDIR}/docker/Dockerfile"
23
- template 'react/dockerignore.erb', "#{WORKDIR}/.dockerignore"
24
- directory 'react/docker/nginx', "#{WORKDIR}/docker/nginx"
25
- end
26
- end
27
-
28
- private
29
-
30
- def ask_with_default(question = '', default = '')
31
- result = ask(question)
32
- result != '' ? result : default
33
- end
34
-
35
- def append_or_create(file_path, file_content)
36
- if File.exist?(file_path)
37
- append_to_file file_path, file_content
38
- else
39
- create_file file_path, file_content
40
- end
41
- end
42
- end
@@ -1,37 +0,0 @@
1
- FROM node:10.13.0-slim as nodejs
2
-
3
- # ******Multi stage ********
4
- FROM ruby:<%= ruby_version %>-slim
5
-
6
- # install common dev libs
7
- RUN apt-get update -qq && apt-get install -y \
8
- build-essential vim git
9
- <% if database == "mysql" %>
10
- # install Mysql
11
- RUN apt-get install -y mysql-client libmysqlclient-dev
12
- <% elsif database == "postgresql" %>
13
- # install Postgresql
14
- RUN apt-get install -y postgresql-client libpq-dev
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/
21
-
22
- WORKDIR /app
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}
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,41 +0,0 @@
1
- #!/bin/sh
2
- set -ex
3
- PROJECT_ID=<PROJECT_ID>
4
- BRANCH_NAME=`git rev-parse --abbrev-ref HEAD`
5
- SHORT_SHA=`git rev-parse --short HEAD`
6
- IMAGE_NAME=gcr.io/${PROJECT_ID}
7
-
8
- # Build rails builder
9
- docker build \
10
- -t ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA}-builder \
11
- -t ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest-builder \
12
- -t ${IMAGE_NAME}/rails:latest-builder \
13
- --target builder \
14
- -f docker/production/rails/Dockerfile \
15
- .
16
-
17
- # Build rails
18
- docker build \
19
- -t ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA} \
20
- -t ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest \
21
- -t ${IMAGE_NAME}/rails:latest \
22
- -f docker/production/rails/Dockerfile \
23
- .
24
-
25
- # Build nginx
26
- docker build \
27
- -t ${IMAGE_NAME}/nginx:${BRANCH_NAME}-${SHORT_SHA} \
28
- -t ${IMAGE_NAME}/nginx:${BRANCH_NAME}-latest \
29
- -t ${IMAGE_NAME}/nginx:latest \
30
- -f docker/production/nginx/Dockerfile \
31
- docker/production/nginx
32
-
33
- gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA}-builder
34
- gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest-builder
35
- gcloud docker -- push ${IMAGE_NAME}/rails:latest-builder
36
- gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA}
37
- gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest
38
- gcloud docker -- push ${IMAGE_NAME}/rails:latest
39
- gcloud docker -- push ${IMAGE_NAME}/nginx:${BRANCH_NAME}-${SHORT_SHA}
40
- gcloud docker -- push ${IMAGE_NAME}/nginx:${BRANCH_NAME}-latest
41
- gcloud docker -- push ${IMAGE_NAME}/nginx:latest
@@ -1,75 +0,0 @@
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" ]
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -ex
3
-
4
- # migrate database before run server
5
- bundle exec rake db:create db:migrate
6
- # run rails
7
- bundle exec rails server -p 3000 -b 0.0.0.0
@@ -1,19 +0,0 @@
1
- # Ignore all files from .gitignore
2
- # echo .git > .dockerignore && cat .gitignore >> .dockerignore
3
-
4
- /log/*
5
- /tmp/*
6
-
7
- .byebug_history
8
-
9
- volumes
10
-
11
- public/packs
12
- public/packs-test
13
- public/uploads
14
-
15
- node_modules
16
- coverage
17
- yarn-error.log
18
- .DS_Store
19
- .git
@@ -1,27 +0,0 @@
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*