modulorails 0.2.2 → 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
  SHA256:
3
- metadata.gz: 7aebb014e4b73e3c0b3cd12106187db5592900f90ea33beb4bd80ffe7b54fba0
4
- data.tar.gz: e84b4a5949cf657a3205b9f9b3edae7a7e1b0bc5621723eff5455d939199da5c
3
+ metadata.gz: 55dbb40ab0e717d0204e96ded91f37a2384d6a068cc588d4c4c9db90e96c2d91
4
+ data.tar.gz: e6f08f5aeec11a0249d8323604f17471120a066e696308c6ad9d0b2e4ed93cd7
5
5
  SHA512:
6
- metadata.gz: c8abc2a6dc7bd6e6d344441bd16123f9a750a752732e02ae2826fd8a0a8ef0e5806cdde5da9da9b06d16a80fa414775d11fb657b90812c59350775b36db17a1c
7
- data.tar.gz: af263b043c1c5ae69555b76ccf805d7567b0964eefe7748c96aad3aff2d66f9495e61025c8a51c242703e87bfc6e849e8accd69aafa1ab1ce2be35b8735cafde
6
+ metadata.gz: f4c82055e0f2037c6f4ff7831659be156ff501eb4fbe80ac52089f1857f20ff1db40e81446d0bf2bbfba1df6bba7638b05b54bb114623ff856eb9fce5cb65641
7
+ data.tar.gz: 79732d5ad59379f2988ac10d8dac50f99d1984365fca5487ead432cb8d7f2e1b39b666e344dc02f051c267ffe9da19dcc4a82785ecda669c638bed101ee23fe0
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.gem
data/CHANGELOG.md CHANGED
@@ -2,7 +2,20 @@
2
2
 
3
3
  This file is used to list changes made in each version of the gem.
4
4
 
5
- # 0.2.1
5
+ # 0.3.0
6
+
7
+ Docker release.
8
+
9
+ - Add generator for Docker.
10
+ - Use templates for Gitlabci generator.
11
+
12
+ # 0.2.3
13
+
14
+ Gitlab-ci generator.
15
+
16
+ - Fixes the Ruby version put in the generated `.gitlab-ci.yml`.
17
+
18
+ # 0.2.2
6
19
 
7
20
  Auto-update fixes.
8
21
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- modulorails (0.2.2)
4
+ modulorails (0.3.0)
5
5
  git (~> 1.7, >= 1.7.0)
6
6
  httparty
7
7
  i18n
@@ -53,11 +53,9 @@ GEM
53
53
  mime-types (3.3.1)
54
54
  mime-types-data (~> 3.2015)
55
55
  mime-types-data (3.2021.0225)
56
- mini_portile2 (2.5.0)
57
56
  minitest (5.14.1)
58
57
  multi_xml (0.6.0)
59
- nokogiri (1.11.1)
60
- mini_portile2 (~> 2.5.0)
58
+ nokogiri (1.11.1-x86_64-darwin)
61
59
  racc (~> 1.4)
62
60
  racc (1.5.2)
63
61
  rack (2.2.3)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ class DockerGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+ desc 'This generator creates Dockerfiles for an app'
8
+
9
+ def create_config_file
10
+ template 'Dockerfile'
11
+ template 'Dockerfile.prod'
12
+ template 'docker-compose.yml'
13
+ template 'docker-compose.prod.yml'
14
+ template 'entrypoints/docker-entrypoint.sh'
15
+ template 'config/database.yml'
16
+ rescue StandardError => e
17
+ $stderr.puts("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ FROM surnet/alpine-wkhtmltopdf:3.12-0.12.6-small as wkhtmltopdf
2
+ # BUILD IMAGE
3
+ FROM ruby:<%= Modulorails.data.ruby_version %>-alpine as builder
4
+
5
+ ENV RAILS_ENV=production
6
+ WORKDIR /app
7
+
8
+ RUN apk add --update --no-cache \
9
+ alpine-sdk \
10
+ mysql-dev \
11
+ nodejs \
12
+ sqlite-dev \
13
+ tzdata \
14
+ yarn \
15
+ shared-mime-info
16
+ RUN gem install bundler -v <%= Modulorails.data.bundler_version %>
17
+
18
+ COPY Gemfile Gemfile.lock ./
19
+ RUN bundle check || bundle install --deployment --jobs=2 \
20
+ && rm -rf vendor/bundle/ruby/*/cache/*
21
+
22
+ COPY package.json yarn.lock ./
23
+ RUN yarn install
24
+
25
+ COPY . .
26
+ RUN bundle exec rake assets:precompile
27
+
28
+ # FINAL IMAGE
29
+ FROM ruby:<%= Modulorails.data.ruby_version %>-alpine
30
+
31
+ WORKDIR /app
32
+
33
+ RUN apk add --update --no-cache \
34
+ curl \
35
+ git \
36
+ mysql-dev \
37
+ nodejs \
38
+ sqlite-dev \
39
+ tzdata \
40
+ shared-mime-info
41
+ && rm -rf .git/
42
+
43
+ # Replace segfault version with patched one
44
+ COPY --from=wkhtmltopdf /bin/wkhtmltopdf /usr/bin/wkhtmltopdf
45
+ COPY --from=builder /app .
46
+
47
+ RUN bundle config --local path vendor/bundle \
48
+ && bundle config --local without development:test:assets
49
+
50
+ EXPOSE 3000
51
+
52
+ ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]
@@ -0,0 +1,28 @@
1
+ # Import wkhtmltopdf with qt patched because from alpine it's not and segfault
2
+ FROM surnet/alpine-wkhtmltopdf:3.12-0.12.6-small as wkhtmltopdf
3
+
4
+ FROM ruby:<%= Modulorails.data.ruby_version %>-alpine
5
+
6
+ ENV RAILS_ENV=development
7
+ WORKDIR /app
8
+
9
+ RUN apk add --update --no-cache \
10
+ alpine-sdk \
11
+ nodejs \
12
+ yarn \
13
+ sqlite-dev \
14
+ tzdata \
15
+ mysql-dev
16
+ RUN gem install bundler -v <%= Modulorails.data.bundler_version %>
17
+
18
+ COPY Gemfile Gemfile.lock ./
19
+ RUN bundle install --jobs=2
20
+
21
+ COPY . .
22
+
23
+ # Replace segfault version with patched one
24
+ COPY --from=wkhtmltopdf /bin/wkhtmltopdf /usr/bin/wkhtmltopdf
25
+
26
+ EXPOSE 3000
27
+
28
+ ENTRYPOINT ["./entrypoints/docker-entrypoint.sh"]
@@ -0,0 +1,21 @@
1
+ <%- image_name = Modulorails.data.name.parameterize -%>
2
+ <%- upper_image_name = image_name.upcase -%>
3
+ development: &default
4
+ adapter: mysql2
5
+ encoding: utf8mb4
6
+ collation: utf8mb4_unicode_ci
7
+ database: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_NAME', '<%= image_name %>') %>
8
+ username: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_USERNAME', 'root') %>
9
+ password: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_PASSWORD', '') %>
10
+ host: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_HOST', 'database') %>
11
+ port: <%%= ENV.fetch('<%= upper_image_name %>_DATABASE_PORT', 3306) %>
12
+
13
+ test:
14
+ <<: *default
15
+ database: <%%= ENV.fetch('<%= upper_image_name %>_TEST_DATABASE_NAME', '<%= image_name %>_test') %>
16
+
17
+ staging:
18
+ <<: *default
19
+
20
+ production:
21
+ <<: *default
@@ -0,0 +1,36 @@
1
+ version: '3.7'
2
+
3
+ <% image_name = Modulorails.data.name.parameterize %>
4
+
5
+ services:
6
+ app:
7
+ image: modulotechgroup/<%= image_name %>
8
+ build:
9
+ context: .
10
+ dockerfile: Dockerfile.prod
11
+ depends_on:
12
+ - database
13
+ - redis
14
+ ports:
15
+ - '3000:3000'
16
+ environment:
17
+ RAILS_ENV: production
18
+ URL: http://localhost:3000
19
+ <%= image_name.upcase %>_DATABASE_HOST: database
20
+ <%= image_name.upcase %>_DATABASE_NAME: <%= image_name %>
21
+ RAILS_SERVE_STATIC_FILES: 'true'
22
+
23
+ database:
24
+ image: mysql:8.0
25
+ volumes:
26
+ - db_data:/var/lib/mysql
27
+ environment:
28
+ MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
29
+ MYSQL_DATABASE: <%= image_name %>
30
+
31
+ redis:
32
+ image: redis:6.2-alpine
33
+
34
+ # Define the volumes references in the services
35
+ volumes:
36
+ db_data:
@@ -0,0 +1,37 @@
1
+ version: '3.7'
2
+
3
+ <% image_name = Modulorails.data.name.parameterize %>
4
+
5
+ services:
6
+ app:
7
+ image: modulotechgroup/<%= image_name %>:dev
8
+ build:
9
+ context: .
10
+ dockerfile: Dockerfile
11
+ depends_on:
12
+ - database
13
+ - redis
14
+ ports:
15
+ - '3000:3000'
16
+ volumes:
17
+ - .:/app
18
+ environment:
19
+ RAILS_ENV: development
20
+ URL: http://localhost:3000
21
+ <%= image_name.upcase %>_DATABASE_HOST: database
22
+ <%= image_name.upcase %>_DATABASE_NAME: <%= image_name %>
23
+ entrypoint: ./entrypoints/docker-entrypoint.sh
24
+
25
+ database:
26
+ image: mysql:8.0
27
+ volumes:
28
+ - db_data:/var/lib/mysql
29
+ environment:
30
+ MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
31
+ MYSQL_DATABASE: <%= image_name %>
32
+
33
+ redis:
34
+ image: redis:6.2-alpine
35
+
36
+ volumes:
37
+ db_data:
@@ -0,0 +1,20 @@
1
+ #!/bin/sh
2
+
3
+ # Exit immediately if a command exits with a non-zero status
4
+ set -e
5
+
6
+ # No `node_modules` directory means `yarn install` was never launched.
7
+ # It is mandatory to install yarn dependencies.
8
+ if [ ! -d node_modules ]
9
+ then
10
+ yarn install
11
+ fi
12
+
13
+ # Remove pidfile if it exists else the server will not launch
14
+ if [ -f tmp/pids/server.pid ]
15
+ then
16
+ rm tmp/pids/server.pid
17
+ fi
18
+
19
+ # Launch the application listening from all origins on port 3000
20
+ ./bin/bundle exec rails s -b 0.0.0.0 -p 3000
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ class GitlabciGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+ desc 'This generator creates a template for a .gitlab-ci.yml file at root'
8
+
9
+ # Configurations for MySQL/Postgres dockers
10
+ MYSQL_DOCKER_DB = <<~EOS
11
+ # Install a MySQL 5.7 database and configure mandatory environment variables
12
+ # (https://hub.docker.com/_/mysql/)
13
+ services:
14
+ - mysql:5.7
15
+ variables:
16
+ MYSQL_DATABASE: test
17
+ MYSQL_ROOT_PASSWORD: password
18
+ EOS
19
+ POSTGRES_DOCKER_DB = <<~EOS
20
+ # Install a Postgres 11 database and configure mandatory environment variables
21
+ # (https://hub.docker.com/_/postgres/)
22
+ services:
23
+ - postgresql:11
24
+ variables:
25
+ POSTGRES_DB: test
26
+ POSTGRES_PASSWORD: password
27
+ EOS
28
+
29
+ def create_config_file
30
+ # Update the gitlab-ci template
31
+ template '.gitlab-ci.yml'
32
+
33
+ # Update the database-ci template
34
+ template 'config/database-ci.yml'
35
+
36
+ # Create file to avoid this generator on next modulorails launch
37
+ create_keep_file
38
+ rescue StandardError => e
39
+ $stderr.puts("[Modulorails] Error: cannot generate CI configuration: #{e.message}")
40
+ end
41
+
42
+ private
43
+
44
+ def create_keep_file
45
+ file = '.modulorails-gitlab-ci'
46
+
47
+ # Create file to avoid this generator on next modulorails launch
48
+ copy_file(file, file)
49
+
50
+ say "Add #{file} to git"
51
+ %x(git add #{file})
52
+ end
53
+ end
@@ -1,10 +1,17 @@
1
- image: ruby:RUBY_VERSION
1
+ <%- adapter = Modulorails.data.adapter -%>
2
+ <%- if adapter =~ /mysql/ -%>
3
+ <%= GitlabciGenerator::MYSQL_DOCKER_DB -%>
4
+ <%- else -%>
5
+ <%= GitlabciGenerator::POSTGRES_DOCKER_DB -%>
6
+ <%- end -%>
7
+
8
+ image: ruby:<%= Modulorails.data.ruby_version %>
2
9
  stages:
3
10
  - lint
4
11
  - test
5
12
  - deploy
6
13
  cache:
7
- key: CI_CD_CACHE_KEY
14
+ key: <%= Modulorails.data.rails_name.parameterize %>-ci_cd
8
15
  paths:
9
16
  - vendor/ruby
10
17
 
@@ -16,7 +23,7 @@ before_script:
16
23
  - mkdir -p ~/.ssh
17
24
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
18
25
  - apt-get install -y ruby-dev
19
- - gem install bundler -v BUNDLER_VERSION --no-document
26
+ - gem install bundler -v <%= Modulorails.data.bundler_version %> --no-document
20
27
  # You might need DPL if you're deploying using Heroku
21
28
  #- gem install dpl -v 1.10.15 --no-document
22
29
  # You might need to add some configurations here like a key for a theme
@@ -0,0 +1,8 @@
1
+ <%- adapter = Modulorails.data.adapter -%>
2
+ test:
3
+ host: <%= adapter =~ /mysql/ ? 'mysql' : 'postgres' %>
4
+ adapter: <%= adapter %>
5
+ database: test
6
+ username: root
7
+ password: password
8
+ encoding: utf8
data/lib/modulorails.rb CHANGED
@@ -4,7 +4,7 @@ require 'modulorails/data'
4
4
  require 'modulorails/validators/database_configuration'
5
5
  require 'modulorails/updater'
6
6
  require 'modulorails/railtie' if defined?(Rails::Railtie)
7
- require 'generators/gitlabci_generator'
7
+ require 'generators/gitlabci/gitlabci_generator'
8
8
  require 'httparty'
9
9
 
10
10
  # Author: Matthieu 'ciappa_m' Ciappara
@@ -100,13 +100,7 @@ module Modulorails
100
100
  def generate_ci_template
101
101
  return if File.exists?(Rails.root.join('.modulorails-gitlab-ci'))
102
102
 
103
- generator_options = [
104
- '--app', data.rails_name.parameterize,
105
- '--database', data.adapter,
106
- '--bundler', data.bundler_version,
107
- '--ruby_version', data.ruby_version
108
- ]
109
- GitlabciGenerator.new([], generator_options, {}).invoke_all
103
+ GitlabciGenerator.new([], {}, {}).invoke_all
110
104
  end
111
105
 
112
106
  # @author Matthieu 'ciappa_m' Ciappara
@@ -18,7 +18,7 @@ module Modulorails
18
18
  Modulorails.check_database_config
19
19
 
20
20
  # Gem's self-update if a new version was released
21
- Modulorails.self_update
21
+ # Modulorails.self_update
22
22
  end
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module Modulorails
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulorails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Ciappara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -111,10 +111,17 @@ files:
111
111
  - bin/console
112
112
  - bin/setup
113
113
  - config/locales/en.yml
114
- - lib/generators/gitlabci_generator.rb
115
- - lib/generators/templates/.gitlab-ci.yml
116
- - lib/generators/templates/.modulorails-gitlab-ci
117
- - lib/generators/templates/config/database-ci.yml
114
+ - lib/generators/docker/docker_generator.rb
115
+ - lib/generators/docker/templates/Dockerfile.prod.tt
116
+ - lib/generators/docker/templates/Dockerfile.tt
117
+ - lib/generators/docker/templates/config/database.yml.tt
118
+ - lib/generators/docker/templates/docker-compose.prod.yml.tt
119
+ - lib/generators/docker/templates/docker-compose.yml.tt
120
+ - lib/generators/docker/templates/entrypoints/docker-entrypoint.sh.tt
121
+ - lib/generators/gitlabci/gitlabci_generator.rb
122
+ - lib/generators/gitlabci/templates/.gitlab-ci.yml.tt
123
+ - lib/generators/gitlabci/templates/.modulorails-gitlab-ci
124
+ - lib/generators/gitlabci/templates/config/database-ci.yml.tt
118
125
  - lib/modulorails.rb
119
126
  - lib/modulorails/configuration.rb
120
127
  - lib/modulorails/data.rb
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
-
5
- class GitlabciGenerator < Rails::Generators::Base
6
- source_root File.expand_path('templates', __dir__)
7
- class_option(:app,
8
- required: true, type: :string,
9
- desc: 'Specify the application name.')
10
- class_option(:database,
11
- required: true, type: :string,
12
- desc: 'Specify the database to use (either mysql or postgres).')
13
- class_option(:bundler,
14
- required: true, type: :string,
15
- desc: 'Specify the Bundler version.')
16
- class_option(:ruby_version,
17
- required: true, type: :string,
18
- desc: 'Specify the Ruby version.')
19
- desc 'This generator creates a template for a .gitlab-ci.yml file at root'
20
-
21
- # Configurations for MySQL/Postgres dockers
22
- MYSQL_DOCKER_DB = <<~EOS
23
- # Install a MySQL 5.7 database and configure mandatory environment variables
24
- # (https://hub.docker.com/_/mysql/)
25
- services:
26
- - mysql:5.7
27
- variables:
28
- MYSQL_DATABASE: test
29
- MYSQL_ROOT_PASSWORD: password
30
- EOS
31
- POSTGRES_DOCKER_DB = <<~EOS
32
- # Install a Postgres 11 database and configure mandatory environment variables
33
- # (https://hub.docker.com/_/postgres/)
34
- services:
35
- - postgresql:11
36
- variables:
37
- POSTGRES_DB: test
38
- POSTGRES_PASSWORD: password
39
- EOS
40
-
41
- def create_config_file
42
- # Get the configuration for the database engine
43
- db_conf = database_config(options[:database])
44
-
45
- # Update the gitlab-ci template
46
- update_gitlab_ci(options, db_conf)
47
-
48
- # Update the database-ci template
49
- update_database_ci(db_conf)
50
-
51
- # Create file to avoid this generator on next modulorails launch
52
- create_keep_file
53
- rescue StandardError => e
54
- $stderr.puts("[Modulorails] Error: cannot generate CI configuration: #{e.message}")
55
- end
56
-
57
- private
58
-
59
- def update_gitlab_ci(options, db_conf)
60
- file = '.gitlab-ci.yml'
61
- exists = File.exists?(file)
62
-
63
- # Remove original file if there is one
64
- remove_file file if exists
65
-
66
- # Copy file
67
- copy_file file, file
68
-
69
- # Add the correct database docker
70
- prepend_file file, db_conf[:header]
71
-
72
- # Replace key for CI/CD cache
73
- gsub_file file, 'CI_CD_CACHE_KEY', "#{options[:app]}-ci_cd"
74
-
75
- # Replace key for bundler version
76
- gsub_file file, 'BUNDLER_VERSION', options[:bundler]
77
-
78
- # Replace ruby version
79
- gsub_file file, 'RUBY_VERSION', '2.5.0'
80
-
81
- # Warn the user about file overwrite/creation
82
- warn_file_update(file, exists)
83
- end
84
-
85
- def update_database_ci(db_conf)
86
- file = 'config/database-ci.yml'
87
- exists = File.exists?(file)
88
-
89
- # Remove original file if there is one
90
- remove_file file if exists
91
-
92
- # Copy file
93
- copy_file file, file
94
-
95
- # Replace configuration
96
- gsub_file file, 'HOST', db_conf[:host]
97
- gsub_file file, 'ADAPTER', db_conf[:adapter]
98
- gsub_file file, 'DATABASE', 'test'
99
-
100
- # Warn the user about file overwrite/creation
101
- warn_file_update(file, exists)
102
- end
103
-
104
- def database_config(database)
105
- case database
106
- when 'mysql', 'mysql2'
107
- { header: MYSQL_DOCKER_DB, host: 'mysql', adapter: 'mysql2' }
108
- when 'postgres', 'postgresql'
109
- { header: POSTGRES_DOCKER_DB, host: 'postgres', adapter: 'postgresql' }
110
- else
111
- raise "Unknown database adapter `#{database}`: either mysql or postgres"
112
- end
113
- end
114
-
115
- def warn_file_update(file, exists)
116
- intro = if exists
117
- "/!\\ Watch out! Your #{file} was overwritten"
118
- else
119
- "A new file #{file} was added"
120
- end
121
-
122
- say "#{intro} by Modulorails. Ensure everything is correct!"
123
- end
124
-
125
- def create_keep_file
126
- file = '.modulorails-gitlab-ci'
127
-
128
- # Create file to avoid this generator on next modulorails launch
129
- copy_file(file, file)
130
-
131
- say "Add #{file} to git"
132
- %x(git add #{file})
133
- end
134
- end
@@ -1,7 +0,0 @@
1
- test:
2
- host: HOST
3
- adapter: ADAPTER
4
- database: DATABASE
5
- username: root
6
- password: password
7
- encoding: utf8