dpmrb 0.1.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 +76 -0
- data/README.md +54 -20
- data/bin/dpm +3 -2
- data/config/config.template.yml +30 -0
- data/{packages/default.yml → config/package.yml} +4 -3
- data/dpm.gemspec +1 -1
- data/lib/dpm/options.rb +87 -0
- data/lib/dpm/runner.rb +98 -70
- data/lib/dpm/version.rb +1 -1
- data/lib/dpm.rb +8 -0
- data/packages/elasticsearch.yml +35 -0
- data/packages/mysql.yml +35 -0
- data/packages/nginx.yml +22 -0
- data/packages/postgres.yml +56 -0
- data/packages/redis.yml +38 -0
- metadata +13 -12
- data/README.zh-CN.md +0 -103
- data/packages/elasticsearch/default.yml +0 -5
- data/packages/mysql/default.yml +0 -7
- data/packages/mysql/tag-5.7.yml +0 -2
- data/packages/nginx/default.yml +0 -2
- data/packages/redis/default.yml +0 -2
- data/sig/dpm.rbs +0 -4
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
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
|
+
## 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
|
+
```
|
72
|
+
|
73
|
+
### Development Skills
|
74
|
+
|
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
@@ -1,41 +1,75 @@
|
|
1
|
-
[
|
1
|
+
[简体中文](README.md) | [English](README.en-US.md)
|
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
|
```
|
12
17
|
|
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
|
-
##
|
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
|
-
|
40
|
+
### 用户包配置
|
28
41
|
|
29
|
-
|
42
|
+
"用户包配置" 有以下使用场景:
|
43
|
+
1. DPM 默认包配置不合理想更改,可以先用 "用户包配置" 调试查看结果,然后给 repo 提 MR。
|
44
|
+
2. DPM 没有提供你需要的包,需要添加自己包配置。(欢迎给 DPM 贡献你的新包配置)。
|
45
|
+
3. DPM 默认包配置不适合本地环境,需要覆盖 "系统包配置"。比如我本地需要跑两个 MySQL 服务,那我就需要把其中一个服务的端口改成其他避免冲突。
|
30
46
|
|
31
|
-
|
47
|
+
#### 添加用户包配置
|
48
|
+
|
49
|
+
"用户包配置" 提供了以下命令快速创建:
|
50
|
+
```bash
|
51
|
+
dpm configure PACKAGE
|
52
|
+
```
|
32
53
|
|
33
|
-
|
54
|
+
该命令功能就是在用户目录 `~/.dpm/` 下添加一个新的包配置文件 `PACKAGE.yml`。如果该包在 "系统包配置" 已经存在,则会将内容初始化到该文件里。
|
34
55
|
|
35
|
-
|
56
|
+
**注意:** 如果 PACKAGE 参数为 `package`,则配置的是 "全局系统包配置" `config/package.yml`,这里的配置会合并到所有包里。
|
36
57
|
|
37
|
-
|
58
|
+
## 相关工具
|
59
|
+
|
60
|
+
- [Visual Studio Code 插件](https://marketplace.visualstudio.com/items?itemName=UoooBarry.dpm-vscode)
|
61
|
+
|
62
|
+
## 开发调试
|
63
|
+
|
64
|
+
### 搭建环境
|
65
|
+
|
66
|
+
```bash
|
67
|
+
git clone git@github.com:songhuangcn/dpm.git
|
68
|
+
cd dpm
|
69
|
+
bin/setup # 需要 Ruby >= 2.6
|
70
|
+
```
|
38
71
|
|
39
|
-
|
72
|
+
### 开发技巧
|
40
73
|
|
41
|
-
|
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
ADDED
@@ -0,0 +1,87 @@
|
|
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, :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_tail("-h", "--help", "Show the help") do
|
33
|
+
puts help_text
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
|
37
|
+
parser.on_tail("-v", "--version", "Show the version") do
|
38
|
+
puts VERSION
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
parser.parse!(argv)
|
43
|
+
end
|
44
|
+
|
45
|
+
process_args!
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def help_text
|
50
|
+
<<~EOF
|
51
|
+
#{parser}
|
52
|
+
COMMAND:
|
53
|
+
help Show the help
|
54
|
+
version Show the version
|
55
|
+
packages List supported packages
|
56
|
+
list List running packages
|
57
|
+
cleanup Cleanup useless data
|
58
|
+
tags PACKAGE List supported tags of a package
|
59
|
+
status PACKAGE Get the status of a package
|
60
|
+
start PACKAGE Start a package
|
61
|
+
stop PACKAGE Stop a package
|
62
|
+
restart PACKAGE Restart a package
|
63
|
+
configure PACKAGE Configure a package in the user-level, including configure a new package
|
64
|
+
|
65
|
+
See more at https://github.com/songhuangcn/dpm
|
66
|
+
EOF
|
67
|
+
end
|
68
|
+
|
69
|
+
def process_args!
|
70
|
+
self.command, self.package = argv
|
71
|
+
|
72
|
+
case command
|
73
|
+
when "help"
|
74
|
+
puts help_text
|
75
|
+
exit
|
76
|
+
when "version"
|
77
|
+
puts VERSION
|
78
|
+
exit
|
79
|
+
when *PACKAGE_COMMANDS
|
80
|
+
raise Error, "Command `#{command}` need a package" if package.blank?
|
81
|
+
raise Error, "Package invalid, valid regex: #{PACKAGE_REGEX}" if !PACKAGE_REGEX.match?(package)
|
82
|
+
else
|
83
|
+
raise Error, "Unknown command `#{command}`, see `dpm help`" unless UNPACKAGE_COMMANDS.include?(command)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
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
|
-
|
13
|
+
attr_accessor :options
|
15
14
|
|
16
|
-
def self.call!(
|
17
|
-
new(
|
15
|
+
def self.call!(options)
|
16
|
+
new(options).call!
|
18
17
|
end
|
19
18
|
|
20
|
-
def initialize(
|
21
|
-
|
22
|
-
validate_argv!
|
19
|
+
def initialize(options)
|
20
|
+
self.options = options
|
23
21
|
end
|
24
22
|
|
25
23
|
def call!
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
38
|
-
|
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
|
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}`"
|
59
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}`
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def call_packages!
|
66
|
+
packages = Dir.glob(File.join(ROOT, "packages", "*.yml")).map { |file| File.basename(file, ".yml") }
|
67
|
+
puts packages
|
68
|
+
end
|
69
|
+
|
70
|
+
def call_tags!
|
71
|
+
tags = package_config_yaml.keys.reject { |key| key.start_with?(".") }
|
72
|
+
puts tags
|
60
73
|
end
|
61
74
|
|
62
|
-
def
|
63
|
-
|
64
|
-
Usage: dpm command [PACKAGE]
|
75
|
+
def call_configure!
|
76
|
+
raise Error, "Need set $EDITOR" unless ENV["EDITOR"]
|
65
77
|
|
66
|
-
|
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
|
67
89
|
|
68
|
-
|
69
|
-
|
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
|
90
|
+
`#{ENV["EDITOR"]} #{user_config}`
|
91
|
+
end
|
80
92
|
|
81
|
-
|
82
|
-
|
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(
|
102
|
+
process_options(package_config["run_options"])
|
91
103
|
end
|
92
104
|
|
93
105
|
def config_command
|
94
|
-
|
106
|
+
package_config["base"]["command"]
|
95
107
|
end
|
96
108
|
|
97
109
|
def config_args
|
98
|
-
process_options(
|
110
|
+
process_options(package_config["run_args"])
|
99
111
|
end
|
100
112
|
|
101
113
|
def process_options(hash)
|
@@ -110,57 +122,73 @@ module DPM
|
|
110
122
|
option_prefix = "--"
|
111
123
|
value_joiner = "="
|
112
124
|
end
|
113
|
-
full_value = "#{value_joiner}#{value}" if value != true
|
114
125
|
|
115
|
-
|
126
|
+
if value == true
|
127
|
+
"#{option_prefix}#{key}"
|
128
|
+
elsif value.is_a?(Array)
|
129
|
+
value.map { |v| "#{option_prefix}#{key}#{value_joiner}#{v}" }.join(" ")
|
130
|
+
else
|
131
|
+
"#{option_prefix}#{key}#{value_joiner}#{value}"
|
132
|
+
end
|
116
133
|
end
|
117
134
|
hash_arr.join(" ")
|
118
135
|
end
|
119
136
|
|
120
137
|
def docker_image
|
121
|
-
|
138
|
+
"#{image_name}:#{image_tag}"
|
122
139
|
end
|
123
140
|
|
124
141
|
def image_name
|
125
|
-
@image_name ||=
|
142
|
+
@image_name ||= package_config["image_name"] || package_name
|
126
143
|
end
|
127
144
|
|
128
145
|
def image_tag
|
129
|
-
@image_tag ||=
|
146
|
+
@image_tag ||= package_config["image_tag"] || package_tag
|
130
147
|
end
|
131
148
|
|
132
|
-
def
|
133
|
-
@
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
149
|
+
def package_config
|
150
|
+
@package_config ||= begin
|
151
|
+
version = package_tag.dup
|
152
|
+
version_config = loop do
|
153
|
+
raise Error, "Package tag `#{package_tag}` not support" unless version
|
154
|
+
break package_config_yaml[version] if package_config_yaml[version]
|
155
|
+
version = version.sub!(/\.\d+\z/, "")
|
156
|
+
end
|
157
|
+
default_config.deep_merge(version_config)
|
141
158
|
end
|
142
159
|
end
|
143
160
|
|
161
|
+
def package_config_yaml
|
162
|
+
@package_config_yaml ||= load_yaml(File.join("packages", "#{package_name}.yml"))
|
163
|
+
rescue Errno::ENOENT
|
164
|
+
raise Error, "Package `#{package_name}` not support"
|
165
|
+
end
|
166
|
+
|
167
|
+
def default_config
|
168
|
+
@default_config ||= load_yaml(File.join("config", "package.yml"))
|
169
|
+
end
|
170
|
+
|
144
171
|
def package_name
|
145
|
-
@package_name ||= package.split(":")[0]
|
172
|
+
@package_name ||= options.package.split(":")[0]
|
146
173
|
end
|
147
174
|
|
148
175
|
def package_tag
|
149
|
-
@package_tag ||= package.split(":")[1]
|
176
|
+
@package_tag ||= options.package.split(":")[1] || "latest"
|
150
177
|
end
|
151
178
|
|
152
179
|
def container_name
|
153
|
-
@container_name ||= "#{CONTAINER_NAME_PREFIX}#{package.tr(":", "-")}"
|
180
|
+
@container_name ||= "#{CONTAINER_NAME_PREFIX}#{options.package.tr(":", "-")}"
|
154
181
|
end
|
155
182
|
|
156
183
|
def load_yaml(file_path)
|
157
|
-
|
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)
|
158
187
|
data = ERB.new(text).result(binding)
|
159
|
-
YAML.safe_load(data).tap do |yaml|
|
188
|
+
yaml = YAML.safe_load(data, aliases: true).tap do |yaml|
|
160
189
|
raise Error, "Config need to be a hash yaml: #{file_path}" unless yaml.is_a?(Hash)
|
161
190
|
end
|
162
|
-
|
163
|
-
{}
|
191
|
+
yaml.transform_keys!(&:to_s)
|
164
192
|
end
|
165
193
|
end
|
166
194
|
end
|
data/lib/dpm/version.rb
CHANGED
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
|
data/packages/mysql.yml
ADDED
@@ -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
|
data/packages/nginx.yml
ADDED
@@ -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
|
data/packages/redis.yml
ADDED
@@ -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.
|
4
|
+
version: 0.2.2
|
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-
|
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:
|
@@ -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/
|
52
|
-
- packages/
|
53
|
-
- packages/
|
54
|
-
- packages/
|
55
|
-
- packages/
|
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
|
-
```
|
data/packages/mysql/default.yml
DELETED
data/packages/mysql/tag-5.7.yml
DELETED
data/packages/nginx/default.yml
DELETED
data/packages/redis/default.yml
DELETED
data/sig/dpm.rbs
DELETED