dpmrb 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1288404d92033ac62902d42ed3727ac3de47df684ce225adf8f386d9a7968edd
4
- data.tar.gz: ca7f984fe889bdb0c497e6e04865d1166231b71ffc744d66c49361b00e5ff914
3
+ metadata.gz: d408ee6f24c0e503159587c35ef634821cba4143ee0a4bde49c0497636cde125
4
+ data.tar.gz: 1de01b1572bcc96575e7f2716ac78fefc5e38f87da9ed59e25a8d27117861e79
5
5
  SHA512:
6
- metadata.gz: ab4c5ef506c195e0bf11c52620a12c10d6ec2bfa07d2dd8c3307f2431b11f013c7a752eef9cb17d4c289242fa7c9d66a31d140c4f9c9ee73580fd1830a6f8b7c
7
- data.tar.gz: a25e3e9b13ff5a5bd36a64a92d146a728373593c907f989b279bbcf4bd1b2b7838b55af029672bae8048b9819bcd2fb4d8d36d4a1042c639e517057cf77cff12
6
+ metadata.gz: 14f44aa24ca13e24032199766ddfc0ee90e25e8ffd873cba6d53ecffbc751def9a01cedd4c9e52457b64a44ccff48d65da6e30e20d9cbd3e1d23595708a760ed
7
+ data.tar.gz: 0cf758ea38f95aea2cd0ce13d3ca300f0936d5c751b1fc957b993395d3f020ecef5850f78ad39c9135f587dd88b03b993cfe612f2819a3e700ebc5703702e0bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dpmrb (0.2.0)
4
+ dpmrb (0.2.1)
5
5
  activesupport (~> 6.x)
6
6
 
7
7
  GEM
data/README.en-US.md ADDED
@@ -0,0 +1,41 @@
1
+ [简体中文](README.md) | [English](README.en-US.md)
2
+
3
+ # DPM
4
+
5
+ Docker Package Manager, makes using your containers as easy as package managers (`apt`, `yml`, `brew`).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gem install dpmrb
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ dpm help # Show help
17
+ dpm list # docker ps --filter "name=dpm-"
18
+ dpm start mysql # docker run --name=dpm-mysql -d --rm -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes ...
19
+ dpm stop mysql # docker stop dpm-mysql
20
+ dpm status mysql # docker ps --filter "name=dpm-mysql"
21
+ dpm start elasticsearch:7.10.2 # docker run --name=dpm-elasticsearch-7.10.2 -d --rm -p 9200:9200 -e discovery.type=single-node ...
22
+ dpm start mysql:5.7 # docker run --name=dpm-mysql-5.7 -d --rm -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes ...
23
+ ```
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/songhuangcn/dpm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/songhuangcn/dpm/blob/main/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the DPM project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/songhuangcn/dpm/blob/main/CODE_OF_CONDUCT.md).
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
- [English](README.md) | [简体中文](README.zh-CN.md)
1
+ [简体中文](README.md) | [English](README.en-US.md)
2
2
 
3
3
  # DPM
4
4
 
5
- Docker Package Manager, makes using your containers as easy as package managers (`apt`, `yml`, `brew`).
5
+ Docker Package Manager, 让你的容器用起来跟包管理器(`apt`, `yml`, `brew`)一样简单。
6
6
 
7
- ## Installation
7
+ ## 安装
8
8
 
9
9
  ```bash
10
10
  gem install dpmrb
11
11
  ```
12
12
 
13
- ## Usage
13
+ ## 使用
14
14
 
15
15
  ```bash
16
16
  dpm help # Show help
@@ -22,20 +22,82 @@ dpm start elasticsearch:7.10.2 # docker run --name=dpm-elasticsearch-7.10.2 -d -
22
22
  dpm start mysql:5.7 # docker run --name=dpm-mysql-5.7 -d --rm -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes ...
23
23
  ```
24
24
 
25
- ## Development
25
+ ## 为项目添加新包
26
26
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+ DPM [Homebrew](https://brew.sh/) 一样,需要完善更多的包配置,欢迎为 `packages` 目录添加你需要的包配置。
28
28
 
29
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+ ### 配置级别
30
30
 
31
- ## Contributing
31
+ 容器配置都是通用的 YAML 格式,有三个级别:
32
32
 
33
- Bug reports and pull requests are welcome on GitHub at https://github.com/songhuangcn/dpm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/songhuangcn/dpm/blob/main/CODE_OF_CONDUCT.md).
33
+ 1. 默认级别:`packages/default.yml`
34
+ 1. 包级别:`packages/PACKAGE/default.yml`
35
+ 1. 版本级别:`packages/PACKAGE/tag-TAG.yml`
34
36
 
35
- ## License
37
+ 配置是合并机制,如果一个包没有自定义配置,他就会根据默认级别配置跑起来。
36
38
 
37
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+ ### 配置示例
38
40
 
39
- ## Code of Conduct
41
+ 例如有配置如下:
40
42
 
41
- Everyone interacting in the DPM project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/songhuangcn/dpm/blob/main/CODE_OF_CONDUCT.md).
43
+ 1. `packages/default.yml`:
44
+ ```yml
45
+ run_options:
46
+ rm: true
47
+ d: true
48
+ ```
49
+ 1. `packages/mysql/default.yml`:
50
+ ```yml
51
+ run_options:
52
+ e: "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
53
+ p: "3306:3306"
54
+ ```
55
+ 1. `packages/mysql/tag-5.7.yml`:
56
+ ```yml
57
+ run_options:
58
+ p: "3307:3307"
59
+ ```
60
+
61
+ 则最终这些包配置的启动命令为:
62
+
63
+ - `mysql:5.7` 的配置:
64
+ ```bash
65
+ docker run --rm -d -p 3307:3307 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.7
66
+ ```
67
+ - `mysql` 的配置:
68
+ ```bash
69
+ docker run --rm -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql
70
+ ```
71
+ - `not-exist-pkg` 的配置:
72
+ ```bash
73
+ docker run --rm -d not-exist-pkg
74
+ ```
75
+
76
+ ### 其他配置
77
+
78
+ 有一些其他配置项,例如 `image`:
79
+
80
+ `packages/elasticsearch/default.yml`
81
+ ```yml
82
+ image: "docker.elastic.co/elasticsearch/elasticsearch"
83
+ ```
84
+
85
+ 则 `elasticsearch` 包的镜像将不在按约定自动计算,而是变成了:
86
+
87
+ ```bash
88
+ docker.elastic.co/elasticsearch/elasticsearch
89
+ ```
90
+
91
+ 还有一些配置,例如:`args`,这个是传入到容器的参数,例如有配置文件 `packages/mysql/default.yml`:
92
+
93
+ ```yml
94
+ args:
95
+ character-set-server: "utf8mb4"
96
+ collation-server: "utf8mb4_unicode_ci"
97
+ ```
98
+
99
+ 则所有版本的 `mysql` 包将会多这两个启动参数:
100
+
101
+ ```bash
102
+ docker run mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
103
+ ```
data/bin/dpm CHANGED
@@ -3,8 +3,8 @@
3
3
  require_relative "../lib/dpm"
4
4
 
5
5
  begin
6
- DPM::Runner.call!(ARGV)
6
+ DPM.call!(ARGV)
7
7
  rescue => exception
8
- puts "Errors: #{exception.message}"
8
+ puts "Fatal error: #{exception.message}"
9
9
  exit 1
10
10
  end
@@ -1,7 +1,8 @@
1
+ base:
2
+ {}
1
3
  run_options:
2
4
  name: "<%= container_name %>"
3
5
  d: true
4
6
  rm: true
5
- image: ""
6
- command: ""
7
- args: {}
7
+ run_args:
8
+ {}
@@ -0,0 +1,88 @@
1
+ require "optparse"
2
+
3
+ module DPM
4
+ class Options
5
+ PACKAGE_COMMANDS = %w[tags status start stop restart].freeze
6
+ PACKAGE_REGEX = /\A[\w.\-:]+\z/.freeze
7
+ UNPACKAGE_COMMANDS = %w[list packages].freeze
8
+
9
+ attr_accessor :argv, :dry_run, :parser, :command, :package
10
+
11
+ def initialize(argv)
12
+ self.argv = argv
13
+ self.dry_run = false
14
+ end
15
+
16
+ def self.parse!(argv)
17
+ new(argv).parse!
18
+ end
19
+
20
+ def parse!
21
+ OptionParser.new do |parser|
22
+ self.parser = parser
23
+
24
+ parser.banner = "Usage: dpm [options] [COMMAND] [PACKAGE]"
25
+ parser.separator ""
26
+ parser.separator "Specific options:"
27
+
28
+ parser.on("-d", "--dry-run", "Don't actually run anything, just print") do |v|
29
+ self.dry_run = v
30
+ end
31
+
32
+ parser.separator ""
33
+ parser.separator "Common options:"
34
+
35
+ parser.on_tail("-h", "--help", "Show the help") do
36
+ puts help_text
37
+ exit
38
+ end
39
+
40
+ parser.on_tail("-v", "--version", "Show the version") do
41
+ puts VERSION
42
+ exit
43
+ end
44
+
45
+ parser.parse!(argv)
46
+ end
47
+
48
+ process_args!
49
+ self
50
+ end
51
+
52
+ def help_text
53
+ <<~EOF
54
+ #{parser}
55
+ COMMAND:
56
+ help Show the help
57
+ version Show the version
58
+ packages List supported packages
59
+ list List running packages
60
+ tags PACKAGE List supported tags of a package
61
+ status PACKAGE Get the status of a package
62
+ start PACKAGE Start a package
63
+ stop PACKAGE Stop a package
64
+ restart PACKAGE Restart a package
65
+
66
+ See more at https://github.com/songhuangcn/dpm
67
+ EOF
68
+ end
69
+
70
+ def process_args!
71
+ self.command, self.package = argv
72
+
73
+ case command
74
+ when "help"
75
+ puts help_text
76
+ exit
77
+ when "version"
78
+ puts VERSION
79
+ exit
80
+ when *PACKAGE_COMMANDS
81
+ raise Error, "Command `#{command}` need a package" if package.blank?
82
+ raise Error, "Package invalid, valid regex: #{PACKAGE_REGEX}" if !PACKAGE_REGEX.match?(package)
83
+ else
84
+ raise Error, "Unknown command `#{command}`, see `dpm help`" unless UNPACKAGE_COMMANDS.include?(command)
85
+ end
86
+ end
87
+ end
88
+ end
data/lib/dpm/runner.rb CHANGED
@@ -5,81 +5,71 @@ require "erb"
5
5
 
6
6
  module DPM
7
7
  class Runner
8
- PACKAGE_COMMANDS = %w[status start stop restart].freeze
9
- PACKAGE_REGEX = /\A[\w.\-:]+\z/.freeze
10
8
  CONTAINER_NAME_PREFIX = "dpm-"
11
9
  BASH_COLOR_GRAY = "\033[0;37m"
12
10
  BASH_COLOR_NONE = "\033[0m"
11
+ DOCKER_COMMANDS = %w[list status start stop restart].freeze
13
12
 
14
- attr_reader :command, :package
13
+ attr_accessor :options
15
14
 
16
- def self.call!(argv)
17
- new(argv).call!
15
+ def self.call!(options)
16
+ new(options).call!
18
17
  end
19
18
 
20
- def initialize(argv)
21
- @command, @package = argv
22
- validate_argv!
19
+ def initialize(options)
20
+ self.options = options
23
21
  end
24
22
 
25
23
  def call!
26
- if docker_command
27
- puts bash_color(docker_command)
28
- puts ""
29
- puts `#{docker_command}`
30
- else
31
- puts help_text
24
+ case options.command
25
+ when *DOCKER_COMMANDS
26
+ call_docker!
27
+ when "packages"
28
+ call_packages!
29
+ when "tags"
30
+ call_tags!
32
31
  end
33
32
  end
34
33
 
35
34
  private
36
35
 
37
- def validate_argv!
38
- if PACKAGE_COMMANDS.include?(command) && !PACKAGE_REGEX.match?(package)
39
- raise Error, "`package` invalid, valid regex: #{PACKAGE_REGEX}"
40
- end
41
- end
42
-
43
- def bash_color(text)
44
- "#{BASH_COLOR_GRAY}#{text}#{BASH_COLOR_NONE}"
45
- end
46
-
47
- def docker_command
48
- case command
36
+ def call_docker!
37
+ docker_command = case options.command
49
38
  when "list"
50
39
  %(docker ps --filter "name=#{CONTAINER_NAME_PREFIX}")
51
40
  when "status"
52
- %(docker ps --filter "name=#{container_name}")
41
+ %(docker ps --filter "name=^/#{container_name}$")
53
42
  when "start"
54
43
  "docker run #{docker_run_params}"
55
44
  when "stop"
56
45
  "docker stop #{container_name}"
57
46
  when "restart"
58
- "dpm stop #{package} && dpm start #{package}"
47
+ "dpm stop #{options.package} && dpm start #{options.package}"
48
+ else
49
+ raise "Not implemented command: `#{command}`"
50
+ end
51
+ if options.dry_run
52
+ puts "Dry run:"
53
+ puts bash_color(docker_command)
54
+ else
55
+ puts bash_color(docker_command)
56
+ puts ""
57
+ puts `#{docker_command}`
59
58
  end
60
59
  end
61
60
 
62
- def help_text
63
- <<~EOF
64
- Usage: dpm command [PACKAGE]
65
-
66
- Docker Package Manager
61
+ def call_packages!
62
+ packages = Dir.glob(File.join(ROOT, "packages", "*.yml")).map { |file| File.basename(file, ".yml") }
63
+ puts packages
64
+ end
67
65
 
68
- dpm help:
69
- Show the help
70
- dpm list:
71
- List running packages
72
- dpm status PACKAGE:
73
- Get the status of the package
74
- dpm start PACKAGE:
75
- Start the package
76
- dpm stop PACKAGE:
77
- Stop the package
78
- dpm restart PACKAGE:
79
- Restart the package
66
+ def call_tags!
67
+ tags = package_config_yaml.keys.reject { |key| key.start_with?(".") }
68
+ puts tags
69
+ end
80
70
 
81
- See more at https://github.com/songhuangcn/dpm
82
- EOF
71
+ def bash_color(text)
72
+ "#{BASH_COLOR_GRAY}#{text}#{BASH_COLOR_NONE}"
83
73
  end
84
74
 
85
75
  def docker_run_params
@@ -87,15 +77,15 @@ module DPM
87
77
  end
88
78
 
89
79
  def config_run_options
90
- process_options(manager_config["run_options"])
80
+ process_options(package_config["run_options"])
91
81
  end
92
82
 
93
83
  def config_command
94
- manager_config["command"]
84
+ package_config["base"]["command"]
95
85
  end
96
86
 
97
87
  def config_args
98
- process_options(manager_config["args"])
88
+ process_options(package_config["run_args"])
99
89
  end
100
90
 
101
91
  def process_options(hash)
@@ -123,49 +113,58 @@ module DPM
123
113
  end
124
114
 
125
115
  def docker_image
126
- image_tag ? "#{image_name}:#{image_tag}" : image_name
116
+ "#{image_name}:#{image_tag}"
127
117
  end
128
118
 
129
119
  def image_name
130
- @image_name ||= manager_config["image_name"] || package_name
120
+ @image_name ||= package_config["image_name"] || package_name
131
121
  end
132
122
 
133
123
  def image_tag
134
- @image_tag ||= manager_config["image_tag"] || package_tag
124
+ @image_tag ||= package_config["image_tag"] || package_tag
135
125
  end
136
126
 
137
- def manager_config
138
- @manager_config ||= begin
139
- default_options = load_yaml(File.join(ROOT, "packages", "default.yml"))
140
- image_options = load_yaml(File.join(ROOT, "packages", package_name, "default.yml"))
141
- tag_options = load_yaml(File.join(ROOT, "packages", package_name, "tag-#{package_tag}.yml"))
142
-
143
- default_options \
144
- .deep_merge(image_options) \
145
- .deep_merge(tag_options)
127
+ def package_config
128
+ @package_config ||= begin
129
+ version = package_tag.dup
130
+ version_config = loop do
131
+ raise Error, "Package tag `#{package_tag}` not support" unless version
132
+ break package_config_yaml[version] if package_config_yaml[version]
133
+ version = version.sub!(/\.\d+\z/, "")
134
+ end
135
+ default_config.deep_merge(version_config)
146
136
  end
147
137
  end
148
138
 
139
+ def package_config_yaml
140
+ @package_config_yaml ||= load_yaml(File.join(ROOT, "packages", "#{package_name}.yml"))
141
+ rescue Errno::ENOENT
142
+ raise Error, "Package `#{package_name}` not support"
143
+ end
144
+
145
+ def default_config
146
+ @default_config ||= load_yaml(File.join(ROOT, "config", "package.yml"))
147
+ end
148
+
149
149
  def package_name
150
- @package_name ||= package.split(":")[0]
150
+ @package_name ||= options.package.split(":")[0]
151
151
  end
152
152
 
153
153
  def package_tag
154
- @package_tag ||= package.split(":")[1]
154
+ @package_tag ||= options.package.split(":")[1] || "latest"
155
155
  end
156
156
 
157
157
  def container_name
158
- @container_name ||= "#{CONTAINER_NAME_PREFIX}#{package.tr(":", "-")}"
158
+ @container_name ||= "#{CONTAINER_NAME_PREFIX}#{options.package.tr(":", "-")}"
159
159
  end
160
160
 
161
161
  def load_yaml(file_path)
162
162
  text = File.read(file_path)
163
163
  data = ERB.new(text).result(binding)
164
- YAML.safe_load(data).tap do |yaml|
164
+ yaml = YAML.safe_load(data, aliases: true).tap do |yaml|
165
165
  raise Error, "Config need to be a hash yaml: #{file_path}" unless yaml.is_a?(Hash)
166
166
  end
167
- rescue Errno::ENOENT
168
- {}
167
+ yaml.transform_keys!(&:to_s)
169
168
  end
170
169
  end
171
170
  end
data/lib/dpm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DPM
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/dpm.rb CHANGED
@@ -5,9 +5,17 @@ require "active_support/core_ext"
5
5
 
6
6
  require_relative "dpm/version"
7
7
  require_relative "dpm/errors"
8
+ require_relative "dpm/options"
8
9
  require_relative "dpm/runner"
9
10
 
10
11
  module DPM
11
12
  ROOT = File.expand_path("..", __dir__).freeze
12
13
  HOME = File.expand_path("~/.dpm").freeze
14
+
15
+ def self.call!(argv)
16
+ options = Options.parse!(argv)
17
+ Runner.call!(options)
18
+ rescue Error => exception
19
+ puts "Error: #{exception.message}"
20
+ end
13
21
  end
@@ -0,0 +1,35 @@
1
+ .base: &base
2
+ {}
3
+ .run_options: &run_options
4
+ p:
5
+ - "9200:9200"
6
+ - "9300:9300"
7
+ v: "<%= DPM::HOME %>/data/<%= package_name %>/<%= package_tag || 'default' %>:/usr/share/elasticsearch/data"
8
+ .run_args: &run_args
9
+ {}
10
+
11
+ latest:
12
+ base:
13
+ <<: *base
14
+ run_options:
15
+ <<: *run_options
16
+ run_args:
17
+ <<: *run_args
18
+
19
+ 8:
20
+ base:
21
+ <<: *base
22
+ run_options:
23
+ <<: *run_options
24
+ run_args:
25
+ <<: *run_args
26
+
27
+ 7:
28
+ base:
29
+ <<: *base
30
+ image_name: "docker.elastic.co/elasticsearch/elasticsearch"
31
+ run_options:
32
+ <<: *run_options
33
+ e: "discovery.type=single-node"
34
+ run_args:
35
+ <<: *run_args
@@ -0,0 +1,35 @@
1
+ .base: &base
2
+ {}
3
+ .run_options: &run_options
4
+ p: "3306:3306"
5
+ e: "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
6
+ v: "<%= DPM::HOME %>/data/<%= package_name %>/<%= package_tag || 'default' %>:/var/lib/mysql"
7
+ .run_args: &run_args
8
+ character-set-server: "utf8mb4"
9
+ collation-server: "utf8mb4_unicode_ci"
10
+
11
+ latest:
12
+ base:
13
+ <<: *base
14
+ run_options:
15
+ <<: *run_options
16
+ run_args:
17
+ <<: *run_args
18
+
19
+ 8:
20
+ base:
21
+ <<: *base
22
+ run_options:
23
+ <<: *run_options
24
+ p: "3306:3306"
25
+ run_args:
26
+ <<: *run_args
27
+
28
+ 5:
29
+ base:
30
+ <<: *base
31
+ run_options:
32
+ <<: *run_options
33
+ p: "3307:3307"
34
+ run_args:
35
+ <<: *run_args
@@ -0,0 +1,22 @@
1
+ .base: &base
2
+ {}
3
+ .run_options: &run_options
4
+ p: "80:80"
5
+ .run_args: &run_args
6
+ {}
7
+
8
+ latest:
9
+ base:
10
+ <<: *base
11
+ run_options:
12
+ <<: *run_options
13
+ run_args:
14
+ <<: *run_args
15
+
16
+ 1:
17
+ base:
18
+ <<: *base
19
+ run_options:
20
+ <<: *run_options
21
+ run_args:
22
+ <<: *run_args
@@ -0,0 +1,56 @@
1
+ .base: &base
2
+ {}
3
+ .run_options: &run_options
4
+ p: "5432:5432"
5
+ e: "POSTGRES_PASSWORD=mysecretpassword"
6
+ v: "<%= DPM::HOME %>/data/<%= package_name %>/<%= package_tag || 'default' %>:/var/lib/postgressql/data"
7
+ .run_args: &run_args
8
+ {}
9
+
10
+ latest:
11
+ base:
12
+ <<: *base
13
+ run_options:
14
+ <<: *run_options
15
+ run_args:
16
+ <<: *run_args
17
+
18
+ 14:
19
+ base:
20
+ <<: *base
21
+ run_options:
22
+ <<: *run_options
23
+ run_args:
24
+ <<: *run_args
25
+
26
+ 13:
27
+ base:
28
+ <<: *base
29
+ run_options:
30
+ <<: *run_options
31
+ run_args:
32
+ <<: *run_args
33
+
34
+ 12:
35
+ base:
36
+ <<: *base
37
+ run_options:
38
+ <<: *run_options
39
+ run_args:
40
+ <<: *run_args
41
+
42
+ 11:
43
+ base:
44
+ <<: *base
45
+ run_options:
46
+ <<: *run_options
47
+ run_args:
48
+ <<: *run_args
49
+
50
+ 10:
51
+ base:
52
+ <<: *base
53
+ run_options:
54
+ <<: *run_options
55
+ run_args:
56
+ <<: *run_args
@@ -0,0 +1,38 @@
1
+ .base: &base
2
+ {}
3
+ .run_options: &run_options
4
+ p: "6379:6379"
5
+ .run_args: &run_args
6
+ {}
7
+
8
+ latest:
9
+ base:
10
+ <<: *base
11
+ run_options:
12
+ <<: *run_options
13
+ run_args:
14
+ <<: *run_args
15
+
16
+ 7:
17
+ base:
18
+ <<: *base
19
+ run_options:
20
+ <<: *run_options
21
+ run_args:
22
+ <<: *run_args
23
+
24
+ 6:
25
+ base:
26
+ <<: *base
27
+ run_options:
28
+ <<: *run_options
29
+ run_args:
30
+ <<: *run_args
31
+
32
+ 5:
33
+ base:
34
+ <<: *base
35
+ run_options:
36
+ <<: *run_options
37
+ run_args:
38
+ <<: *run_args
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpmrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Song Huang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-13 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -39,22 +39,22 @@ files:
39
39
  - Gemfile
40
40
  - Gemfile.lock
41
41
  - LICENSE.txt
42
+ - README.en-US.md
42
43
  - README.md
43
- - README.zh-CN.md
44
44
  - Rakefile
45
45
  - bin/dpm
46
+ - config/package.yml
46
47
  - dpm.gemspec
47
48
  - lib/dpm.rb
48
49
  - lib/dpm/errors.rb
50
+ - lib/dpm/options.rb
49
51
  - lib/dpm/runner.rb
50
52
  - lib/dpm/version.rb
51
- - packages/default.yml
52
- - packages/elasticsearch/default.yml
53
- - packages/mysql/default.yml
54
- - packages/mysql/tag-5.7.yml
55
- - packages/nginx/default.yml
56
- - packages/redis/default.yml
57
- - sig/dpm.rbs
53
+ - packages/elasticsearch.yml
54
+ - packages/mysql.yml
55
+ - packages/nginx.yml
56
+ - packages/postgres.yml
57
+ - packages/redis.yml
58
58
  homepage: https://github.com/songhuangcn/dpm
59
59
  licenses:
60
60
  - MIT
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubygems_version: 3.3.20
80
- signing_key:
80
+ signing_key:
81
81
  specification_version: 4
82
82
  summary: Docker Package Manager.
83
83
  test_files: []
data/README.zh-CN.md DELETED
@@ -1,103 +0,0 @@
1
- [English](README.md) | [简体中文](README.zh-CN.md)
2
-
3
- # DPM
4
-
5
- Docker Package Manager, 让你的容器用起来跟包管理器(`apt`, `yml`, `brew`)一样简单。
6
-
7
- ## 安装
8
-
9
- ```bash
10
- gem install dpmrb
11
- ```
12
-
13
- ## 使用
14
-
15
- ```bash
16
- dpm help # Show help
17
- dpm list # docker ps --filter "name=dpm-"
18
- dpm start mysql # docker run --name=dpm-mysql -d --rm -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes ...
19
- dpm stop mysql # docker stop dpm-mysql
20
- dpm status mysql # docker ps --filter "name=dpm-mysql"
21
- dpm start elasticsearch:7.10.2 # docker run --name=dpm-elasticsearch-7.10.2 -d --rm -p 9200:9200 -e discovery.type=single-node ...
22
- dpm start mysql:5.7 # docker run --name=dpm-mysql-5.7 -d --rm -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes ...
23
- ```
24
-
25
- ## 为项目添加新包
26
-
27
- DPM 跟 [Homebrew](https://brew.sh/) 一样,需要完善更多的包配置,欢迎为 `packages` 目录添加你需要的包配置。
28
-
29
- ### 配置级别
30
-
31
- 容器配置都是通用的 YAML 格式,有三个级别:
32
-
33
- 1. 默认级别:`packages/default.yml`
34
- 1. 包级别:`packages/PACKAGE/default.yml`
35
- 1. 版本级别:`packages/PACKAGE/tag-TAG.yml`
36
-
37
- 配置是合并机制,如果一个包没有自定义配置,他就会根据默认级别配置跑起来。
38
-
39
- ### 配置示例
40
-
41
- 例如有配置如下:
42
-
43
- 1. `packages/default.yml`:
44
- ```yml
45
- run_options:
46
- rm: true
47
- d: true
48
- ```
49
- 1. `packages/mysql/default.yml`:
50
- ```yml
51
- run_options:
52
- e: "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
53
- p: "3306:3306"
54
- ```
55
- 1. `packages/mysql/tag-5.7.yml`:
56
- ```yml
57
- run_options:
58
- p: "3307:3307"
59
- ```
60
-
61
- 则最终这些包配置的启动命令为:
62
-
63
- - `mysql:5.7` 的配置:
64
- ```bash
65
- docker run --rm -d -p 3307:3307 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql:5.7
66
- ```
67
- - `mysql` 的配置:
68
- ```bash
69
- docker run --rm -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes mysql
70
- ```
71
- - `not-exist-pkg` 的配置:
72
- ```bash
73
- docker run --rm -d not-exist-pkg
74
- ```
75
-
76
- ### 其他配置
77
-
78
- 有一些其他配置项,例如 `image`:
79
-
80
- `packages/elasticsearch/default.yml`
81
- ```yml
82
- image: "docker.elastic.co/elasticsearch/elasticsearch"
83
- ```
84
-
85
- 则 `elasticsearch` 包的镜像将不在按约定自动计算,而是变成了:
86
-
87
- ```bash
88
- docker.elastic.co/elasticsearch/elasticsearch
89
- ```
90
-
91
- 还有一些配置,例如:`args`,这个是传入到容器的参数,例如有配置文件 `packages/mysql/default.yml`:
92
-
93
- ```yml
94
- args:
95
- character-set-server: "utf8mb4"
96
- collation-server: "utf8mb4_unicode_ci"
97
- ```
98
-
99
- 则所有版本的 `mysql` 包将会多这两个启动参数:
100
-
101
- ```bash
102
- docker run mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
103
- ```
@@ -1,7 +0,0 @@
1
- image_name: "docker.elastic.co/elasticsearch/elasticsearch"
2
- run_options:
3
- p:
4
- - "9200:9200"
5
- - "9300:9300"
6
- e: "discovery.type=single-node"
7
- v: "<%= DPM::HOME %>/data/<%= package_name %>/<%= package_tag || 'default' %>:/usr/share/elasticsearch/data"
@@ -1,7 +0,0 @@
1
- run_options:
2
- p: "3306:3306"
3
- e: "MYSQL_ALLOW_EMPTY_PASSWORD=yes"
4
- v: "<%= DPM::HOME %>/data/<%= package_name %>/<%= package_tag || 'default' %>:/var/lib/mysql"
5
- args:
6
- character-set-server: "utf8mb4"
7
- collation-server: "utf8mb4_unicode_ci"
@@ -1,2 +0,0 @@
1
- run_options:
2
- v: "<%= DPM::HOME %>/data/mysql-5.7:/var/lib/mysql"
@@ -1,2 +0,0 @@
1
- run_options:
2
- p: "80:80"
@@ -1,2 +0,0 @@
1
- run_options:
2
- p: "6379:6379"
data/sig/dpm.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Dpm
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end