docker-runner 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c922e4be88775142c1940bf163272b4323abb756
4
- data.tar.gz: a18982c3960b9466baa51df30b6555e9ae3fa433
3
+ metadata.gz: d9ba1c187306ebe03331ed95d0b46aa17d46054d
4
+ data.tar.gz: 4c0011e49704208b423735b85eaeedbe6451bdf5
5
5
  SHA512:
6
- metadata.gz: f92c3643aeece1712cc6eba42e37cead1c749ecfb773e86704a6ea66293e7142c655a6244d3e7134936134136aae95742fe8fef42d8dba81a57676d12c431cba
7
- data.tar.gz: 0a6488b68daa8eb3ec4a1288e36a405ff81aea296c84a518c54bdafd42c3f808a9ddf2303ff362a1b67555e1c9f297deaa409c5cd633ce11ebe135b0fbe36c8b
6
+ metadata.gz: c815fb8d8d3190bc764d80410387c779532520982018f0f70b97fc5dc1c9c30e419d57f53b7c07450a8479da9145c9e1b40d8e80b8ee489bcb02be9100d5d3dd
7
+ data.tar.gz: 551667a63fb0aea99c70fc55f95846cb2c49a93164b802b4d6cbc384fb0cac662181c506bfa5c8742c6330db325bbb7ca2315cbcbdc5a3b0da45eeb720f91e7c
data/README.md CHANGED
@@ -9,16 +9,23 @@ A Rails Like Docker Runner Cli
9
9
 
10
10
  ## Commands List
11
11
 
12
- 1. [docker-runner setup](#commands-list)
13
- 2. [docker-runner new [project]](#commands-list)
14
- 3. [docker-runner config](#commands-list)
15
- 4. [docker-runner build](#commands-list)
16
- 5. [docker-runner push](#commands-list)
17
- 6. [docker-runner login](#commands-list)
18
- 7. [docker-runner logout](#commands-list)
19
- 8. [docker-runner console](#commands-list)
20
- 9. [docker-runner update](#commands-list)
21
- 10. [docker-runner version](#commands-list)
12
+ ~~~
13
+ $ docker-runner
14
+ Usage:
15
+ - docker-runner new [project_name] 新建一个镜像
16
+ - docker-runner setup 执行环境初始化
17
+ - docker-runner reset 重置执行环境
18
+ - docker-runner config 查看当前执行环境
19
+ - docker-runner build 构建镜像
20
+ - docker-runner push 推送镜像到远程仓库
21
+ - docker-runner login 登录镜像远程仓库
22
+ - docker-runner logout 退出镜像远程仓库
23
+ - docker-runner console 开启镜像控制台
24
+ - docker-runner update 更新镜像模板
25
+ - docker-runner version 查看当前版本
26
+
27
+ docker-runner v0.1.0 (c) 2016 @caishuo
28
+ ~~~
22
29
 
23
30
  ## 使用说明
24
31
 
data/bin/docker-runner CHANGED
@@ -5,8 +5,8 @@ require 'docker/runner'
5
5
  bin_dir = File.expand_path(File.dirname(__FILE__))
6
6
  shell_script_path = File.join(bin_dir, 'include', 'docker-runner.sh')
7
7
 
8
- if ARGV[0] == 'version'
8
+ if ARGV[0] == 'version' or ARGV[0] == '-v'
9
9
  puts Docker::Runner::ABOUT
10
10
  else
11
- puts `#{shell_script_path} #{ARGV * ' '}`
11
+ `VERSION='#{Docker::Runner::ABOUT}' #{shell_script_path} #{ARGV * ' '} >&2`
12
12
  end
@@ -9,6 +9,9 @@ case "$1" in
9
9
  setup)
10
10
  do_setup
11
11
  ;;
12
+ reset)
13
+ do_reset
14
+ ;;
12
15
  config)
13
16
  do_config
14
17
  ;;
@@ -27,14 +30,34 @@ case "$1" in
27
30
  do_logout
28
31
  ;;
29
32
  console)
30
- docker_opts=${@%shell}
33
+ docker_opts=${@%console}
31
34
  do_console
32
35
  ;;
36
+ clean)
37
+ do_clean
38
+ ;;
33
39
  update)
34
40
  do_update
35
41
  ;;
36
42
  *)
37
- echo "Usage: $NAME {new|setup|config|build|push|login|logout|console|update|version}" >&2
43
+ echo -e "\
44
+ Usage:\n\
45
+ - docker-runner new [project_name] 新建一个镜像\n\
46
+ - docker-runner setup 执行环境初始化\n\
47
+ - docker-runner reset 重置执行环境\n\
48
+ - docker-runner config 查看当前执行环境\n\
49
+ - docker-runner build 构建镜像\n\
50
+ - docker-runner push 推送镜像到远程仓库\n\
51
+ - docker-runner login 登录镜像远程仓库\n\
52
+ - docker-runner logout 退出镜像远程仓库\n\
53
+ - docker-runner console 开启镜像控制台\n\
54
+ - docker-runner clean Docker环境清理\n\
55
+ - docker-runner update 更新镜像模板\n\
56
+ - docker-runner version 查看当前版本\n\
57
+ " >&2
58
+ if [ '$VERSION' != '' ]; then
59
+ echo $VERSION >&2
60
+ fi
38
61
  exit 3
39
62
  ;;
40
63
  esac
@@ -70,31 +70,45 @@ print_env() {
70
70
  }
71
71
 
72
72
  print_global_env() {
73
- if [ -r "$HOME/.docker-runner" ]; then
73
+ if require_global_env; then
74
74
  echo "全局变量:"
75
75
  cat $HOME/.docker-runner
76
- else
77
- echo "找不到全局 ~/.docker-runner 文件, 请执行 docker-runner init"
78
76
  fi
79
77
  }
80
78
 
81
79
  print_project_env() {
82
- if [ -r ".docker-runner" ]; then
80
+ if require_project_env; then
83
81
  echo "项目变量:"
84
82
  cat .docker-runner
85
- else
86
- echo "当前目录找不到 .docker-runner 文件"
87
83
  fi
88
84
  }
89
85
 
90
86
  # 重置全局变量
91
- rest_global_env() {
87
+ reset_global_env() {
92
88
  ask_global_env
93
89
  set_default_global_env
94
90
  save_global_env
95
91
  print_global_env
96
92
  }
97
93
 
94
+ require_global_env() {
95
+ if [ -r "$HOME/.docker-runner" ]; then
96
+ return 1
97
+ else
98
+ echo "**请先执行docker-runner setup, 进行环境初始化"
99
+ exit 11
100
+ fi
101
+ }
102
+
103
+ require_project_env() {
104
+ if require_global_env && [ -r ".docker-runner" ]; then
105
+ return 1
106
+ else
107
+ echo "**当前目录不是镜像项目, 请切换至镜像项目"
108
+ exit 12
109
+ fi
110
+ }
111
+
98
112
  #------------------------------------------------------------------------------
99
113
  # 2. 环境变量默认值处理:
100
114
  #------------------------------------------------------------------------------
@@ -275,6 +289,11 @@ valid_variables() {
275
289
  }
276
290
 
277
291
  set_image_name() {
292
+ if ! require_project_env; then
293
+ echo '**当前目录不是镜像项目, 请切换至镜像项目'
294
+ exit 3
295
+ fi
296
+
278
297
  if [ $username = $OFFICIAL_USER ]; then
279
298
  img="$docker_host/$image:${version:-latest}"
280
299
  else
@@ -283,7 +302,7 @@ set_image_name() {
283
302
  }
284
303
 
285
304
  build_image() {
286
- set_image_name
305
+ set_image_name && \
287
306
  (docker build $docker_opts -t $img .) && \
288
307
  echo $img was built successfully
289
308
  }
@@ -299,6 +318,7 @@ push_image() {
299
318
  #------------------------------------------------------------------------------
300
319
 
301
320
  docker_login() {
321
+ echo "正在登录$docker_host:"
302
322
  read -p "用户名($(default_username)): " username
303
323
  echo "docker login -u ${username:=$(default_username)} -e $email $docker_host"
304
324
  docker login -u ${username:=$(default_username)} -e $email $docker_host
@@ -309,10 +329,16 @@ docker_logout() {
309
329
  }
310
330
 
311
331
  docker_console() {
312
- set_image_name
332
+ set_image_name && \
313
333
  docker run -i -t --rm --name ${NAME:-tmp} $docker_opts $img /bin/sh
314
334
  }
315
335
 
336
+ docker_clean() {
337
+ echo '[开始清理container]' && docker rm `docker ps -a | grep Exited | awk '{print $1 }'`
338
+ echo '[开始清理image]' && docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
339
+ echo '[开始清理volume]' && docker volume rm $(docker volume ls -qf dangling=true)
340
+ }
341
+
316
342
  #------------------------------------------------------------------------------
317
343
  # Public API
318
344
  #------------------------------------------------------------------------------
@@ -329,11 +355,24 @@ do_new_project() {
329
355
  }
330
356
 
331
357
  do_setup() {
332
- rest_global_env
333
- echo ''
358
+ reset_global_env
334
359
  do_login
335
360
  }
336
361
 
362
+ do_reset() {
363
+ echo "该操作将删除已有配置"
364
+ read -p "确认是否进行: (Y/n) " is_reset_env
365
+ if ([ "$is_reset_env" = '' ] || [ "$is_reset_env" = 'Y' ] || [ "$is_reset_env" = 'y' ]); then
366
+ rm -f "$HOME/.docker-runner"
367
+ unset gitlab_token
368
+ echo "清理成功, 开始重置..."
369
+ do_setup
370
+ echo "重置成功"
371
+ else
372
+ echo 停止执行环境重置
373
+ fi
374
+ }
375
+
337
376
  do_config() {
338
377
  print_env
339
378
  }
@@ -360,6 +399,10 @@ do_console() {
360
399
  docker_console
361
400
  }
362
401
 
402
+ do_clean() {
403
+ docker_clean
404
+ }
405
+
363
406
  do_update() {
364
407
  update_template
365
408
  }
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = ['docker-runner']
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.post_install_message = "\033[41;37m [Important] run \`docker-runner setup\`, before using \033[0m "
23
+ # spec.post_install_message = `docker-runner`
24
+
22
25
  spec.add_dependency 'gitlab'
23
26
 
24
27
  spec.add_development_dependency "bundler", "~> 1.11"
data/lib/docker/runner.rb CHANGED
@@ -2,7 +2,7 @@ require 'docker/runner/version'
2
2
 
3
3
  module Docker
4
4
  module Runner
5
- ABOUT = "docker-runner v#{VERSION} (c) 2016 @caishuo.com".freeze
5
+ ABOUT = "docker-runner v#{VERSION} (c) 2016 @caishuo".freeze
6
6
  PROCLINE = "docker-runner v#{VERSION}".freeze
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Docker
2
2
  module Runner
3
- VERSION = "0.1.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "王长明"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -76,7 +76,8 @@ homepage: https://gitlab.caishuo.com/docker/docker-runner
76
76
  licenses:
77
77
  - MIT
78
78
  metadata: {}
79
- post_install_message:
79
+ post_install_message: "\e[41;37m [Important] run `docker-runner setup`, before using
80
+ \e[0m "
80
81
  rdoc_options: []
81
82
  require_paths:
82
83
  - lib