dpmrb 0.2.0 → 0.2.3

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: d315bd0172c0bbcc72a159b18170c25fa032a652eec376f47f28aa06323d8ec8
4
+ data.tar.gz: fc768c6e80c8f45909b838a6a59c05bffe3682efdf3cb81f782a7c72065ed696
5
5
  SHA512:
6
- metadata.gz: ab4c5ef506c195e0bf11c52620a12c10d6ec2bfa07d2dd8c3307f2431b11f013c7a752eef9cb17d4c289242fa7c9d66a31d140c4f9c9ee73580fd1830a6f8b7c
7
- data.tar.gz: a25e3e9b13ff5a5bd36a64a92d146a728373593c907f989b279bbcf4bd1b2b7838b55af029672bae8048b9819bcd2fb4d8d36d4a1042c639e517057cf77cff12
6
+ metadata.gz: a758ce7ea8ebc362853c7ad2e7289d7debd7bf9174a0a11527260bda87e8faae74329db05032a4555b5b98e75a1e515bf5d90283aa3f0a8d4e7c7118bd58a78f
7
+ data.tar.gz: d283ba5ad26596745bf42c7f50bbab781e7785ea27549967da1126629613c15318488f9ad0b32381987fa51a0cb1857a3933a88cb00def388406bb6021bc0ab3
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.3)
5
5
  activesupport (~> 6.x)
6
6
 
7
7
  GEM
data/README.en-US.md ADDED
@@ -0,0 +1,76 @@
1
+ [简体中文](README.md) | [English](README.en-US.md)
2
+
3
+ # DPM
4
+
5
+ Docker Package Manager, makes using your Docker as easy as package managers (`apt`, `yum`, `brew`).
6
+
7
+ ## Installation
8
+
9
+ Dependency:
10
+ - Docker
11
+ - Ruby >= 2.6
12
+
13
+ Install command:
14
+ ```bash
15
+ gem install dpmrb
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ dpm pacakges # List all supported packages
22
+ dpm start mysql # Start the package `mysql` by the config `packages/mysql.yml`
23
+ dpm stop mysql # Stop the package `mysql`
24
+ dpm status mysql # Show the status of the package `mysql`
25
+ dpm help # Get help to show all the features
26
+ ```
27
+
28
+ ## Package Config
29
+
30
+ DPM supports two types of package configs:
31
+ 1. The "System Package Config" in the directory `packages/` of repo
32
+ 2. The "User Package Config" in the directory `~/.dpm/packages/` of user
33
+
34
+ ### System Package Config
35
+
36
+ The goal of "System Package Config" is to make a Docker service run the same as the natively installed one. Take MySQL as an example:
37
+ - After the native MySQL is installed and run, it will bind port 3306 by default, so our MySQL package configuration should also expose the service port to the host by default
38
+ - After the native MySQL is installed, there are fixed configuration directories and log directories, so our MySQL package configuration must also map these directories in the container to fixed directories
39
+
40
+ ### User Package Config
41
+
42
+ "User Package Config" has the following usage scenarios:
43
+ 1. If the default package configuration of DPM is unreasonable and you want to change it, you can use "User Package Config" to debug and view the results, and then submit MR to the repo.
44
+ 2. DPM does not provide the package you need, you need to add your own package configuration. (Contributions of your new package configuration to DPM are welcome).
45
+ 3. DPM default package configuration is not suitable for local environment, need to override "System Package Config". For example, if I need to run two MySQL services locally, then I need to change the port of one of the services to the other to avoid conflicts.
46
+
47
+ #### Add User Package Config
48
+
49
+ "User Package Config" provides the following commands for quick creation:
50
+ ```bash
51
+ dpm configure PACKAGE
52
+ ```
53
+
54
+ The function of this command is to add a new package configuration file `PACKAGE.yml` under the user directory `~/.dpm/`.
55
+ If the package already exists in the "system package configuration", the contents will be initialized into this file.
56
+
57
+ **Note:** If the PACKAGE parameter is `package`, the "Global Package Config" `config/package.yml` is configured, and the configuration here will be merged into all packages.
58
+
59
+ ## Development
60
+
61
+ ### Setup environment
62
+
63
+ ```bash
64
+ git clone git@github.com:songhuangcn/dpm.git
65
+ cd dpm
66
+ bin/setup # Need Ruby >= 2.6
67
+ ```
68
+
69
+ ### Development Skills
70
+
71
+ - Adding ENV `DEBUG` to all commands will show detailed error stack to help locate the problem
72
+ - After development, use the command `bin/check` to check code specifications and tests, and resolve some CI failures in advance
73
+
74
+ ## Recommended tools
75
+
76
+ - [Visual Studio Code Plugin](https://github.com/UoooBarry/vscode-dpm)
data/README.md CHANGED
@@ -1,41 +1,75 @@
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, 让你的 Docker 用起来跟包管理器(`apt`, `yum`, `brew`)一样简单。
6
6
 
7
- ## Installation
7
+ ## 安装
8
8
 
9
+ 依赖:
10
+ - Docker
11
+ - Ruby >= 2.6
12
+
13
+ 安装命令:
9
14
  ```bash
10
15
  gem install dpmrb
11
16
  ```
12
17
 
13
- ## Usage
18
+ ## 使用
14
19
 
15
20
  ```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 ...
21
+ dpm pacakges # 列出所有支持的包
22
+ dpm start mysql # 通过配置 `packages/mysql.yml` 运行 `mysql` 包
23
+ dpm stop mysql # 停止运行 `mysql`
24
+ dpm status mysql # 展示 `mysql` 包的运行状态
25
+ dpm help # 展示帮助,查看所有功能
23
26
  ```
24
27
 
25
- ## Development
28
+ ## 包配置
29
+
30
+ DPM 支持两种包配置:
31
+ 1. 项目 repo 目录 `packages/` 的 "系统包配置"
32
+ 1. 用户目录 `~/.dpm/packages` 的 "用户包配置"
33
+
34
+ ### 系统包配置
35
+
36
+ "系统包配置" 目标是让一个 Docker 服务跑起来跟原生安装的软件一致,拿 MySQL 来举例:
37
+ - 原生软件 MySQL 安装好运行后,会默认绑定好 3306 端口,那我们的 MySQL 包配置就要做到默认也暴露该服务端口到主机
38
+ - 原生软件 MySQL 安装好后,有固定的配置目录和日志目录,那我们的 MySQL 包配置就要做到也将容器里的这些目录映射到固定的目录
26
39
 
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.
40
+ ### 用户包配置
28
41
 
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).
42
+ "用户包配置" 有以下使用场景:
43
+ 1. DPM 默认包配置不合理想更改,可以先用 "用户包配置" 调试查看结果,然后给 repo 提 MR。
44
+ 2. DPM 没有提供你需要的包,需要添加自己包配置。(欢迎给 DPM 贡献你的新包配置)。
45
+ 3. DPM 默认包配置不适合本地环境,需要覆盖 "系统包配置"。比如我本地需要跑两个 MySQL 服务,那我就需要把其中一个服务的端口改成其他避免冲突。
30
46
 
31
- ## Contributing
47
+ #### 添加用户包配置
48
+
49
+ "用户包配置" 提供了以下命令快速创建:
50
+ ```bash
51
+ dpm configure PACKAGE
52
+ ```
32
53
 
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).
54
+ 该命令功能就是在用户目录 `~/.dpm/` 下添加一个新的包配置文件 `PACKAGE.yml`。如果该包在 "系统包配置" 已经存在,则会将内容初始化到该文件里。
55
+
56
+ **注意:** 如果 PACKAGE 参数为 `package`,则配置的是 "全局系统包配置" `config/package.yml`,这里的配置会合并到所有包里。
57
+
58
+ ## 开发
59
+
60
+ ### 搭建环境
61
+
62
+ ```bash
63
+ git clone git@github.com:songhuangcn/dpm.git
64
+ cd dpm
65
+ bin/setup # 需要 Ruby >= 2.6
66
+ ```
34
67
 
35
- ## License
68
+ ### 开发技巧
36
69
 
37
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
70
+ - 给所有命令添加 ENV `DEBUG` 会展示详细错误堆栈,帮助定位问题
71
+ - 开发完后,请使用命令 `bin/check` 检查代码规范和测试,提前解决一些 CI 失败的情况
38
72
 
39
- ## Code of Conduct
73
+ ## 推荐工具
40
74
 
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).
75
+ - [Visual Studio Code 插件](https://github.com/UoooBarry/vscode-dpm)
data/bin/dpm CHANGED
@@ -3,8 +3,9 @@
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
+ raise if ENV["DEBUG"]
9
+ puts "Fatal error: #{exception.message}"
9
10
  exit 1
10
11
  end
@@ -0,0 +1,30 @@
1
+ # .base: &base
2
+ # {} # Base config, like: `image_name`, `tag_name`
3
+ # .run_options: &run_options
4
+ # {} # Docker run options, like: `p`, `publish`, `v`, `volume`
5
+ # .run_args: &run_args
6
+ # {} #Docker run args, like: `character-set-server`
7
+ #
8
+ # latest:
9
+ # base:
10
+ # <<: *base
11
+ # run_options:
12
+ # <<: *run_options
13
+ # run_args:
14
+ # <<: *run_args
15
+ #
16
+ # tag1:
17
+ # base:
18
+ # <<: *base
19
+ # run_options:
20
+ # <<: *run_options
21
+ # run_args:
22
+ # <<: *run_args
23
+ #
24
+ # tag2:
25
+ # base:
26
+ # <<: *base
27
+ # run_options:
28
+ # <<: *run_options
29
+ # run_args:
30
+ # <<: *run_args
@@ -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
+ {}
data/dpm.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["songhuangcn@gmail.com"]
10
10
 
11
11
  spec.summary = "Docker Package Manager."
12
- spec.description = "Makes using your containers as easy as package managers (`apt`, `yml`, `brew`)."
12
+ spec.description = "Docker Package Manager. Makes using your containers as easy as package managers (`apt`, `yum`, `brew`)."
13
13
  spec.homepage = "https://github.com/songhuangcn/dpm"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.6.0"
@@ -0,0 +1,91 @@
1
+ require "optparse"
2
+
3
+ module DPM
4
+ class Options
5
+ PACKAGE_COMMANDS = %w[tags status start stop restart configure].freeze
6
+ PACKAGE_REGEX = /\A[\w.\-:]+\z/.freeze
7
+ UNPACKAGE_COMMANDS = %w[list packages cleanup].freeze
8
+
9
+ attr_accessor :argv, :dry_run, :raw, :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 "Options:"
27
+
28
+ parser.on("-d", "--dry-run", "Don't actually run Docker command, just print") do |v|
29
+ self.dry_run = v
30
+ end
31
+
32
+ parser.on("-r", "--raw", "Try to run a package even if it doesn't exist") do |v|
33
+ self.raw = v
34
+ end
35
+
36
+ parser.on_tail("-h", "--help", "Show the help") do
37
+ puts help_text
38
+ exit
39
+ end
40
+
41
+ parser.on_tail("-v", "--version", "Show the version") do
42
+ puts VERSION
43
+ exit
44
+ end
45
+
46
+ parser.parse!(argv)
47
+ end
48
+
49
+ process_args!
50
+ self
51
+ end
52
+
53
+ def help_text
54
+ <<~EOF
55
+ #{parser}
56
+ COMMAND:
57
+ help Show the help
58
+ version Show the version
59
+ packages List supported packages
60
+ list List running packages
61
+ cleanup Cleanup useless data
62
+ tags PACKAGE List supported tags of a package
63
+ status PACKAGE Get the status of a package
64
+ start PACKAGE Start a package
65
+ stop PACKAGE Stop a package
66
+ restart PACKAGE Restart a package
67
+ configure PACKAGE Configure a package in the user-level, including configure a new package
68
+
69
+ See more at https://github.com/songhuangcn/dpm
70
+ EOF
71
+ end
72
+
73
+ def process_args!
74
+ self.command, self.package = argv
75
+
76
+ case command
77
+ when "help"
78
+ puts help_text
79
+ exit
80
+ when "version"
81
+ puts VERSION
82
+ exit
83
+ when *PACKAGE_COMMANDS
84
+ raise Error, "Command `#{command}` need a package" if package.blank?
85
+ raise Error, "Package invalid, valid regex: #{PACKAGE_REGEX}" if !PACKAGE_REGEX.match?(package)
86
+ else
87
+ raise Error, "Unknown command `#{command}`, see `dpm help`" unless UNPACKAGE_COMMANDS.include?(command)
88
+ end
89
+ end
90
+ end
91
+ end
data/lib/dpm/runner.rb CHANGED
@@ -5,81 +5,93 @@ 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 cleanup].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!
31
+ when "configure"
32
+ call_configure!
32
33
  end
33
34
  end
34
35
 
35
36
  private
36
37
 
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
38
+ def call_docker!
39
+ docker_command = case options.command
49
40
  when "list"
50
41
  %(docker ps --filter "name=#{CONTAINER_NAME_PREFIX}")
51
42
  when "status"
52
- %(docker ps --filter "name=#{container_name}")
43
+ %(docker ps --filter "name=^/#{container_name}$")
53
44
  when "start"
54
45
  "docker run #{docker_run_params}"
55
46
  when "stop"
56
47
  "docker stop #{container_name}"
57
48
  when "restart"
58
- "dpm stop #{package} && dpm start #{package}"
49
+ "dpm stop #{options.package} && dpm start #{options.package}"
50
+ when "cleanup"
51
+ "docker system prune --force"
52
+ else
53
+ raise "Not implemented command: `#{command}`"
54
+ end
55
+ if options.dry_run
56
+ puts "Dry run:"
57
+ puts bash_color(docker_command)
58
+ else
59
+ puts bash_color(docker_command)
60
+ puts ""
61
+ puts `#{docker_command}`
59
62
  end
60
63
  end
61
64
 
62
- def help_text
63
- <<~EOF
64
- Usage: dpm command [PACKAGE]
65
+ def call_packages!
66
+ packages = Dir.glob(File.join(ROOT, "packages", "*.yml")).map { |file| File.basename(file, ".yml") }
67
+ puts packages
68
+ end
65
69
 
66
- Docker Package Manager
70
+ def call_tags!
71
+ tags = package_config_yaml.keys.reject { |key| key.start_with?(".") }
72
+ puts tags
73
+ end
67
74
 
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
75
+ def call_configure!
76
+ raise Error, "Need set $EDITOR" unless ENV["EDITOR"]
80
77
 
81
- See more at https://github.com/songhuangcn/dpm
82
- EOF
78
+ config_dir = package_name == "package" ? "config" : "packages"
79
+ user_config = File.join(HOME, config_dir, "#{package_name}.yml")
80
+ unless File.exist?(user_config)
81
+ system_config = File.join(ROOT, config_dir, "#{package_name}.yml")
82
+ init_data = if File.exist?(system_config)
83
+ File.read(system_config)
84
+ else
85
+ File.read(File.join(ROOT, "config", "config.template.yml"))
86
+ end
87
+ File.write(user_config, init_data)
88
+ end
89
+
90
+ `#{ENV["EDITOR"]} #{user_config}`
91
+ end
92
+
93
+ def bash_color(text)
94
+ "#{BASH_COLOR_GRAY}#{text}#{BASH_COLOR_NONE}"
83
95
  end
84
96
 
85
97
  def docker_run_params
@@ -87,15 +99,15 @@ module DPM
87
99
  end
88
100
 
89
101
  def config_run_options
90
- process_options(manager_config["run_options"])
102
+ process_options(package_config["run_options"])
91
103
  end
92
104
 
93
105
  def config_command
94
- manager_config["command"]
106
+ package_config["base"]["command"]
95
107
  end
96
108
 
97
109
  def config_args
98
- process_options(manager_config["args"])
110
+ process_options(package_config["run_args"])
99
111
  end
100
112
 
101
113
  def process_options(hash)
@@ -123,49 +135,65 @@ module DPM
123
135
  end
124
136
 
125
137
  def docker_image
126
- image_tag ? "#{image_name}:#{image_tag}" : image_name
138
+ "#{image_name}:#{image_tag}"
127
139
  end
128
140
 
129
141
  def image_name
130
- @image_name ||= manager_config["image_name"] || package_name
142
+ @image_name ||= package_config["image_name"] || package_name
131
143
  end
132
144
 
133
145
  def image_tag
134
- @image_tag ||= manager_config["image_tag"] || package_tag
146
+ @image_tag ||= package_config["image_tag"] || package_tag
135
147
  end
136
148
 
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"))
149
+ def package_config
150
+ @package_config ||= begin
151
+ version = package_tag.dup
152
+ version_config = loop do
153
+ if !version
154
+ break {} if options.raw
155
+ raise Error, "Package tag `#{package_tag}` not support"
156
+ end
142
157
 
143
- default_options \
144
- .deep_merge(image_options) \
145
- .deep_merge(tag_options)
158
+ break package_config_yaml[version] if package_config_yaml[version]
159
+ version = version.sub!(/\.\d+\z/, "")
160
+ end
161
+ default_config.deep_merge(version_config)
146
162
  end
147
163
  end
148
164
 
165
+ def package_config_yaml
166
+ @package_config_yaml ||= load_yaml(File.join("packages", "#{package_name}.yml"))
167
+ rescue Errno::ENOENT
168
+ return {} if options.raw
169
+ raise Error, "Package `#{package_name}` not support"
170
+ end
171
+
172
+ def default_config
173
+ @default_config ||= load_yaml(File.join("config", "package.yml"))
174
+ end
175
+
149
176
  def package_name
150
- @package_name ||= package.split(":")[0]
177
+ @package_name ||= options.package.split(":")[0]
151
178
  end
152
179
 
153
180
  def package_tag
154
- @package_tag ||= package.split(":")[1]
181
+ @package_tag ||= options.package.split(":")[1] || "latest"
155
182
  end
156
183
 
157
184
  def container_name
158
- @container_name ||= "#{CONTAINER_NAME_PREFIX}#{package.tr(":", "-")}"
185
+ @container_name ||= "#{CONTAINER_NAME_PREFIX}#{options.package.tr(":", "-")}"
159
186
  end
160
187
 
161
188
  def load_yaml(file_path)
162
- text = File.read(file_path)
189
+ user_path = File.join(HOME, file_path)
190
+ system_path = File.join(ROOT, file_path)
191
+ text = File.exist?(user_path) ? File.read(user_path) : File.read(system_path)
163
192
  data = ERB.new(text).result(binding)
164
- YAML.safe_load(data).tap do |yaml|
193
+ yaml = YAML.safe_load(data, aliases: true).tap do |yaml|
165
194
  raise Error, "Config need to be a hash yaml: #{file_path}" unless yaml.is_a?(Hash)
166
195
  end
167
- rescue Errno::ENOENT
168
- {}
196
+ yaml.transform_keys!(&:to_s)
169
197
  end
170
198
  end
171
199
  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.3"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Song Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-13 00:00:00.000000000 Z
11
+ date: 2022-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 6.x
27
- description: Makes using your containers as easy as package managers (`apt`, `yml`,
28
- `brew`).
27
+ description: Docker Package Manager. Makes using your containers as easy as package
28
+ managers (`apt`, `yum`, `brew`).
29
29
  email:
30
30
  - songhuangcn@gmail.com
31
31
  executables:
@@ -39,22 +39,23 @@ 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/config.template.yml
47
+ - config/package.yml
46
48
  - dpm.gemspec
47
49
  - lib/dpm.rb
48
50
  - lib/dpm/errors.rb
51
+ - lib/dpm/options.rb
49
52
  - lib/dpm/runner.rb
50
53
  - 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
54
+ - packages/elasticsearch.yml
55
+ - packages/mysql.yml
56
+ - packages/nginx.yml
57
+ - packages/postgres.yml
58
+ - packages/redis.yml
58
59
  homepage: https://github.com/songhuangcn/dpm
59
60
  licenses:
60
61
  - MIT
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