modulorails 1.4.0 → 1.5.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/Gemfile +3 -0
- data/lib/generators/modulorails/bundleraudit/bundleraudit_generator.rb +13 -8
- data/lib/generators/modulorails/docker/docker_generator.rb +58 -15
- data/lib/generators/modulorails/docker/templates/config/cable.yml.tt +6 -6
- data/lib/generators/modulorails/docker/templates/config/database.yml.tt +3 -15
- data/lib/generators/modulorails/docker/templates/config/initializers/0_redis.rb +2 -0
- data/lib/generators/modulorails/docker/templates/config/puma.rb +41 -0
- data/lib/generators/modulorails/docker/templates/docker-compose.yml.tt +14 -7
- data/lib/generators/modulorails/docker/templates/{Dockerfile.prod.tt → dockerfiles/modulotech/Dockerfile.prod.tt} +9 -7
- data/lib/generators/modulorails/docker/templates/{Dockerfile.tt → dockerfiles/modulotech/Dockerfile.tt} +3 -1
- data/lib/generators/modulorails/docker/templates/dockerfiles/rails/Dockerfile.prod.tt +87 -0
- data/lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt +13 -9
- data/lib/generators/modulorails/githooks/githooks_generator.rb +57 -0
- data/lib/generators/modulorails/githooks/templates/dockeruby.sh +112 -0
- data/lib/generators/modulorails/githooks/templates/post-rewrite.sh +5 -0
- data/lib/generators/modulorails/githooks/templates/pre-merge-commit.sh +2 -0
- data/lib/generators/modulorails/githooks/templates/refresh_generations.sh +25 -0
- data/lib/generators/modulorails/gitlabci/gitlabci_generator.rb +5 -19
- data/lib/generators/modulorails/gitlabci/templates/.gitlab-ci.yml.tt +15 -3
- data/lib/generators/modulorails/gitlabci/templates/config/deploy/production.yaml.tt +15 -0
- data/lib/generators/modulorails/gitlabci/templates/config/deploy/review.yaml.tt +15 -0
- data/lib/generators/modulorails/gitlabci/templates/config/deploy/staging.yaml.tt +15 -0
- data/lib/generators/modulorails/health_check/health_check_generator.rb +29 -0
- data/lib/generators/modulorails/{healthcheck → health_check}/templates/.modulorails-health_check +2 -0
- data/lib/generators/modulorails/moduloproject/moduloproject_generator.rb +42 -0
- data/lib/generators/modulorails/moduloproject/templates/config/environments/production.rb.tt +109 -0
- data/lib/generators/modulorails/rubocop/rubocop_generator.rb +1 -0
- data/lib/generators/modulorails/self_update/self_update_generator.rb +7 -4
- data/lib/generators/modulorails/service/service_generator.rb +2 -2
- data/lib/generators/modulorails/service/templates/service.rb.tt +4 -11
- data/lib/generators/modulorails/sidekiq/sidekiq_generator.rb +41 -45
- data/lib/modulorails/data.rb +10 -6
- data/lib/modulorails/generators/base.rb +79 -0
- data/lib/modulorails/railtie.rb +6 -0
- data/lib/modulorails/services/base_service.rb +22 -12
- data/lib/modulorails/services/logs_for_method_service.rb +5 -0
- data/lib/modulorails/version.rb +1 -1
- data/lib/modulorails.rb +23 -12
- data/modulorails.gemspec +9 -10
- metadata +37 -54
- data/lib/generators/modulorails/docker/templates/docker-compose.prod.yml.tt +0 -49
- data/lib/generators/modulorails/healthcheck/health_check_generator.rb +0 -40
- /data/lib/generators/modulorails/{healthcheck → health_check}/templates/config/initializers/health_check.rb.tt +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 928b92b50a47d10967876fd9fec84d9f1e0da9b9082d642a48cb2ee0eb49be89
|
4
|
+
data.tar.gz: 599f3d7b1546dfa9b294e8c09d9f1d429ad9d2b2ce69914c62f53e45cf213776
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bcc2bc9acd9c84f41dd80c60036adffdcc85eb4c79c549209852d8dd918806e5d488d40df6b222648512e056b4d09f0f94f894a97215472577d222eea1d996e
|
7
|
+
data.tar.gz: '09cad76576542012ce824cd16891309d6d6e1b380b808e9839799294d099da9b9f6406a71be92a2d7ac8345044fd11c46bf9b8c28580fbb876b12ff06a8d86d3'
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,34 @@ This file is used to list changes made in each version of the gem.
|
|
4
4
|
|
5
5
|
# Unreleased
|
6
6
|
|
7
|
+
# 1.5.0
|
8
|
+
|
9
|
+
- Update templates according to new standards:
|
10
|
+
- Optimize layers in Dockerfile.prod.
|
11
|
+
- Remove root privileges in Dockerfile.prod.
|
12
|
+
- Exec Docker `CMD` in entrypoints.
|
13
|
+
- Configure Puma and Redis.
|
14
|
+
- Remove docker-compose.prod.
|
15
|
+
- Rename docker-compose.yml to compose.yml.
|
16
|
+
- Remove version from compose.yml.
|
17
|
+
- Auto-stop staging container after 7 days.
|
18
|
+
- Use `rails` chart in Gitlab CI templates.
|
19
|
+
- Move entrypoints locations to `bin` to be rails-standard.
|
20
|
+
- Rewrite Dockerfile.prod for Rails 7.2+ to be more rails-standard.
|
21
|
+
- Version Docker generator.
|
22
|
+
- Add a generator for project initialization:
|
23
|
+
- Add default configuration for production and staging environments.
|
24
|
+
- Add default locale configuration to application.rb.
|
25
|
+
- Add a generator for Git hooks.
|
26
|
+
- Update service template to use keyword arguments and add `attr_reader`s.
|
27
|
+
- Add optional `data` argument to `with_transaction`.
|
28
|
+
- Deprecate `Modulorails::BaseService#log` and `Modulorails::LogsForMethodService`.
|
29
|
+
- Add a common base for all generators.
|
30
|
+
|
31
|
+
# 1.4.0.1
|
32
|
+
|
33
|
+
- Fix auto-update.
|
34
|
+
|
7
35
|
# 1.4.0
|
8
36
|
|
9
37
|
- Remove custom from standard health_check checks.
|
data/Gemfile
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'modulorails/generators/base'
|
4
4
|
|
5
|
-
class Modulorails::BundlerauditGenerator <
|
5
|
+
class Modulorails::BundlerauditGenerator < Modulorails::Generators::Base
|
6
6
|
|
7
|
-
source_root File.expand_path('templates', __dir__)
|
8
7
|
desc 'This generator creates a configuration for Bundler-Audit'
|
9
8
|
|
10
|
-
|
11
|
-
gitlab_config_path = Rails.root.join('.gitlab-ci.yml')
|
9
|
+
protected
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
append_file gitlab_config_path do
|
11
|
+
def create_config
|
12
|
+
append_file @gitlab_config_path do
|
16
13
|
<<~YAML
|
14
|
+
|
17
15
|
# Scan Gemfile.lock for Common Vulnerabilities and Exposures
|
18
16
|
# https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures
|
19
17
|
# https://www.cve.org/
|
@@ -23,4 +21,11 @@ class Modulorails::BundlerauditGenerator < Rails::Generators::Base
|
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
24
|
+
def keep_file_present?
|
25
|
+
@gitlab_config_path = Rails.root.join('.gitlab-ci.yml')
|
26
|
+
|
27
|
+
!@gitlab_config_path.exist? ||
|
28
|
+
@gitlab_config_path.read.match?(/\s+extends:\s+.bundleraudit\s*$/)
|
29
|
+
end
|
30
|
+
|
26
31
|
end
|
@@ -1,35 +1,78 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'modulorails/generators/base'
|
4
4
|
|
5
|
-
class Modulorails::DockerGenerator <
|
5
|
+
class Modulorails::DockerGenerator < Modulorails::Generators::Base
|
6
6
|
|
7
|
-
|
8
|
-
desc 'This generator creates Dockerfiles for an app'
|
7
|
+
VERSION = 2
|
9
8
|
|
10
|
-
|
9
|
+
desc 'This generator creates Docker configuration for an app'
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def create_config
|
11
14
|
@data = Modulorails.data
|
12
15
|
@adapter = @data.adapter
|
13
16
|
@webpack_container_needed = @data.webpacker_version.present?
|
14
17
|
@image_name = @data.name.parameterize
|
15
18
|
@environment_name = @data.environment_name
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
template 'entrypoints/docker-entrypoint.sh'
|
22
|
-
chmod 'entrypoints/docker-entrypoint.sh', 0755
|
20
|
+
create_dockerfile
|
21
|
+
create_dockerfile_prod
|
22
|
+
create_compose_yml
|
23
|
+
create_docker_entrypoint
|
23
24
|
template 'config/database.yml'
|
24
25
|
template 'config/cable.yml'
|
26
|
+
template 'config/initializers/0_redis.rb'
|
27
|
+
template 'config/puma.rb'
|
25
28
|
|
26
29
|
# Useless unless project is using Webpacker
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
30
|
+
return unless @webpack_container_needed
|
31
|
+
|
32
|
+
create_webpack_entrypoint
|
31
33
|
rescue StandardError => e
|
32
34
|
warn("[Modulorails] Error: cannot generate Docker configuration: #{e.message}")
|
33
35
|
end
|
34
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
def create_dockerfile
|
40
|
+
say('WARNING: The entrypoint was moved. Check that your Dockerfile still works.') if File.exist?('Dockerfile')
|
41
|
+
template 'dockerfiles/modulotech/Dockerfile', 'Dockerfile'
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_webpack_entrypoint
|
45
|
+
create_new_file('entrypoints/webpack-entrypoint.sh', 'bin/webpack-entrypoint')
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_docker_entrypoint
|
49
|
+
create_new_file 'entrypoints/docker-entrypoint.sh', 'bin/docker-entrypoint'
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_compose_yml
|
53
|
+
create_new_file 'docker-compose.yml', 'compose.yml', executable: false
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_dockerfile_prod
|
57
|
+
if File.exist?('Dockerfile.prod')
|
58
|
+
say('WARNING: The entrypoint was moved. Check that your Dockerfile.prod still works.')
|
59
|
+
end
|
60
|
+
|
61
|
+
if Gem::Version.new(@data.rails_version) >= Gem::Version.new('7.2')
|
62
|
+
template 'dockerfiles/rails/Dockerfile.prod', 'Dockerfile.prod'
|
63
|
+
else
|
64
|
+
template 'dockerfiles/modulotech/Dockerfile.prod', 'Dockerfile.prod'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_new_file(old_file, new_file, executable: true)
|
69
|
+
if File.exist?(old_file)
|
70
|
+
copy_file old_file, new_file
|
71
|
+
remove_file old_file
|
72
|
+
else
|
73
|
+
template old_file, new_file
|
74
|
+
end
|
75
|
+
chmod new_file, 0o755 if executable
|
76
|
+
end
|
77
|
+
|
35
78
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
redis_remote: &redis_remote
|
2
2
|
adapter: redis
|
3
|
-
url:
|
3
|
+
url: <%%= defined?(REDIS_URL) ? REDIS_URL : ENV.fetch('REDIS_URL', 'redis://redis:6379') %>
|
4
4
|
|
5
5
|
development:
|
6
|
-
<<: *
|
6
|
+
<<: *redis_remote
|
7
7
|
|
8
8
|
test:
|
9
|
-
<<: *
|
9
|
+
<<: *redis_remote
|
10
10
|
|
11
11
|
staging:
|
12
|
-
<<: *
|
12
|
+
<<: *redis_remote
|
13
13
|
|
14
14
|
production:
|
15
|
-
<<: *
|
15
|
+
<<: *redis_remote
|
@@ -1,26 +1,14 @@
|
|
1
|
-
<%- if @adapter =~ /mysql/ -%>
|
2
1
|
development: &default
|
2
|
+
<%- if @adapter =~ /mysql/ -%>
|
3
3
|
adapter: mysql2
|
4
|
-
encoding: utf8mb4
|
5
|
-
collation: utf8mb4_unicode_ci
|
6
|
-
database: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_NAME', '<%= @image_name %>') %>
|
7
|
-
username: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_USERNAME', 'root') %>
|
8
|
-
password: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_PASSWORD', '') %>
|
9
|
-
host: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_HOST', 'database') %>
|
10
|
-
port: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_PORT', 3306) %>
|
11
4
|
<%- else -%>
|
12
|
-
development: &default
|
13
5
|
adapter: postgresql
|
14
|
-
database: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_NAME', '<%= @image_name %>') %>
|
15
|
-
username: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_USERNAME', 'postgres') %>
|
16
|
-
password: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_PASSWORD', 'postgres') %>
|
17
|
-
host: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_HOST', 'database') %>
|
18
|
-
port: <%%= ENV.fetch('<%= @environment_name %>_DATABASE_PORT', 5432) %>
|
19
6
|
<%- end -%>
|
7
|
+
url: <%%= ENV['DATABASE_URL'] %>
|
20
8
|
|
21
9
|
test:
|
22
10
|
<<: *default
|
23
|
-
database: <%%= ENV
|
11
|
+
database: <%%= ENV['DTABASE_TEST_URL'] %>
|
24
12
|
|
25
13
|
staging:
|
26
14
|
<<: *default
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This configuration file will be evaluated by Puma. The top-level methods that
|
2
|
+
# are invoked here are part of Puma's configuration DSL. For more information
|
3
|
+
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
|
4
|
+
|
5
|
+
# Puma starts a configurable number of processes (workers) and each process
|
6
|
+
# serves each request in a thread from an internal thread pool.
|
7
|
+
#
|
8
|
+
# The ideal number of threads per worker depends both on how much time the
|
9
|
+
# application spends waiting for IO operations and on how much you wish to
|
10
|
+
# to prioritize throughput over latency.
|
11
|
+
#
|
12
|
+
# As a rule of thumb, increasing the number of threads will increase how much
|
13
|
+
# traffic a given process can handle (throughput), but due to CRuby's
|
14
|
+
# Global VM Lock (GVL) it has diminishing returns and will degrade the
|
15
|
+
# response time (latency) of the application.
|
16
|
+
#
|
17
|
+
# The default is set to 3 threads as it's deemed a decent compromise between
|
18
|
+
# throughput and latency for the average Rails application.
|
19
|
+
#
|
20
|
+
# Any libraries that use a connection pool or another resource pool should
|
21
|
+
# be configured to provide at least as many connections as the number of
|
22
|
+
# threads. This includes Active Record's `pool` parameter in `database.yml`.
|
23
|
+
threads_count = ENV.fetch('RAILS_MAX_THREADS', 3)
|
24
|
+
threads threads_count, threads_count
|
25
|
+
|
26
|
+
# Specifies the worker count.
|
27
|
+
if ENV['RAILS_ENV'] == 'production'
|
28
|
+
require 'concurrent-ruby'
|
29
|
+
worker_count = Integer(ENV.fetch('WEB_CONCURRENCY', 4))
|
30
|
+
workers worker_count if worker_count > 1
|
31
|
+
end
|
32
|
+
|
33
|
+
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
34
|
+
bind "tcp://0.0.0.0:#{ENV.fetch('PORT', 3000)}"
|
35
|
+
|
36
|
+
# Allow puma to be restarted by `bin/rails restart` command.
|
37
|
+
plugin :tmp_restart
|
38
|
+
|
39
|
+
# Specify the PID file. Defaults to tmp/pids/server.pid in development.
|
40
|
+
# In other environments, only set the PID file if requested.
|
41
|
+
pidfile ENV['PIDFILE'] if ENV['PIDFILE']
|
@@ -1,5 +1,3 @@
|
|
1
|
-
version: '3.7'
|
2
|
-
|
3
1
|
services:
|
4
2
|
app:
|
5
3
|
image: modulotechgroup/<%= @image_name %>:dev
|
@@ -16,10 +14,14 @@ services:
|
|
16
14
|
environment:
|
17
15
|
RAILS_ENV: development
|
18
16
|
URL: http://localhost:3000
|
19
|
-
|
20
|
-
|
17
|
+
<%- if @adapter =~ /mysql/ -%>
|
18
|
+
DATABASE_URL: mysql2://root@database/<%= @image_name %>
|
19
|
+
DATABASE_TEST_URL: mysql2://root@database/<%= @image_name %>-test
|
20
|
+
<%- else -%>
|
21
|
+
DATABASE_URL: postgresql://postgres:postgres@database/<%= @image_name %>
|
22
|
+
DATABASE_TEST_URL: postgresql://postgres:postgres@database/<%= @image_name %>-test
|
23
|
+
<%- end -%>
|
21
24
|
REDIS_URL: redis://redis:6379/1
|
22
|
-
entrypoint: ./entrypoints/docker-entrypoint.sh
|
23
25
|
stdin_open: true
|
24
26
|
tty: true
|
25
27
|
|
@@ -28,6 +30,8 @@ services:
|
|
28
30
|
image: mysql/mysql-server:8.0
|
29
31
|
volumes:
|
30
32
|
- db_data:/var/lib/mysql
|
33
|
+
ports:
|
34
|
+
- '3306:3306'
|
31
35
|
environment:
|
32
36
|
MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
|
33
37
|
MYSQL_DATABASE: <%= @image_name %>
|
@@ -37,6 +41,8 @@ services:
|
|
37
41
|
image: postgres:16-alpine
|
38
42
|
volumes:
|
39
43
|
- db_data:/var/lib/postgresql/data
|
44
|
+
ports:
|
45
|
+
- '5432:5432'
|
40
46
|
environment:
|
41
47
|
POSTGRES_USER: postgres
|
42
48
|
POSTGRES_PASSWORD: postgres
|
@@ -51,7 +57,8 @@ services:
|
|
51
57
|
mailcatcher:
|
52
58
|
image: dockage/mailcatcher
|
53
59
|
ports:
|
54
|
-
- 1080:1080
|
60
|
+
- '1080:1080'
|
61
|
+
- '1025:1025'
|
55
62
|
|
56
63
|
<%- if @webpack_container_needed -%>
|
57
64
|
webpack:
|
@@ -59,7 +66,7 @@ services:
|
|
59
66
|
build:
|
60
67
|
context: .
|
61
68
|
dockerfile: Dockerfile
|
62
|
-
entrypoint: ./
|
69
|
+
entrypoint: ./bin/webpack-entrypoint
|
63
70
|
volumes:
|
64
71
|
- .:/app
|
65
72
|
ports:
|
@@ -20,8 +20,8 @@ RUN apk add --update --no-cache \
|
|
20
20
|
RUN gem install bundler -v <%= @data.bundler_version %>
|
21
21
|
|
22
22
|
COPY Gemfile Gemfile.lock ./
|
23
|
-
RUN bundle config set --local deployment 'true'
|
24
|
-
|
23
|
+
RUN bundle config set --local deployment 'true' \
|
24
|
+
&& bundle check || bundle install --jobs=2 \
|
25
25
|
&& rm -rf vendor/bundle/ruby/*/cache/*
|
26
26
|
|
27
27
|
<%- if @webpack_container_needed -%>
|
@@ -35,12 +35,12 @@ RUN bundle exec rake assets:precompile
|
|
35
35
|
# FINAL IMAGE
|
36
36
|
FROM ruby:<%= @data.ruby_version %>-alpine
|
37
37
|
|
38
|
-
ENV RAILS_ENV=development
|
39
|
-
|
38
|
+
ENV RAILS_ENV=development \
|
39
|
+
EDITOR=vim
|
40
40
|
WORKDIR /app
|
41
|
+
RUN adduser -D user
|
41
42
|
|
42
43
|
RUN apk add --update --no-cache \
|
43
|
-
curl \
|
44
44
|
git \
|
45
45
|
nodejs \
|
46
46
|
tzdata \
|
@@ -54,11 +54,13 @@ RUN apk add --update --no-cache \
|
|
54
54
|
&& rm -rf .git/
|
55
55
|
RUN gem install bundler -v <%= @data.bundler_version %>
|
56
56
|
|
57
|
-
COPY --from=builder /app .
|
57
|
+
COPY --chown=user:user --from=builder /app .
|
58
58
|
|
59
59
|
RUN bundle config --local path vendor/bundle \
|
60
60
|
&& bundle config --local without development:test:assets
|
61
61
|
|
62
62
|
EXPOSE 3000
|
63
63
|
|
64
|
-
ENTRYPOINT ["./
|
64
|
+
ENTRYPOINT ["./bin/docker-entrypoint"]
|
65
|
+
|
66
|
+
CMD ["./bin/rails", "server"]
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# syntax = docker/dockerfile:1
|
2
|
+
|
3
|
+
# This Dockerfile is designed for production, not development.
|
4
|
+
# It is adapted from Rails 7.2 default Dockerfile with Modulotech's twist to fit the use of Alpine.
|
5
|
+
|
6
|
+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
7
|
+
ARG RUBY_VERSION=<%= @data.ruby_version %>
|
8
|
+
FROM docker.io/library/ruby:$RUBY_VERSION-alpine AS base
|
9
|
+
|
10
|
+
# Rails app lives here
|
11
|
+
WORKDIR /rails
|
12
|
+
|
13
|
+
# Install base packages
|
14
|
+
RUN apk add --update --no-cache \
|
15
|
+
tzdata \
|
16
|
+
shared-mime-info \
|
17
|
+
vim \
|
18
|
+
jemalloc \
|
19
|
+
vips \
|
20
|
+
<%- if @adapter =~ /mysql/ -%>
|
21
|
+
mysql-client
|
22
|
+
<%- else -%>
|
23
|
+
postgresql-client
|
24
|
+
<%- end -%>
|
25
|
+
|
26
|
+
# Set production environment
|
27
|
+
ENV RAILS_ENV="production" \
|
28
|
+
BUNDLE_DEPLOYMENT="1" \
|
29
|
+
BUNDLE_PATH="/usr/local/bundle" \
|
30
|
+
BUNDLE_WITHOUT="development"
|
31
|
+
|
32
|
+
# Throw-away build stage to reduce size of final image
|
33
|
+
FROM base AS build
|
34
|
+
|
35
|
+
# Install packages needed to build gems
|
36
|
+
RUN apk add --update --no-cache \
|
37
|
+
alpine-sdk \
|
38
|
+
nodejs \
|
39
|
+
tzdata \
|
40
|
+
yarn \
|
41
|
+
shared-mime-info \
|
42
|
+
gcompat \
|
43
|
+
<%- if @adapter =~ /mysql/ -%>
|
44
|
+
mysql-dev
|
45
|
+
<%- else -%>
|
46
|
+
postgresql-dev
|
47
|
+
<%- end -%>
|
48
|
+
|
49
|
+
# Install application gems
|
50
|
+
RUN gem install bundler -v <%= @data.bundler_version %>
|
51
|
+
|
52
|
+
COPY Gemfile Gemfile.lock ./
|
53
|
+
RUN bundle install && \
|
54
|
+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
|
55
|
+
bundle exec bootsnap precompile --gemfile
|
56
|
+
|
57
|
+
# Copy application code
|
58
|
+
COPY . .
|
59
|
+
|
60
|
+
# Precompile bootsnap code for faster boot times
|
61
|
+
RUN bundle exec bootsnap precompile app/ lib/
|
62
|
+
|
63
|
+
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
|
64
|
+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
# Final stage for app image
|
70
|
+
FROM base
|
71
|
+
|
72
|
+
# Copy built artifacts: gems, application
|
73
|
+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
|
74
|
+
COPY --from=build /rails /rails
|
75
|
+
|
76
|
+
# Run and own only the runtime files as a non-root user for security
|
77
|
+
RUN addgroup -S -g 1000 rails && \
|
78
|
+
adduser rails -u 1000 -G rails -h /home/rails -s /bin/sh -D && \
|
79
|
+
chown -R rails:rails db log storage tmp
|
80
|
+
USER 1000:1000
|
81
|
+
|
82
|
+
# Entrypoint prepares the database.
|
83
|
+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
84
|
+
|
85
|
+
# Start the server by default, this can be overwritten at runtime
|
86
|
+
EXPOSE 3000
|
87
|
+
CMD ["./bin/rails", "server"]
|
@@ -1,7 +1,12 @@
|
|
1
|
-
#!/bin/sh
|
1
|
+
#!/bin/sh -e
|
2
2
|
|
3
|
-
#
|
4
|
-
|
3
|
+
# Enable jemalloc for reduced memory usage and latency.
|
4
|
+
jemalloc_lib=$(find /usr/lib/ -name "libjemalloc.so.2" 2>/dev/null | head -n 1)
|
5
|
+
|
6
|
+
if [ -z "${LD_PRELOAD+x}" ] && [ -n "$jemalloc_lib" ]; then
|
7
|
+
LD_PRELOAD="$jemalloc_lib"
|
8
|
+
export LD_PRELOAD
|
9
|
+
fi
|
5
10
|
|
6
11
|
# No `node_modules` directory means `yarn install` was never launched.
|
7
12
|
# It is mandatory to install yarn dependencies IF there is a `package.json` file.
|
@@ -10,11 +15,10 @@ then
|
|
10
15
|
yarn install
|
11
16
|
fi
|
12
17
|
|
13
|
-
#
|
14
|
-
if [
|
15
|
-
|
16
|
-
rm tmp/pids/server.pid
|
18
|
+
# If running the rails server then create or migrate existing database
|
19
|
+
if [ "$1" = "./bin/rails" ] && [ "$2" = "server" ]; then
|
20
|
+
./bin/rails db:prepare
|
17
21
|
fi
|
18
22
|
|
19
|
-
#
|
20
|
-
exec
|
23
|
+
# Execute the CMD
|
24
|
+
exec "$@"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'modulorails/generators/base'
|
4
|
+
|
5
|
+
module Modulorails
|
6
|
+
|
7
|
+
class GithooksGenerator < Modulorails::Generators::Base
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def create_config
|
12
|
+
create_hook_executor
|
13
|
+
create_refresh_generations_script
|
14
|
+
create_git_hooks
|
15
|
+
update_gitattributes
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def create_hook_executor
|
21
|
+
template 'dockeruby.sh', 'bin/dockeruby'
|
22
|
+
chmod 'bin/dockeruby', 0o755
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_refresh_generations_script
|
26
|
+
template 'refresh_generations.sh', 'bin/refresh_generations'
|
27
|
+
chmod 'bin/refresh_generations', 0o755
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_git_hooks
|
31
|
+
%w[post-rewrite pre-merge-commit].each do |hook|
|
32
|
+
template "#{hook}.sh", ".git/hooks/#{hook}"
|
33
|
+
chmod ".git/hooks/#{hook}", 0o755
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_gitattributes
|
38
|
+
content = <<~CONTENT
|
39
|
+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
|
40
|
+
|
41
|
+
# Mark any vendored files as having been vendored.
|
42
|
+
vendor/* linguist-vendored
|
43
|
+
|
44
|
+
config/credentials/*.yml.enc diff=rails_credentials
|
45
|
+
config/credentials.yml.enc diff=rails_credentials
|
46
|
+
|
47
|
+
Gemfile.lock merge=ours
|
48
|
+
app/assets/javascripts/i18n/translations.js merge=ours
|
49
|
+
db/schema.rb merge=ours
|
50
|
+
CONTENT
|
51
|
+
|
52
|
+
create_file '.gitattributes', content, force: true
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|