dpmrb 0.2.1 → 0.2.2

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: d408ee6f24c0e503159587c35ef634821cba4143ee0a4bde49c0497636cde125
4
- data.tar.gz: 1de01b1572bcc96575e7f2716ac78fefc5e38f87da9ed59e25a8d27117861e79
3
+ metadata.gz: 7071062b1142b4ccb9003d85dba16f38167dcb8e1338a39f0d815c6177750bf6
4
+ data.tar.gz: 286ac526db640e294e52a35f0939e2840ac8dd124979187e343d9f5c1a0f1c6b
5
5
  SHA512:
6
- metadata.gz: 14f44aa24ca13e24032199766ddfc0ee90e25e8ffd873cba6d53ecffbc751def9a01cedd4c9e52457b64a44ccff48d65da6e30e20d9cbd3e1d23595708a760ed
7
- data.tar.gz: 0cf758ea38f95aea2cd0ce13d3ca300f0936d5c751b1fc957b993395d3f020ecef5850f78ad39c9135f587dd88b03b993cfe612f2819a3e700ebc5703702e0bf
6
+ metadata.gz: d1afcdbab71d64680d3e350999585526dab02ce1fa5dcfc36f5083f88c92780148c50aa8e7ac393cb62f519f4ccf05d37bfde6cec75ea76ca22ee02f797a1533
7
+ data.tar.gz: eb3fcc41aa0cf974809a916a7f5c3d0d11f91342476276a92fc92e0ad895e94e519476d54528c16d05e1b202852c8dfd11b513f937c070a0e3d0210345878087
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dpmrb (0.2.1)
4
+ dpmrb (0.2.2)
5
5
  activesupport (~> 6.x)
6
6
 
7
7
  GEM
data/README.en-US.md CHANGED
@@ -2,10 +2,15 @@
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, makes using your Docker as easy as package managers (`apt`, `yum`, `brew`).
6
6
 
7
7
  ## Installation
8
8
 
9
+ Dependency:
10
+ - Docker
11
+ - Ruby >= 2.6
12
+
13
+ Install command:
9
14
  ```bash
10
15
  gem install dpmrb
11
16
  ```
@@ -13,29 +18,59 @@ gem install dpmrb
13
18
  ## Usage
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 # 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
23
26
  ```
24
27
 
25
- ## Development
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
26
35
 
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.
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
28
39
 
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).
40
+ ### User Package Config
30
41
 
31
- ## Contributing
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
+ ```
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
+ 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.
34
56
 
35
- ## License
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.
36
58
 
37
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
+ ## Related Tools
60
+
61
+ - [Visual Studio Code Plugin](https://marketplace.visualstudio.com/items?itemName=UoooBarry.dpm-vscode)
62
+
63
+ ## Development
64
+
65
+ ### Setup environment
66
+
67
+ ```bash
68
+ git clone git@github.com:songhuangcn/dpm.git
69
+ cd dpm
70
+ bin/setup # Need Ruby >= 2.6
71
+ ```
38
72
 
39
- ## Code of Conduct
73
+ ### Development Skills
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
+ - Adding ENV `DEBUG` to all commands will show detailed error stack to help locate the problem
76
+ - After development, use the command `bin/check` to check code specifications and tests, and resolve some CI failures in advance
data/README.md CHANGED
@@ -2,10 +2,15 @@
2
2
 
3
3
  # DPM
4
4
 
5
- Docker Package Manager, 让你的容器用起来跟包管理器(`apt`, `yml`, `brew`)一样简单。
5
+ Docker Package Manager, 让你的 Docker 用起来跟包管理器(`apt`, `yum`, `brew`)一样简单。
6
6
 
7
7
  ## 安装
8
8
 
9
+ 依赖:
10
+ - Docker
11
+ - Ruby >= 2.6
12
+
13
+ 安装命令:
9
14
  ```bash
10
15
  gem install dpmrb
11
16
  ```
@@ -13,91 +18,58 @@ gem install dpmrb
13
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
- ## 为项目添加新包
26
-
27
- DPM 跟 [Homebrew](https://brew.sh/) 一样,需要完善更多的包配置,欢迎为 `packages` 目录添加你需要的包配置。
28
+ ## 包配置
28
29
 
29
- ### 配置级别
30
+ DPM 支持两种包配置:
31
+ 1. 项目 repo 目录 `packages/` 的 "系统包配置"
32
+ 1. 用户目录 `~/.dpm/packages` 的 "用户包配置"
30
33
 
31
- 容器配置都是通用的 YAML 格式,有三个级别:
34
+ ### 系统包配置
32
35
 
33
- 1. 默认级别:`packages/default.yml`
34
- 1. 包级别:`packages/PACKAGE/default.yml`
35
- 1. 版本级别:`packages/PACKAGE/tag-TAG.yml`
36
+ "系统包配置" 目标是让一个 Docker 服务跑起来跟原生安装的软件一致,拿 MySQL 来举例:
37
+ - 原生软件 MySQL 安装好运行后,会默认绑定好 3306 端口,那我们的 MySQL 包配置就要做到默认也暴露该服务端口到主机
38
+ - 原生软件 MySQL 安装好后,有固定的配置目录和日志目录,那我们的 MySQL 包配置就要做到也将容器里的这些目录映射到固定的目录
36
39
 
37
- 配置是合并机制,如果一个包没有自定义配置,他就会根据默认级别配置跑起来。
40
+ ### 用户包配置
38
41
 
39
- ### 配置示例
42
+ "用户包配置" 有以下使用场景:
43
+ 1. DPM 默认包配置不合理想更改,可以先用 "用户包配置" 调试查看结果,然后给 repo 提 MR。
44
+ 2. DPM 没有提供你需要的包,需要添加自己包配置。(欢迎给 DPM 贡献你的新包配置)。
45
+ 3. DPM 默认包配置不适合本地环境,需要覆盖 "系统包配置"。比如我本地需要跑两个 MySQL 服务,那我就需要把其中一个服务的端口改成其他避免冲突。
40
46
 
41
- 例如有配置如下:
47
+ #### 添加用户包配置
42
48
 
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
- ```
49
+ "用户包配置" 提供了以下命令快速创建:
50
+ ```bash
51
+ dpm configure PACKAGE
52
+ ```
60
53
 
61
- 则最终这些包配置的启动命令为:
54
+ 该命令功能就是在用户目录 `~/.dpm/` 下添加一个新的包配置文件 `PACKAGE.yml`。如果该包在 "系统包配置" 已经存在,则会将内容初始化到该文件里。
62
55
 
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
- ```
56
+ **注意:** 如果 PACKAGE 参数为 `package`,则配置的是 "全局系统包配置" `config/package.yml`,这里的配置会合并到所有包里。
75
57
 
76
- ### 其他配置
58
+ ## 相关工具
77
59
 
78
- 有一些其他配置项,例如 `image`:
60
+ - [Visual Studio Code 插件](https://marketplace.visualstudio.com/items?itemName=UoooBarry.dpm-vscode)
79
61
 
80
- `packages/elasticsearch/default.yml`
81
- ```yml
82
- image: "docker.elastic.co/elasticsearch/elasticsearch"
83
- ```
62
+ ## 开发调试
84
63
 
85
- `elasticsearch` 包的镜像将不在按约定自动计算,而是变成了:
64
+ ### 搭建环境
86
65
 
87
66
  ```bash
88
- docker.elastic.co/elasticsearch/elasticsearch
67
+ git clone git@github.com:songhuangcn/dpm.git
68
+ cd dpm
69
+ bin/setup # 需要 Ruby >= 2.6
89
70
  ```
90
71
 
91
- 还有一些配置,例如:`args`,这个是传入到容器的参数,例如有配置文件 `packages/mysql/default.yml`:
72
+ ### 开发技巧
92
73
 
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
- ```
74
+ - 给所有命令添加 ENV `DEBUG` 会展示详细错误堆栈,帮助定位问题
75
+ - 开发完后,请使用命令 `bin/check` 检查代码规范和测试,提前解决一些 CI 失败的情况
data/bin/dpm CHANGED
@@ -5,6 +5,7 @@ require_relative "../lib/dpm"
5
5
  begin
6
6
  DPM.call!(ARGV)
7
7
  rescue => exception
8
+ raise if ENV["DEBUG"]
8
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
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"
data/lib/dpm/options.rb CHANGED
@@ -2,9 +2,9 @@ require "optparse"
2
2
 
3
3
  module DPM
4
4
  class Options
5
- PACKAGE_COMMANDS = %w[tags status start stop restart].freeze
5
+ PACKAGE_COMMANDS = %w[tags status start stop restart configure].freeze
6
6
  PACKAGE_REGEX = /\A[\w.\-:]+\z/.freeze
7
- UNPACKAGE_COMMANDS = %w[list packages].freeze
7
+ UNPACKAGE_COMMANDS = %w[list packages cleanup].freeze
8
8
 
9
9
  attr_accessor :argv, :dry_run, :parser, :command, :package
10
10
 
@@ -23,15 +23,12 @@ module DPM
23
23
 
24
24
  parser.banner = "Usage: dpm [options] [COMMAND] [PACKAGE]"
25
25
  parser.separator ""
26
- parser.separator "Specific options:"
26
+ parser.separator "Options:"
27
27
 
28
- parser.on("-d", "--dry-run", "Don't actually run anything, just print") do |v|
28
+ parser.on("-d", "--dry-run", "Don't actually run Docker command, just print") do |v|
29
29
  self.dry_run = v
30
30
  end
31
31
 
32
- parser.separator ""
33
- parser.separator "Common options:"
34
-
35
32
  parser.on_tail("-h", "--help", "Show the help") do
36
33
  puts help_text
37
34
  exit
@@ -57,11 +54,13 @@ module DPM
57
54
  version Show the version
58
55
  packages List supported packages
59
56
  list List running packages
57
+ cleanup Cleanup useless data
60
58
  tags PACKAGE List supported tags of a package
61
59
  status PACKAGE Get the status of a package
62
60
  start PACKAGE Start a package
63
61
  stop PACKAGE Stop a package
64
62
  restart PACKAGE Restart a package
63
+ configure PACKAGE Configure a package in the user-level, including configure a new package
65
64
 
66
65
  See more at https://github.com/songhuangcn/dpm
67
66
  EOF
data/lib/dpm/runner.rb CHANGED
@@ -8,7 +8,7 @@ module DPM
8
8
  CONTAINER_NAME_PREFIX = "dpm-"
9
9
  BASH_COLOR_GRAY = "\033[0;37m"
10
10
  BASH_COLOR_NONE = "\033[0m"
11
- DOCKER_COMMANDS = %w[list status start stop restart].freeze
11
+ DOCKER_COMMANDS = %w[list status start stop restart cleanup].freeze
12
12
 
13
13
  attr_accessor :options
14
14
 
@@ -28,6 +28,8 @@ module DPM
28
28
  call_packages!
29
29
  when "tags"
30
30
  call_tags!
31
+ when "configure"
32
+ call_configure!
31
33
  end
32
34
  end
33
35
 
@@ -45,6 +47,8 @@ module DPM
45
47
  "docker stop #{container_name}"
46
48
  when "restart"
47
49
  "dpm stop #{options.package} && dpm start #{options.package}"
50
+ when "cleanup"
51
+ "docker system prune --force"
48
52
  else
49
53
  raise "Not implemented command: `#{command}`"
50
54
  end
@@ -68,6 +72,24 @@ module DPM
68
72
  puts tags
69
73
  end
70
74
 
75
+ def call_configure!
76
+ raise Error, "Need set $EDITOR" unless ENV["EDITOR"]
77
+
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
+
71
93
  def bash_color(text)
72
94
  "#{BASH_COLOR_GRAY}#{text}#{BASH_COLOR_NONE}"
73
95
  end
@@ -137,13 +159,13 @@ module DPM
137
159
  end
138
160
 
139
161
  def package_config_yaml
140
- @package_config_yaml ||= load_yaml(File.join(ROOT, "packages", "#{package_name}.yml"))
162
+ @package_config_yaml ||= load_yaml(File.join("packages", "#{package_name}.yml"))
141
163
  rescue Errno::ENOENT
142
164
  raise Error, "Package `#{package_name}` not support"
143
165
  end
144
166
 
145
167
  def default_config
146
- @default_config ||= load_yaml(File.join(ROOT, "config", "package.yml"))
168
+ @default_config ||= load_yaml(File.join("config", "package.yml"))
147
169
  end
148
170
 
149
171
  def package_name
@@ -159,7 +181,9 @@ module DPM
159
181
  end
160
182
 
161
183
  def load_yaml(file_path)
162
- text = File.read(file_path)
184
+ user_path = File.join(HOME, file_path)
185
+ system_path = File.join(ROOT, file_path)
186
+ text = File.exist?(user_path) ? File.read(user_path) : File.read(system_path)
163
187
  data = ERB.new(text).result(binding)
164
188
  yaml = YAML.safe_load(data, aliases: true).tap do |yaml|
165
189
  raise Error, "Config need to be a hash yaml: #{file_path}" unless yaml.is_a?(Hash)
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.1"
4
+ VERSION = "0.2.2"
5
5
  end
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.1
4
+ version: 0.2.2
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-18 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:
@@ -43,6 +43,7 @@ files:
43
43
  - README.md
44
44
  - Rakefile
45
45
  - bin/dpm
46
+ - config/config.template.yml
46
47
  - config/package.yml
47
48
  - dpm.gemspec
48
49
  - lib/dpm.rb
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  version: '0'
78
79
  requirements: []
79
80
  rubygems_version: 3.3.20
80
- signing_key:
81
+ signing_key:
81
82
  specification_version: 4
82
83
  summary: Docker Package Manager.
83
84
  test_files: []