modulorails 1.5.0.pre2 → 1.5.1
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/generators/modulorails/docker/docker_generator.rb +17 -1
- data/lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt +1 -1
- data/lib/generators/modulorails/githooks/githooks_generator.rb +1 -1
- data/lib/generators/modulorails/githooks/templates/dockeruby.rb +126 -0
- data/lib/modulorails/version.rb +1 -1
- metadata +3 -3
- data/lib/generators/modulorails/githooks/templates/dockeruby.sh +0 -112
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49cd77852f9aee93c053c1722f8332ad44fa712f2ff00830ddd44ab0e873a722
|
4
|
+
data.tar.gz: 6ce2b6f0314ee71f843bdc4f012ceda11ead2b326e98e954b517e334e1646fde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 104ac0e4ab98f6194fec633367c0a87b25198fa5c8f0aef3cadac808ff8328c1c96fa1b11bd6881690f414c0400b9eacfc86a083c982a60e87039358c5ad8274
|
7
|
+
data.tar.gz: 3652ed356e878e708d54ae4d17cb18707afd7deabe57846cacdb2fc53caff699ae1c0cb3a932699a0829fd01be80978a406960df7eb534fec1c16daa1b124c36
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,7 @@ This file is used to list changes made in each version of the gem.
|
|
4
4
|
|
5
5
|
# Unreleased
|
6
6
|
|
7
|
-
# 1.5.
|
7
|
+
# 1.5.1
|
8
8
|
|
9
9
|
- Update templates according to new standards:
|
10
10
|
- Optimize layers in Dockerfile.prod.
|
@@ -28,6 +28,10 @@ This file is used to list changes made in each version of the gem.
|
|
28
28
|
- Deprecate `Modulorails::BaseService#log` and `Modulorails::LogsForMethodService`.
|
29
29
|
- Add a common base for all generators.
|
30
30
|
|
31
|
+
# 1.5.0
|
32
|
+
|
33
|
+
- Released then
|
34
|
+
|
31
35
|
# 1.4.0.1
|
32
36
|
|
33
37
|
- Fix auto-update.
|
@@ -67,7 +67,7 @@ class Modulorails::DockerGenerator < Modulorails::Generators::Base
|
|
67
67
|
|
68
68
|
def create_new_file(old_file, new_file, executable: true)
|
69
69
|
if File.exist?(old_file)
|
70
|
-
|
70
|
+
copy_original_file old_file, new_file
|
71
71
|
remove_file old_file
|
72
72
|
else
|
73
73
|
template old_file, new_file
|
@@ -75,4 +75,20 @@ class Modulorails::DockerGenerator < Modulorails::Generators::Base
|
|
75
75
|
chmod new_file, 0o755 if executable
|
76
76
|
end
|
77
77
|
|
78
|
+
def copy_original_file(source, *args, &block)
|
79
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
80
|
+
destination = args.first || source
|
81
|
+
source = File.expand_path(source, destination_root)
|
82
|
+
|
83
|
+
create_file destination, nil, config do
|
84
|
+
content = File.binread(source)
|
85
|
+
content = yield(content) if block
|
86
|
+
content
|
87
|
+
end
|
88
|
+
if config[:mode] == :preserve
|
89
|
+
mode = File.stat(source).mode
|
90
|
+
chmod(destination, mode, config)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
78
94
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
def require_or_install(gem_name, version=nil)
|
5
|
+
gem(gem_name, "~> #{version}") unless version.nil?
|
6
|
+
require gem_name
|
7
|
+
rescue LoadError
|
8
|
+
warn "Installing gem #{gem_name}"
|
9
|
+
if version.nil?
|
10
|
+
Gem.install(gem_name)
|
11
|
+
else
|
12
|
+
Gem.install(gem_name, "~> #{version}")
|
13
|
+
gem(gem_name, "~> #{version}")
|
14
|
+
end
|
15
|
+
require gem_name
|
16
|
+
end
|
17
|
+
|
18
|
+
require_or_install('shellwords')
|
19
|
+
|
20
|
+
def check_dockerfile(verbose: false)
|
21
|
+
return true if File.exist?('Dockerfile')
|
22
|
+
|
23
|
+
puts('No Dockerfile') if verbose
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def entrypoint_location
|
28
|
+
entrypoint_line = File.readlines('Dockerfile').find { |line| line.start_with?('ENTRYPOINT') }
|
29
|
+
|
30
|
+
return nil if entrypoint_line.nil?
|
31
|
+
|
32
|
+
md = /\[["'](.+)["']\]/.match(entrypoint_line)
|
33
|
+
return nil if md.nil? || md[1].nil?
|
34
|
+
|
35
|
+
md[1]
|
36
|
+
end
|
37
|
+
|
38
|
+
VALID_LAST_INSTRUCTION = /exec "\$\{?@}?"/
|
39
|
+
|
40
|
+
def check_entrypoint(verbose: false)
|
41
|
+
el = entrypoint_location
|
42
|
+
return true if el.nil?
|
43
|
+
|
44
|
+
unless File.exist?(el)
|
45
|
+
warn("Entrypoint not found at location: #{el}") if verbose
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
|
49
|
+
last_line = File.readlines(el).last&.strip
|
50
|
+
return true if VALID_LAST_INSTRUCTION.match?(last_line)
|
51
|
+
|
52
|
+
warn("Invalid entrypoint: Last instruction should be 'exec \"${@}\"' instead of '#{last_line}'") if verbose
|
53
|
+
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
def executer_docker_run(docker_args, verbose: false)
|
58
|
+
pwd = Dir.pwd
|
59
|
+
working_directory = File.basename(pwd)
|
60
|
+
|
61
|
+
volumes = `docker volume ls -q -f name=modulogem`
|
62
|
+
volumes = volumes.split("\n").map(&:strip)
|
63
|
+
modulogem_gems = volumes.find { |volume| volume.include?('modulogem_gems') }
|
64
|
+
modulogem = volumes.find { |volume| volume.include?('modulogem') }
|
65
|
+
modulogem_gems_option = modulogem_gems.nil? ? '' : "-v #{modulogem_gems}:/usr/local/bundle"
|
66
|
+
modulogem_option = modulogem.nil? ? '' : "-v #{modulogem}:/root"
|
67
|
+
|
68
|
+
# Check if the shell is a TTY
|
69
|
+
tty_option = $stdout.isatty ? '-ti' : ''
|
70
|
+
|
71
|
+
# Build the command string
|
72
|
+
# rubocop:disable Layout/LineLength
|
73
|
+
command = %(docker run --rm #{modulogem_gems_option} #{modulogem_option} -v '#{pwd}:/app/#{working_directory}' #{tty_option} -w '/app/#{working_directory}' ezveus/ruby:latest #{docker_args})
|
74
|
+
# rubocop:enable Layout/LineLength
|
75
|
+
|
76
|
+
puts(command) if verbose
|
77
|
+
exec(command)
|
78
|
+
end
|
79
|
+
|
80
|
+
def executer_compose_run(docker_args, verbose: false)
|
81
|
+
entrypoint_option = check_entrypoint(verbose: verbose) ? '' : '--entrypoint "sh -c"'
|
82
|
+
git_email = `git config --get user.email`.strip
|
83
|
+
git_name = `git config --get user.name`.strip
|
84
|
+
|
85
|
+
# Check if the shell is a TTY
|
86
|
+
tty_option = $stdout.isatty ? '-ti' : ''
|
87
|
+
|
88
|
+
# rubocop:disable Layout/LineLength
|
89
|
+
command = %(docker compose build && docker compose run --rm #{tty_option} -e "GIT_AUTHOR_EMAIL=#{git_email}" -e "GIT_AUTHOR_NAME=#{git_name}" -e "GIT_COMMITTER_EMAIL=#{git_email}" -e "GIT_COMMITTER_NAME=#{git_name}" #{entrypoint_option} app)
|
90
|
+
command = if entrypoint_option == ''
|
91
|
+
"#{command} #{docker_args}"
|
92
|
+
else
|
93
|
+
"#{command} '#{docker_args}'"
|
94
|
+
end
|
95
|
+
# rubocop:enable Layout/LineLength
|
96
|
+
puts(command) if verbose
|
97
|
+
exec(command)
|
98
|
+
end
|
99
|
+
|
100
|
+
def main(args, verbose: false)
|
101
|
+
# Escape each argument individually
|
102
|
+
escaped_args = args.map { |arg| Shellwords.escape(arg) }
|
103
|
+
|
104
|
+
# Check if the arguments contain a Ruby command or only options
|
105
|
+
contains_command = false
|
106
|
+
escaped_args.each_with_index do |arg, index|
|
107
|
+
if !arg.start_with?('-') && (index.zero? || !escaped_args[index - 1].start_with?('-'))
|
108
|
+
contains_command = true
|
109
|
+
break
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
docker_args = if contains_command
|
114
|
+
escaped_args.join(' ')
|
115
|
+
else
|
116
|
+
"ruby #{escaped_args.join(' ')}"
|
117
|
+
end
|
118
|
+
|
119
|
+
if check_dockerfile(verbose: verbose)
|
120
|
+
executer_compose_run(docker_args, verbose: verbose)
|
121
|
+
else
|
122
|
+
executer_docker_run(docker_args, verbose: verbose)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
main(ARGV, verbose: true)
|
data/lib/modulorails/version.rb
CHANGED
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: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthieu Ciappara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler-audit
|
@@ -183,7 +183,7 @@ files:
|
|
183
183
|
- lib/generators/modulorails/docker/templates/entrypoints/docker-entrypoint.sh.tt
|
184
184
|
- lib/generators/modulorails/docker/templates/entrypoints/webpack-entrypoint.sh.tt
|
185
185
|
- lib/generators/modulorails/githooks/githooks_generator.rb
|
186
|
-
- lib/generators/modulorails/githooks/templates/dockeruby.
|
186
|
+
- lib/generators/modulorails/githooks/templates/dockeruby.rb
|
187
187
|
- lib/generators/modulorails/githooks/templates/post-rewrite.sh
|
188
188
|
- lib/generators/modulorails/githooks/templates/pre-merge-commit.sh
|
189
189
|
- lib/generators/modulorails/githooks/templates/refresh_generations.sh
|
@@ -1,112 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
set -e
|
3
|
-
|
4
|
-
# shellcheck disable=SC2016
|
5
|
-
VALID_LAST_INSTRUCTION='exec "${@}"'
|
6
|
-
|
7
|
-
# Check if the Dockerfile exists
|
8
|
-
check_dockerfile() {
|
9
|
-
if [ -f "Dockerfile" ]; then
|
10
|
-
return 0
|
11
|
-
else
|
12
|
-
echo "No Dockerfile"
|
13
|
-
return 1
|
14
|
-
fi
|
15
|
-
}
|
16
|
-
|
17
|
-
# Get the entrypoint location from the Dockerfile
|
18
|
-
entrypoint_location() {
|
19
|
-
entrypoint_line=$(grep '^ENTRYPOINT' Dockerfile || true)
|
20
|
-
|
21
|
-
if [ -z "$entrypoint_line" ]; then
|
22
|
-
echo ""
|
23
|
-
else
|
24
|
-
echo "$entrypoint_line" | sed -n 's/.*\[\(.*\)\].*/\1/p' | tr -d '"'
|
25
|
-
fi
|
26
|
-
}
|
27
|
-
|
28
|
-
# Check if the entrypoint is valid
|
29
|
-
check_entrypoint() {
|
30
|
-
el=$(entrypoint_location)
|
31
|
-
if [ -z "$el" ]; then
|
32
|
-
return 0
|
33
|
-
fi
|
34
|
-
|
35
|
-
if [ ! -f "$el" ]; then
|
36
|
-
echo "Entrypoint not found at location: $el"
|
37
|
-
return 1
|
38
|
-
fi
|
39
|
-
|
40
|
-
last_line=$(tail -n 1 "$el" | xargs)
|
41
|
-
|
42
|
-
if [ "$last_line" != "$VALID_LAST_INSTRUCTION" ]; then
|
43
|
-
echo "Invalid entrypoint: Last instruction should be '$VALID_LAST_INSTRUCTION' instead of '$last_line'"
|
44
|
-
return 1
|
45
|
-
fi
|
46
|
-
|
47
|
-
return 0
|
48
|
-
}
|
49
|
-
|
50
|
-
# Run docker with the necessary options
|
51
|
-
executer_docker_run() {
|
52
|
-
pwd=$(pwd)
|
53
|
-
working_directory=$(basename "$pwd")
|
54
|
-
|
55
|
-
tty_option=""
|
56
|
-
if [ -t 1 ]; then
|
57
|
-
tty_option="-ti"
|
58
|
-
fi
|
59
|
-
|
60
|
-
command="docker run --rm -v '$pwd:/app/$working_directory' -w '/app/$working_directory' $tty_option $git_environment ezveus/ruby:latest $docker_args"
|
61
|
-
echo "$command"
|
62
|
-
exec "$command"
|
63
|
-
}
|
64
|
-
|
65
|
-
executer_dockerfile_run() {
|
66
|
-
if check_entrypoint; then
|
67
|
-
entrypoint_option=""
|
68
|
-
else
|
69
|
-
entrypoint_option="--entrypoint \"sh -c\""
|
70
|
-
fi
|
71
|
-
|
72
|
-
command="docker compose build && docker compose run --rm $tty_option $git_environment $entrypoint_option app $docker_args"
|
73
|
-
echo "$command"
|
74
|
-
exec "$command"
|
75
|
-
}
|
76
|
-
|
77
|
-
# Main function
|
78
|
-
main() {
|
79
|
-
args="$*"
|
80
|
-
docker_args=""
|
81
|
-
contains_command=false
|
82
|
-
git_name=$(git config --get user.name || whoami)
|
83
|
-
git_email=$(git config --get user.email || echo "$git_name@local")
|
84
|
-
git_environment="-e \"GIT_AUTHOR_EMAIL=$git_email\" -e \"GIT_AUTHOR_NAME=$git_name\" -e \"GIT_COMMITTER_EMAIL=$git_email\" -e \"GIT_COMMITTER_NAME=$git_name\""
|
85
|
-
|
86
|
-
tty_option=""
|
87
|
-
if [ -t 1 ]; then
|
88
|
-
tty_option="-ti"
|
89
|
-
fi
|
90
|
-
|
91
|
-
for arg in "$@"; do
|
92
|
-
# Check if any argument is not an option (doesn't start with '-')
|
93
|
-
if [ "${arg#-}" = "$arg" ]; then
|
94
|
-
contains_command=true
|
95
|
-
break
|
96
|
-
fi
|
97
|
-
done
|
98
|
-
|
99
|
-
if [ "$contains_command" = false ]; then
|
100
|
-
docker_args="ruby $args"
|
101
|
-
else
|
102
|
-
docker_args="$args"
|
103
|
-
fi
|
104
|
-
|
105
|
-
if check_dockerfile; then
|
106
|
-
executer_dockerfile_run
|
107
|
-
else
|
108
|
-
executer_docker_run "$docker_args"
|
109
|
-
fi
|
110
|
-
}
|
111
|
-
|
112
|
-
main "$@"
|