r_dockerize 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/bin/console +9 -0
- data/bin/r_dockerize +17 -0
- data/bin/setup +8 -0
- data/lib/config/locales/en.yml +163 -0
- data/lib/r_dockerize/cli.rb +96 -0
- data/lib/r_dockerize/commands/base.rb +44 -0
- data/lib/r_dockerize/commands/dco.rb +108 -0
- data/lib/r_dockerize/commands/docker.rb +101 -0
- data/lib/r_dockerize/commands/dockerize.rb +25 -0
- data/lib/r_dockerize/commands/save.rb +65 -0
- data/lib/r_dockerize/config.rb +20 -0
- data/lib/r_dockerize/errors/base.rb +15 -0
- data/lib/r_dockerize/errors/command_not_found.rb +15 -0
- data/lib/r_dockerize/errors/db_not_found.rb +13 -0
- data/lib/r_dockerize/errors/docker_filename_error.rb +15 -0
- data/lib/r_dockerize/errors/js_not_found.rb +13 -0
- data/lib/r_dockerize/errors/subservice_not_found.rb +15 -0
- data/lib/r_dockerize.rb +3 -0
- data/lib/rdockerize.rb +15 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ba9604da9f5b4557a8b762578fc99f42d7c9efcd26d197313ce38cbf6024cf2f
|
4
|
+
data.tar.gz: d0da7d0675f684e500b7d8f2d91a3e3f320f1d3b67b4a9968cab39b332e409fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6960309e002b6fe7813c7e2ebbd9b845e0f569d30902864325c8463a317480d5c49db9cb664500d3a613742a296500f9186dcd1a62e5260dc3e8c764ebaeea82
|
7
|
+
data.tar.gz: ffa1b4a96057d64c7f71ac5393a411125c56bddc9ea2c6e02384168e733cb2410ae346e030ae0272da5980675e44296892ed92c060fe37e4bb8e39d7d68d9bb0
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Keallar
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# r_dockerize
|
2
|
+
|
3
|
+
`r_dockerize` is a tool for generating ruby and rails Dockerfile and docker-compose.yml
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* Ruby 2.6.0+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```bash
|
12
|
+
bundle install r_dockerize
|
13
|
+
```
|
14
|
+
...or add the following to your `Gemfile` and run `bundle install`:
|
15
|
+
```
|
16
|
+
gem 'r_dockerize', require: false
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This gem provides a command-line interface which can be run like so:
|
22
|
+
|
23
|
+
1. Run `r_dockerize <command> [options]` if gem installed in system
|
24
|
+
2. Run `bundle exec r_dockerize <command> [options]` if gem installed in your Gemfile
|
25
|
+
|
26
|
+
### Available commands
|
27
|
+
1. `r_dockerize docker [options]` - for create Dockerfile
|
28
|
+
```bash
|
29
|
+
Usage:
|
30
|
+
rdockerize docker [options]
|
31
|
+
|
32
|
+
Options:
|
33
|
+
-s, --show # Show assembled dockerfile
|
34
|
+
-u, --user # Use saved user's template
|
35
|
+
-j, --javascript=JAVASCRIPT # Choose JavaScript approach [options: npm, yarn]
|
36
|
+
-r, --ruby=RUBY_VERSION # Choose version of ruby
|
37
|
+
-d, --database=DATABASE # Choose database [options: sqlite]
|
38
|
+
--standard # Standard template
|
39
|
+
-h, --help # Print help for command
|
40
|
+
```
|
41
|
+
2. `r_dockerize dco ` / `compose`/ `docker-compose [options]` - for create docker-compose.yml
|
42
|
+
```bash
|
43
|
+
Usage:
|
44
|
+
rdockerize dco [options]
|
45
|
+
rdockerize compose [options]
|
46
|
+
rdockerize docker-compose [options]
|
47
|
+
|
48
|
+
Options:
|
49
|
+
-s, --show # Show assembled docker-compose file
|
50
|
+
-u, --user # Use saved user's template
|
51
|
+
-d, --database=DATABASE # Choose database [options: sqlite]
|
52
|
+
-b, --subservice=SUBSERVICE # Choose subservice [options: redis rabbitmq sidekiq]
|
53
|
+
-h, --help # Print help for command
|
54
|
+
|
55
|
+
```
|
56
|
+
3. `r_dockerize dockerize [options]` - for create both (Dockerfie and docker-compose.yml)
|
57
|
+
```bash
|
58
|
+
Usage:
|
59
|
+
rdockerize dockerize [options]
|
60
|
+
```
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
65
|
+
|
66
|
+
To install this gem onto your local machine, run `gem install r_dockerize`. To release a new version, update the version number in `version.rb`.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Keallar/r_dockerize.
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/bin/console
ADDED
data/bin/r_dockerize
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib_path = File.expand_path("../lib", __dir__)
|
5
|
+
$:.unshift(lib_path) unless $:.include? lib_path
|
6
|
+
|
7
|
+
require "r_dockerize"
|
8
|
+
require "bundler/setup"
|
9
|
+
|
10
|
+
begin
|
11
|
+
cli = RDockerize::CLI.new
|
12
|
+
cli.run(ARGV)
|
13
|
+
rescue StandardError => e
|
14
|
+
$stderr.puts e.message
|
15
|
+
$stderr.puts e.backtrace.join("\n") if RDockerize::DEBUG
|
16
|
+
exit 1
|
17
|
+
end
|
data/bin/setup
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
---
|
2
|
+
:en:
|
3
|
+
:r_dockerize:
|
4
|
+
:errors:
|
5
|
+
:messages:
|
6
|
+
:command_not_found: 'Non-existent command: %{command}. Available commands:
|
7
|
+
%{av_commands}'
|
8
|
+
:js_not_found: 'Non available js option: %{option}. Available options: %{av_options}'
|
9
|
+
:db_not_found: 'Non available db option: %{option}. Available options: %{av_options}'
|
10
|
+
:subservice_not_found: 'Non available subservice option: %{option}. Available
|
11
|
+
options: %{av_options}'
|
12
|
+
:docker_filename_error: Error in filename to save template. Use filename containing
|
13
|
+
"docker"
|
14
|
+
:docker:
|
15
|
+
:standard: |
|
16
|
+
# Standard Dockerfile
|
17
|
+
FROM ruby:%{ruby_version}
|
18
|
+
|
19
|
+
RUN apt-get update -qq && apt-get install -y postgresql-client
|
20
|
+
|
21
|
+
RUN curl -sL https://deb.nodesource.com/setup_19.x | bash -\
|
22
|
+
&& apt-get update -qq && apt-get install -qq --no-install-recommends \
|
23
|
+
nodejs \
|
24
|
+
&& apt-get upgrade -qq \
|
25
|
+
&& apt-get clean \
|
26
|
+
&& rm -rf /var/lib/apt/lists/*\
|
27
|
+
&& npm install -g yarn@1
|
28
|
+
|
29
|
+
RUN yarn add esbuild
|
30
|
+
RUN yarn add sass
|
31
|
+
|
32
|
+
ENV APP_APTH=/usr/src
|
33
|
+
WORKDIR $APP_APTH
|
34
|
+
|
35
|
+
ADD Gemfile $APP_APTH/Gemfile
|
36
|
+
ADD Gemfile.lock $APP_APTH/Gemfile.lock
|
37
|
+
|
38
|
+
RUN yarn install
|
39
|
+
|
40
|
+
RUN bundle install
|
41
|
+
:user_template: ''
|
42
|
+
:template: |
|
43
|
+
# Template Dockerfile
|
44
|
+
FROM ruby:%{ruby_version}
|
45
|
+
|
46
|
+
RUN apt-get update -qq
|
47
|
+
|
48
|
+
ENV APP_APTH=/usr/src
|
49
|
+
WORKDIR $APP_APTH
|
50
|
+
|
51
|
+
COPY ./ $APP_PATH
|
52
|
+
%{db_option}%{js_pm_option}
|
53
|
+
RUN bundle install
|
54
|
+
:db:
|
55
|
+
:sqlite: |
|
56
|
+
RUN apt-get update -qq && \
|
57
|
+
apt-get install -y sqlite3 libsqlite3-dev && \
|
58
|
+
apt-get clean && \
|
59
|
+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
60
|
+
:js_pm:
|
61
|
+
:yarn: |
|
62
|
+
RUN apt-get update && apt-get install -y \
|
63
|
+
curl \
|
64
|
+
build-essential \
|
65
|
+
libpq-dev &&\
|
66
|
+
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
|
67
|
+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
|
68
|
+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
|
69
|
+
apt-get update && apt-get install -y nodejs yarn
|
70
|
+
|
71
|
+
RUN yarn install
|
72
|
+
:npm: |
|
73
|
+
RUN apt-get update && apt-get install -y \
|
74
|
+
curl \
|
75
|
+
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
|
76
|
+
apt-get update && apt-get install -y nodejs
|
77
|
+
:dco:
|
78
|
+
:template: |-
|
79
|
+
# Standard template
|
80
|
+
version: '3.5'
|
81
|
+
|
82
|
+
services:
|
83
|
+
app:
|
84
|
+
build: .
|
85
|
+
command: sh -c "rm -f tmp/pids/server.pid && bin/dev"
|
86
|
+
tty: true
|
87
|
+
volumes:
|
88
|
+
- .:/usr/src
|
89
|
+
stdin_open: true
|
90
|
+
ports:
|
91
|
+
- "3000:3000"
|
92
|
+
%{js_option}
|
93
|
+
|
94
|
+
%{db_option}
|
95
|
+
|
96
|
+
%{subservices_option}
|
97
|
+
|
98
|
+
%{volumes_option}
|
99
|
+
:user_template: docker-compose
|
100
|
+
:db:
|
101
|
+
:postgresql: |-
|
102
|
+
postgresql:
|
103
|
+
image: postgres
|
104
|
+
environment:
|
105
|
+
- POSTGRES_USER=user
|
106
|
+
- POSTGRES_PASSWORD=pass
|
107
|
+
volumes:
|
108
|
+
- postgresql:/var/lib/postgresql/data
|
109
|
+
ports:
|
110
|
+
- "5432:5432"
|
111
|
+
:mysql: |-
|
112
|
+
mysql:
|
113
|
+
image: mysql:5.7
|
114
|
+
restart: always
|
115
|
+
environment:
|
116
|
+
- MYSQL_ROOT_PASSWORD=pass
|
117
|
+
- MYSQL_DATABASE=app
|
118
|
+
- MYSQL_USE=user
|
119
|
+
- MYSQL_PASSWORD=pass
|
120
|
+
ports:
|
121
|
+
- "3306:3306"
|
122
|
+
:mongodb: |-
|
123
|
+
mongo:
|
124
|
+
image: "mongo:4.2.8"
|
125
|
+
environment:
|
126
|
+
- MONGO_INITDB_ROOT_USERNAME=user
|
127
|
+
- MONGO_INITDB_ROOT_PASSWORD=pass
|
128
|
+
ports:
|
129
|
+
- "27017:27017"
|
130
|
+
volumes:
|
131
|
+
- "mongodb:/var/lib/mongodb/data"
|
132
|
+
:sqlite: |-
|
133
|
+
sqlite:
|
134
|
+
image: nouchka/sqlite3:latest
|
135
|
+
volumes:
|
136
|
+
- db:/root/db
|
137
|
+
stdin_open: true
|
138
|
+
tty: true
|
139
|
+
:subservices:
|
140
|
+
:redis: |-
|
141
|
+
redis:
|
142
|
+
image: redis:alpine
|
143
|
+
expose:
|
144
|
+
- 6379
|
145
|
+
volumes:
|
146
|
+
- redis:/data
|
147
|
+
|
148
|
+
:rabbitmq: |-
|
149
|
+
rabbitmq:
|
150
|
+
platform: linux/x86_64
|
151
|
+
image: rabbitmq:management-alpine
|
152
|
+
command: rabbitmq-server
|
153
|
+
ports:
|
154
|
+
- 15672:15672
|
155
|
+
expose:
|
156
|
+
- 5672
|
157
|
+
|
158
|
+
:sidekiq: |-
|
159
|
+
sidekiq:
|
160
|
+
build: .
|
161
|
+
command: bundle exec sidekiq
|
162
|
+
volumes:
|
163
|
+
- '.:/usr/src'
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optionparser"
|
4
|
+
|
5
|
+
module RDockerize
|
6
|
+
class CLI
|
7
|
+
COMMANDS = {
|
8
|
+
"dco" => "RDockerize::Commands::Dco",
|
9
|
+
"compose" => "RDockerize::Commands::Dco",
|
10
|
+
"docker-compose" => "RDockerize::Commands::Dco",
|
11
|
+
"docker" => "RDockerize::Commands::Docker",
|
12
|
+
"dockerize" => "RDockerize::Commands::Dockerize",
|
13
|
+
"save" => "RDockerize::Commands::Save"
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
option_parser
|
18
|
+
@print_help = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(args = ARGV)
|
22
|
+
command = parse_command(args)
|
23
|
+
|
24
|
+
print_help? unless command
|
25
|
+
|
26
|
+
args.delete(command)
|
27
|
+
|
28
|
+
begin
|
29
|
+
Object.const_get(COMMANDS[command]).run(args)
|
30
|
+
rescue TypeError, KeyError
|
31
|
+
raise Errors::CommandNotFound, command: command, av_commands: COMMANDS.keys.join(", ")
|
32
|
+
rescue StandardError => e
|
33
|
+
if DEBUG
|
34
|
+
$stdout.puts e.message
|
35
|
+
$stdout.puts e.backtrace.join("\n")
|
36
|
+
end
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def option_parser
|
44
|
+
@option_parser ||= OptionParser.new do |opts|
|
45
|
+
opts.banner = banner
|
46
|
+
|
47
|
+
opts.on("-v", "--version", "# Print the version number") do
|
48
|
+
$stdout.puts VERSION
|
49
|
+
exit 0
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on("-h", "--help", "# Print help") do
|
53
|
+
@print_help = true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_help?
|
59
|
+
$stdout.puts option_parser.help
|
60
|
+
exit 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse_command(args)
|
64
|
+
c_args = args.clone
|
65
|
+
unknown_args = []
|
66
|
+
begin
|
67
|
+
ordered_args = option_parser.order(c_args)
|
68
|
+
if ordered_args.empty?
|
69
|
+
option_parser.parse!(c_args)
|
70
|
+
return
|
71
|
+
end
|
72
|
+
command = c_args.shift
|
73
|
+
rescue OptionParser::InvalidOption => e
|
74
|
+
unknown_args += e.args
|
75
|
+
c_args -= unknown_args
|
76
|
+
retry
|
77
|
+
end
|
78
|
+
command
|
79
|
+
end
|
80
|
+
|
81
|
+
def banner
|
82
|
+
<<~USAGE
|
83
|
+
Usage:
|
84
|
+
rdockerize <command> [options]
|
85
|
+
|
86
|
+
Commands:
|
87
|
+
dockerize Create both files (Dockerfile and docker-compose.yml)
|
88
|
+
dco (or compose, docker-compose) Create docker-compose.yml file
|
89
|
+
docker Create Dockerfile
|
90
|
+
save Save user template for Dockerfile or docker-compose.yml
|
91
|
+
|
92
|
+
Options:
|
93
|
+
USAGE
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optionparser"
|
4
|
+
|
5
|
+
module RDockerize
|
6
|
+
module Commands
|
7
|
+
class Base
|
8
|
+
BASE_KEY = "r_dockerize"
|
9
|
+
|
10
|
+
def self.run(args)
|
11
|
+
new(args).run
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(args)
|
15
|
+
parse(args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse(args)
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def opt_parser
|
29
|
+
OptionParser.new do |opts|
|
30
|
+
yield opts if block_given?
|
31
|
+
|
32
|
+
opts.on("-h", "--help", "# Print help for command") do
|
33
|
+
$stdout.puts opts.help
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def banner
|
40
|
+
raise NotImplementedError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDockerize
|
4
|
+
module Commands
|
5
|
+
# rubocop disable:Style/IfUnlessModifier
|
6
|
+
class Dco < Base
|
7
|
+
attr_reader :db, :js, :subservices, :volumes
|
8
|
+
|
9
|
+
def self.run(args)
|
10
|
+
new(args).run
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
@show = false
|
15
|
+
@subservices = []
|
16
|
+
@user_temp = false
|
17
|
+
super(args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse(args)
|
21
|
+
@db = "sqlite"
|
22
|
+
|
23
|
+
parser = opt_parser do |opts|
|
24
|
+
opts.banner = banner
|
25
|
+
|
26
|
+
opts.on("-s", "--show", "# Show assembled docker-compose file") do
|
27
|
+
@show = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-u", "--user", "# Use saved user's template") do
|
31
|
+
@user_temp = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-d", "--database=DATABASE", "# Choose database [options: sqlite]") do |val|
|
35
|
+
prepare_db(val)
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-b", "--subservice=SUBSERVICE", "# Choose subservice [options: redis rabbitmq sidekiq]") do |val|
|
39
|
+
prepare_subservices(val)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.parse!(args)
|
44
|
+
end
|
45
|
+
|
46
|
+
def run
|
47
|
+
text = prepare_text
|
48
|
+
return $stdout.puts text if @show
|
49
|
+
|
50
|
+
File.open("docker-compose.yml", "w+") { |f| f.write(text) }
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
|
55
|
+
def banner
|
56
|
+
<<~USAGE
|
57
|
+
Usage:
|
58
|
+
rdockerize dco [options]
|
59
|
+
rdockerize compose [options]
|
60
|
+
rdockerize docker-compose [options]
|
61
|
+
|
62
|
+
Options:
|
63
|
+
USAGE
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def prepare_db(option)
|
69
|
+
unless DATABASE.include?(option)
|
70
|
+
raise RDockerize::Errors::DbNotFound, option: option,
|
71
|
+
av_options: DATABASE.join(" ")
|
72
|
+
end
|
73
|
+
|
74
|
+
@db = option
|
75
|
+
end
|
76
|
+
|
77
|
+
def prepare_subservices(option)
|
78
|
+
unless SUBSERVICES.include?(option)
|
79
|
+
raise RDockerize::Errors::SubserviceNotFound, option: option,
|
80
|
+
av_options: SUBSERVICES.join(" ")
|
81
|
+
end
|
82
|
+
|
83
|
+
@subservices << option
|
84
|
+
end
|
85
|
+
|
86
|
+
def prepare_text
|
87
|
+
return I18n.t("#{BASE_KEY}.dco.user_template") if @user_temp
|
88
|
+
|
89
|
+
js_text = I18n.t("#{BASE_KEY}.dco.js.#{@js}") if js_text
|
90
|
+
db_text = I18n.t("#{BASE_KEY}.dco.db.#{@db}")
|
91
|
+
subservice_text = if @subservices
|
92
|
+
@subservices.each_with_object([]) do |service, str_arr|
|
93
|
+
str_arr << "#{I18n.t("#{BASE_KEY}.dco.subservices.#{service.dup}")}\n"
|
94
|
+
end.join(" ")
|
95
|
+
else
|
96
|
+
""
|
97
|
+
end
|
98
|
+
volumes_text = "volumes:\n #{@db}:"
|
99
|
+
|
100
|
+
I18n.t(
|
101
|
+
"#{BASE_KEY}.dco.template",
|
102
|
+
js_option: js_text, db_option: db_text, subservices_option: subservice_text, volumes_option: volumes_text
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
# rubocop enable:Style/IfUnlessModifier
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDockerize
|
4
|
+
module Commands
|
5
|
+
class Docker < Base
|
6
|
+
attr_reader :db, :js_pm, :rv
|
7
|
+
|
8
|
+
def self.run(args)
|
9
|
+
new(args).run
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(args)
|
13
|
+
@user_temp = false
|
14
|
+
@show = false
|
15
|
+
@standard = false
|
16
|
+
super(args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# rubocop:disable Metrics/MethodLength
|
20
|
+
def parse(args)
|
21
|
+
@rv = RUBY_VERSION
|
22
|
+
|
23
|
+
parser = opt_parser do |opts|
|
24
|
+
opts.banner = banner
|
25
|
+
|
26
|
+
opts.on("-s", "--show", "# Show assembled dockerfile") do
|
27
|
+
@show = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on("-u", "--user", "# Use saved user's template") do
|
31
|
+
@user_temp = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-j", "--javascript=JAVASCRIPT", "# Choose JavaScript approach [options: npm, yarn]") do |val|
|
35
|
+
prepare_js_pm(val)
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on("-r", "--ruby=RUBY_VERSION", "# Choose version of ruby") do |val|
|
39
|
+
@rv = val
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on("-d", "--database=DATABASE", "# Choose database [options: sqlite]") do |val|
|
43
|
+
prepare_db(val)
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("--standard", "# Standard template") do
|
47
|
+
@standard = true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
parser.parse!(args)
|
52
|
+
end
|
53
|
+
# rubocop:enable Metrics/MethodLength
|
54
|
+
|
55
|
+
def run
|
56
|
+
text = prepare_text
|
57
|
+
return $stdout.puts text if @show
|
58
|
+
|
59
|
+
File.open("Dockerfile", "w+") { |f| f.write(text) }
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def banner
|
65
|
+
<<~USAGE
|
66
|
+
Usage:
|
67
|
+
rdockerize docker [options]
|
68
|
+
|
69
|
+
Options:
|
70
|
+
USAGE
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def prepare_js_pm(option)
|
76
|
+
unless JAVASCRIPT_PM.include?(option)
|
77
|
+
raise Errors::JsNotFound, option: option, av_options: JAVASCRIPT_PM.join(" ")
|
78
|
+
end
|
79
|
+
|
80
|
+
@js_pm = option
|
81
|
+
end
|
82
|
+
|
83
|
+
def prepare_db(option)
|
84
|
+
raise Errors::DbNotFound, option: option, av_options: DATABASE.join(" ") unless DATABASE.include?(option)
|
85
|
+
|
86
|
+
@db = option
|
87
|
+
end
|
88
|
+
|
89
|
+
def prepare_text
|
90
|
+
return I18n.t("#{BASE_KEY}.docker.user_template") if @user_temp
|
91
|
+
return I18n.t("#{BASE_KEY}.docker.standard", ruby_version: @rv) if @standard
|
92
|
+
|
93
|
+
js_pm_text = I18n.t("#{BASE_KEY}.docker.js_pm.#{@js_pm}") if @js_pm
|
94
|
+
db_text = I18n.t("#{BASE_KEY}.docker.db.#{@db}") if @db
|
95
|
+
|
96
|
+
I18n.t("#{BASE_KEY}.docker.template",
|
97
|
+
ruby_version: @rv, js_pm_option: js_pm_text, db_option: db_text)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDockerize
|
4
|
+
module Commands
|
5
|
+
class Dockerize < Base
|
6
|
+
def self.run(args)
|
7
|
+
new(args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse(args)
|
11
|
+
RDockerize::Commands::Dco.run(args)
|
12
|
+
RDockerize::Commands::Docker.run(args)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def banner
|
18
|
+
<<~USAGE
|
19
|
+
Usage:
|
20
|
+
rdockerize dockerize
|
21
|
+
USAGE
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDockerize
|
4
|
+
module Commands
|
5
|
+
class Save < Base
|
6
|
+
def self.run(args)
|
7
|
+
new(args).run
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse(args)
|
11
|
+
raise OptionParser::InvalidOption if args.empty?
|
12
|
+
|
13
|
+
exec_opt = lambda do |val, type|
|
14
|
+
docker_file?(val)
|
15
|
+
save_template(val, type)
|
16
|
+
$stdout.puts val
|
17
|
+
end
|
18
|
+
|
19
|
+
parser = opt_parser do |opts|
|
20
|
+
opts.banner = banner
|
21
|
+
|
22
|
+
opts.on("-d", "--dockerfile=DOCKERFILE_PATH", "# Path to Dockerfile (default)") do |val|
|
23
|
+
exec_opt.call(val, :docker)
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on("-c", "--compose=COMPOSEFILE_PATH", "# Path to docker-compose file") do |val|
|
27
|
+
exec_opt.call(val, :dco)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
parser.parse!(args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
$stdout.puts "Template saved!"
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def banner
|
41
|
+
<<~USAGE
|
42
|
+
Usage:
|
43
|
+
rdockerize save [options]
|
44
|
+
|
45
|
+
Options:
|
46
|
+
USAGE
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def save_template(path, type)
|
52
|
+
user_data = File.read(File.expand_path(path))
|
53
|
+
i18n_path = I18n.load_path.last
|
54
|
+
yaml_hash = YAML.load(File.read(i18n_path), symbolize_names: true)
|
55
|
+
yaml_hash[:en][:r_dockerize][type][:user_template] = user_data
|
56
|
+
File.write(i18n_path, yaml_hash.to_yaml)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Validate filename of template
|
60
|
+
def docker_file?(path)
|
61
|
+
raise Errors::DockerFilenameError unless File.basename(path).downcase.include?("docker")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "i18n"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
module RDockerize
|
7
|
+
VERSION = "0.1.0"
|
8
|
+
|
9
|
+
DEBUG = false
|
10
|
+
|
11
|
+
STANDARD_COMPOSE_VERSION = 3.5
|
12
|
+
|
13
|
+
DATABASE = %w[postgresql mysql mongodb sqlite].freeze
|
14
|
+
|
15
|
+
JAVASCRIPT_PM = %w[yarn npm].freeze
|
16
|
+
|
17
|
+
SUBSERVICES = %w[redis rabbitmq sidekiq].freeze
|
18
|
+
|
19
|
+
I18n.load_path << File.join(File.dirname(__FILE__), "..", "config", "locales", "en.yml")
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RDockerize
|
4
|
+
module Errors
|
5
|
+
class Base < StandardError
|
6
|
+
BASE_KEY = "r_dockerize.errors.messages"
|
7
|
+
|
8
|
+
attr_reader :key, :attrs
|
9
|
+
|
10
|
+
def create_message
|
11
|
+
I18n.t("#{BASE_KEY}.#{key}", **{ locale: :en }.merge(attrs))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
module RDockerize
|
6
|
+
module Errors
|
7
|
+
class DockerFilenameError < Base
|
8
|
+
def initialize(attrs = {})
|
9
|
+
@key = "docker_filename_error"
|
10
|
+
@attrs = attrs
|
11
|
+
super(create_message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module RDockerize
|
6
|
+
module Errors
|
7
|
+
class SubserviceNotFound < Base
|
8
|
+
def initialize(attrs)
|
9
|
+
@key = "subservice_not_found"
|
10
|
+
@attrs = attrs
|
11
|
+
super(create_message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/r_dockerize.rb
ADDED
data/lib/rdockerize.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "r_dockerize/config"
|
4
|
+
require "r_dockerize/cli"
|
5
|
+
require "r_dockerize/commands/base"
|
6
|
+
require "r_dockerize/commands/dco"
|
7
|
+
require "r_dockerize/commands/docker"
|
8
|
+
require "r_dockerize/commands/dockerize"
|
9
|
+
require "r_dockerize/commands/save"
|
10
|
+
require "r_dockerize/errors/base"
|
11
|
+
require "r_dockerize/errors/command_not_found"
|
12
|
+
require "r_dockerize/errors/js_not_found"
|
13
|
+
require "r_dockerize/errors/db_not_found"
|
14
|
+
require "r_dockerize/errors/subservice_not_found"
|
15
|
+
require "r_dockerize/errors/docker_filename_error"
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: r_dockerize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keallar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.14.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.14.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: CLI app for creating ruby and rails Dockerfile and docker-compose.yml
|
56
|
+
email:
|
57
|
+
- zlysanskiy@gmail.com
|
58
|
+
executables:
|
59
|
+
- console
|
60
|
+
- r_dockerize
|
61
|
+
- setup
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- CHANGELOG.md
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- bin/console
|
69
|
+
- bin/r_dockerize
|
70
|
+
- bin/setup
|
71
|
+
- lib/config/locales/en.yml
|
72
|
+
- lib/r_dockerize.rb
|
73
|
+
- lib/r_dockerize/cli.rb
|
74
|
+
- lib/r_dockerize/commands/base.rb
|
75
|
+
- lib/r_dockerize/commands/dco.rb
|
76
|
+
- lib/r_dockerize/commands/docker.rb
|
77
|
+
- lib/r_dockerize/commands/dockerize.rb
|
78
|
+
- lib/r_dockerize/commands/save.rb
|
79
|
+
- lib/r_dockerize/config.rb
|
80
|
+
- lib/r_dockerize/errors/base.rb
|
81
|
+
- lib/r_dockerize/errors/command_not_found.rb
|
82
|
+
- lib/r_dockerize/errors/db_not_found.rb
|
83
|
+
- lib/r_dockerize/errors/docker_filename_error.rb
|
84
|
+
- lib/r_dockerize/errors/js_not_found.rb
|
85
|
+
- lib/r_dockerize/errors/subservice_not_found.rb
|
86
|
+
- lib/rdockerize.rb
|
87
|
+
homepage: https://github.com/Keallar/r_dockerize
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata:
|
91
|
+
homepage_uri: https://github.com/Keallar/r_dockerize
|
92
|
+
source_code_uri: https://github.com/Keallar/r_dockerize
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.6.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubygems_version: 3.5.5
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: CLI app for creating ruby and rails Dockerfile and docker-compose.yml.
|
112
|
+
test_files: []
|