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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.en-US.md +52 -17
- data/README.md +41 -69
- data/bin/dpm +1 -0
- data/config/config.template.yml +30 -0
- data/dpm.gemspec +1 -1
- data/lib/dpm/options.rb +6 -7
- data/lib/dpm/runner.rb +28 -4
- data/lib/dpm/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7071062b1142b4ccb9003d85dba16f38167dcb8e1338a39f0d815c6177750bf6
|
4
|
+
data.tar.gz: 286ac526db640e294e52a35f0939e2840ac8dd124979187e343d9f5c1a0f1c6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1afcdbab71d64680d3e350999585526dab02ce1fa5dcfc36f5083f88c92780148c50aa8e7ac393cb62f519f4ccf05d37bfde6cec75ea76ca22ee02f797a1533
|
7
|
+
data.tar.gz: eb3fcc41aa0cf974809a916a7f5c3d0d11f91342476276a92fc92e0ad895e94e519476d54528c16d05e1b202852c8dfd11b513f937c070a0e3d0210345878087
|
data/Gemfile.lock
CHANGED
data/README.en-US.md
CHANGED
@@ -2,10 +2,15 @@
|
|
2
2
|
|
3
3
|
# DPM
|
4
4
|
|
5
|
-
Docker Package Manager, makes using your
|
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
|
17
|
-
dpm
|
18
|
-
dpm
|
19
|
-
dpm
|
20
|
-
dpm
|
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
|
-
##
|
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
|
-
|
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
|
-
|
40
|
+
### User Package Config
|
30
41
|
|
31
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
73
|
+
### Development Skills
|
40
74
|
|
41
|
-
|
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,
|
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
|
17
|
-
dpm
|
18
|
-
dpm
|
19
|
-
dpm
|
20
|
-
dpm
|
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
|
-
|
34
|
+
### 系统包配置
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
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
|
-
|
60
|
+
- [Visual Studio Code 插件](https://marketplace.visualstudio.com/items?itemName=UoooBarry.dpm-vscode)
|
79
61
|
|
80
|
-
|
81
|
-
```yml
|
82
|
-
image: "docker.elastic.co/elasticsearch/elasticsearch"
|
83
|
-
```
|
62
|
+
## 开发调试
|
84
63
|
|
85
|
-
|
64
|
+
### 搭建环境
|
86
65
|
|
87
66
|
```bash
|
88
|
-
|
67
|
+
git clone git@github.com:songhuangcn/dpm.git
|
68
|
+
cd dpm
|
69
|
+
bin/setup # 需要 Ruby >= 2.6
|
89
70
|
```
|
90
71
|
|
91
|
-
|
72
|
+
### 开发技巧
|
92
73
|
|
93
|
-
|
94
|
-
|
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
@@ -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`, `
|
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 "
|
26
|
+
parser.separator "Options:"
|
27
27
|
|
28
|
-
parser.on("-d", "--dry-run", "Don't actually run
|
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(
|
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(
|
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
|
-
|
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
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.
|
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-
|
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
|
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: []
|