dockerun 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -11
- data/Rakefile +0 -2
- data/Rakefile.bak +8 -0
- data/dockerspec.sample +104 -0
- data/{dockerun.gemspec → dockerun.gemspec.bak} +20 -22
- data/exe/dockerun +8 -115
- data/lib/dockerun/cli/command.rb +133 -0
- data/lib/dockerun/cli/command_factory.rb +313 -0
- data/lib/dockerun/cli/command_result.rb +67 -0
- data/lib/dockerun/cli/delete_container.rb +55 -0
- data/lib/dockerun/cli/delete_image.rb +99 -0
- data/lib/dockerun/cli/run.rb +39 -0
- data/lib/dockerun/cli/user_info.rb +39 -0
- data/lib/dockerun/cli_engine.rb +104 -0
- data/lib/dockerun/config.rb +39 -86
- data/lib/dockerun/context/rubygems.rb +142 -0
- data/lib/dockerun/dfile.rb +204 -0
- data/lib/dockerun/docker_cli.rb +124 -0
- data/lib/dockerun/dsl.rb +291 -0
- data/lib/dockerun/version.rb +1 -1
- data/lib/dockerun.rb +31 -24
- data/sig/dockerun.rbs +4 -0
- metadata +62 -73
- data/.release_history.yml +0 -56
- data/Dockerfile.dockerun +0 -38
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -94
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/dockerun/bundler_helper.rb +0 -25
- data/lib/dockerun/cli_prompt.rb +0 -18
- data/lib/dockerun/command/dockerun.rb +0 -30
- data/lib/dockerun/command/init.rb +0 -79
- data/lib/dockerun/command/remove_container.rb +0 -99
- data/lib/dockerun/command/reset_image.rb +0 -107
- data/lib/dockerun/command/run.rb +0 -226
- data/lib/dockerun/command/run_new_container.rb +0 -94
- data/lib/dockerun/command/run_new_image.rb +0 -89
- data/lib/dockerun/command/stop_container.rb +0 -90
- data/lib/dockerun/docker_command_factory_helper.rb +0 -19
- data/lib/dockerun/docker_container_helper.rb +0 -213
- data/lib/dockerun/docker_image_helper.rb +0 -381
- data/lib/dockerun/template/general_template_writer.rb +0 -14
- data/lib/dockerun/template/jruby_template_writer.rb +0 -24
- data/lib/dockerun/template/template_engine.rb +0 -27
- data/lib/dockerun/template/template_writer.rb +0 -102
- data/lib/dockerun/user_info.rb +0 -37
- data/template/Dockerfile_general.erb +0 -41
- data/template/setup_ruby_devenv.rb.erb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0a6fc97935e5777962a76188ad3a39923ce84b9363c494c7a59c37d6888baff
|
4
|
+
data.tar.gz: db4d15767b81528d7d0c208bb8d7924e5e11d84aed610e0ccf037cfb39f2c6b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6166715ddc5e72fa1f319563ef03a3472ce561e2e72000c73336196a06a59a08b2e6c7fb37fb9567bb58a374dc72ea8f16c49816b4040dfb148c2b924c47393e
|
7
|
+
data.tar.gz: 01df6c0dfa95436c1439f6870bdba7cc942f600c44e75ff16b63682a10cd7cd081ff399b603f0cb163fc31ff95c90e4fd95139bc47babb6498eb08b6ffdb58a2
|
data/README.md
CHANGED
@@ -1,24 +1,20 @@
|
|
1
1
|
# Dockerun
|
2
2
|
|
3
|
-
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
4
|
|
5
|
-
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dockerun`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'dockerun'
|
13
|
-
```
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
14
10
|
|
15
|
-
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
16
12
|
|
17
|
-
$ bundle
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
14
|
|
19
|
-
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
20
16
|
|
21
|
-
$ gem install
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
22
18
|
|
23
19
|
## Usage
|
24
20
|
|
data/Rakefile
CHANGED
data/Rakefile.bak
ADDED
data/dockerspec.sample
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Here is the sample that stipulate fields that can be set
|
4
|
+
#
|
5
|
+
# Config section is shared across by Dockerfile and docker cli
|
6
|
+
config do
|
7
|
+
# this et the workdir inside the docker
|
8
|
+
# - Used by Dockerfile to set the default dir upon startup
|
9
|
+
# - Optionally used by docker cli to mount the development gem
|
10
|
+
# directory into the parent of the workdir
|
11
|
+
# Default to "/opt" if not given
|
12
|
+
#set_workdir "/opt/dockerun"
|
13
|
+
|
14
|
+
# determine apt-get or dnf or other
|
15
|
+
set_platform :debian
|
16
|
+
|
17
|
+
# Create user and group same as local user and group
|
18
|
+
# so the files created on mounted volume is same level
|
19
|
+
# as current running user
|
20
|
+
set_current_user
|
21
|
+
|
22
|
+
# Additional context for dockerun to consider
|
23
|
+
# Here is set to Rubygems context
|
24
|
+
# For example can bundle link the development gems
|
25
|
+
# into docker without user configuration, all from
|
26
|
+
# Gemfile of the Rubygems project
|
27
|
+
#activate_context :rubygems do
|
28
|
+
# duplicate_dev_env
|
29
|
+
# keep_gen_file
|
30
|
+
#end
|
31
|
+
|
32
|
+
# trigger dry run whereby:
|
33
|
+
# 1. Dockerfile shall be generated
|
34
|
+
# 2. All docker command shall be printed out
|
35
|
+
# Docker image is not built and container is not created
|
36
|
+
#dry_run
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# This section is for Dockerfile entry
|
42
|
+
# and also during docker build operation
|
43
|
+
from "ruby:3.2.1" do
|
44
|
+
|
45
|
+
# keep the generated dockerfile
|
46
|
+
# Default is true. Can disable by :
|
47
|
+
# keep_dockerfile false
|
48
|
+
keep_dockerfile
|
49
|
+
|
50
|
+
# Docker image name
|
51
|
+
# Shall be used during building of docker image
|
52
|
+
# Shall be referred for operations such as if
|
53
|
+
# image already exist
|
54
|
+
# If not given shall default to dir_name+"_docker_image"
|
55
|
+
#set_image_name "dockerun-image"
|
56
|
+
|
57
|
+
# apt-get update && apt-get -y upgrade is on by default
|
58
|
+
# Can ask to skip update and upgrade by follwing:
|
59
|
+
#skip_update
|
60
|
+
#skip_upgrade
|
61
|
+
|
62
|
+
# List of software to install on the image
|
63
|
+
install "git", "curl"
|
64
|
+
|
65
|
+
# Transfer the workdir from config into Dockerfile
|
66
|
+
set_workdir
|
67
|
+
|
68
|
+
# set CMD of the Dockerfile
|
69
|
+
set_command "/bin/bash"
|
70
|
+
end
|
71
|
+
|
72
|
+
# section here shall generate docker command line:
|
73
|
+
# docker run -it ... ...
|
74
|
+
up do
|
75
|
+
|
76
|
+
# Container name to be refer later
|
77
|
+
# If not given shall be default to dir_name+"_cont_name"
|
78
|
+
#set_container_name "dockerun-container"
|
79
|
+
|
80
|
+
# keep the generated container so can be reuse
|
81
|
+
# next time
|
82
|
+
# Can be disable by : keep false
|
83
|
+
keep
|
84
|
+
|
85
|
+
# Interactive session for the container
|
86
|
+
# Can be disable by : interactive false
|
87
|
+
interactive
|
88
|
+
|
89
|
+
#mount "/opt/smtg" => "/opt/smtg"
|
90
|
+
# Mount directory into the docker container
|
91
|
+
mount current_dir: workdir
|
92
|
+
|
93
|
+
# Command to be run in docker
|
94
|
+
#run_in_docker "/bin/bash"
|
95
|
+
|
96
|
+
# Map port of docker to host
|
97
|
+
#port 3080 => 3000
|
98
|
+
end
|
99
|
+
|
100
|
+
# Entry point to ask the engine start operation
|
101
|
+
# No needed for scripted operation
|
102
|
+
#go
|
103
|
+
|
104
|
+
|
@@ -3,15 +3,15 @@
|
|
3
3
|
require_relative "lib/dockerun/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "dockerun"
|
7
|
+
spec.version = Dockerun::VERSION
|
8
|
+
spec.authors = ["Chris"]
|
9
|
+
spec.email = ["chris@antrapol.com"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.required_ruby_version = ">= 2.
|
11
|
+
spec.summary = ""
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
15
|
|
16
16
|
#spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
17
|
|
@@ -21,30 +21,28 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
25
|
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
(f == __FILE__) ||
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
27
28
|
end
|
28
29
|
end
|
29
|
-
spec.bindir
|
30
|
-
spec.executables
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
32
|
spec.require_paths = ["lib"]
|
32
33
|
|
33
|
-
spec.add_dependency
|
34
|
-
spec.add_dependency
|
34
|
+
spec.add_dependency "teLogger", "~> 0.2"
|
35
|
+
#spec.add_dependency "toolrack"
|
35
36
|
|
36
|
-
spec.add_dependency 'tty-
|
37
|
-
spec.add_dependency 'tty-
|
37
|
+
spec.add_dependency 'tty-prompt'
|
38
|
+
spec.add_dependency 'tty-command'
|
39
|
+
spec.add_dependency 'tty-which'
|
40
|
+
spec.add_dependency 'pastel'
|
38
41
|
spec.add_dependency 'colorize'
|
39
42
|
|
40
|
-
spec.add_dependency 'docker-cli', ">= 0.3.1"
|
41
|
-
|
42
|
-
spec.add_development_dependency 'devops_assist'
|
43
|
-
|
44
43
|
# Uncomment to register a new dependency of your gem
|
45
44
|
# spec.add_dependency "example-gem", "~> 1.0"
|
46
45
|
|
47
|
-
# For more information and examples about making a new gem,
|
46
|
+
# For more information and examples about making a new gem, check out our
|
48
47
|
# guide at: https://bundler.io/guides/creating_gem.html
|
49
|
-
spec.add_development_dependency 'release-gem'
|
50
48
|
end
|
data/exe/dockerun
CHANGED
@@ -1,121 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
#require 'bundler/setup'
|
4
|
-
require 'toolrack'
|
5
|
-
include TR::CondUtils
|
6
|
-
|
7
|
-
require 'tty/prompt'
|
8
3
|
require_relative '../lib/dockerun'
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
cmd = Dockerun::Command::Dockerun.new
|
18
|
-
res = cmd.parse(ARGV).params.to_h
|
19
|
-
case res[:command].downcase
|
20
|
-
when "init"
|
21
|
-
initCmd = Dockerun::Command::Init.new
|
22
|
-
argv = ARGV[1..-1]
|
23
|
-
begin
|
24
|
-
res2 = initCmd.parse(argv).run do |ops, val|
|
25
|
-
case ops
|
26
|
-
when :multiple_templates_detected
|
27
|
-
pmt.select("There are multiple templates available. Please select one of the template : ") do |m|
|
28
|
-
val.each do |v|
|
29
|
-
m.choice v, v
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
when :prompt_user_configurables
|
34
|
-
pmt.say "\n The following are the configurable items for the template '#{val[:template]}' : \n", color: :yellow
|
35
|
-
res = { }
|
36
|
-
val[:userFields].each do |k,v|
|
37
|
-
res[k] = pmt.ask("#{k.to_s.capitalize} : ") do |s|
|
38
|
-
s.required v[:required] if not_empty?(v[:required]) and is_bool?(v[:required])
|
39
|
-
s.value v[:default].to_s if not_empty?(v[:default])
|
40
|
-
end
|
41
|
-
end
|
42
|
-
res
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
STDOUT.puts "\nDockerfile written to '#{res2}'\n\n"
|
47
|
-
rescue TTY::Reader::InputInterrupt
|
48
|
-
pmt.say "\n\n Aborted\n", color: :yellow
|
49
|
-
end
|
50
|
-
|
51
|
-
when "run", "r"
|
52
|
-
|
53
|
-
begin
|
54
|
-
runCmd = Dockerun::Command::Run.new
|
55
|
-
argv = ARGV[1..-1]
|
56
|
-
runCmd.parse(argv).run
|
57
|
-
rescue TTY::Reader::InputInterrupt
|
58
|
-
pmt.say "\n\n Aborted\n", color: :yellow
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
when "run-new-container", "rnc"
|
63
|
-
|
64
|
-
begin
|
65
|
-
runCmd = Dockerun::Command::RunNewContainer.new
|
66
|
-
argv = ARGV[1..-1]
|
67
|
-
runCmd.parse(argv).run
|
68
|
-
rescue TTY::Reader::InputInterrupt
|
69
|
-
pmt.say "\n\n Aborted\n", color: :yellow
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
when "run-new-image", "rni"
|
74
|
-
|
75
|
-
begin
|
76
|
-
runCmd = Dockerun::Command::RunNewImage.new
|
77
|
-
argv = ARGV[1..-1]
|
78
|
-
runCmd.parse(argv).run
|
79
|
-
rescue TTY::Reader::InputInterrupt
|
80
|
-
pmt.say "\n\n Aborted\n", color: :yellow
|
81
|
-
end
|
82
|
-
|
83
|
-
when "stop", "s"
|
84
|
-
|
85
|
-
begin
|
86
|
-
runCmd = Dockerun::Command::StopContainer.new
|
87
|
-
argv = ARGV[1..-1]
|
88
|
-
runCmd.parse(argv).run
|
89
|
-
rescue TTY::Reader::InputInterrupt
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
when "rmi", "remove-image"
|
96
|
-
begin
|
97
|
-
riCmd = Dockerun::Command::ResetImage.new
|
98
|
-
argv = ARGV[1..-1]
|
99
|
-
riCmd.parse(argv).run
|
100
|
-
rescue TTY::Reader::InputInterrupt
|
101
|
-
pmt.say "\n\n Aborted\n", color: :yellow
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
when "remove-container","rmc"
|
106
|
-
# remove container
|
107
|
-
begin
|
108
|
-
riCmd = Dockerun::Command::RemoveContainer.new
|
109
|
-
argv = ARGV[1..-1]
|
110
|
-
riCmd.parse(argv).run
|
111
|
-
rescue TTY::Reader::InputInterrupt
|
112
|
-
pmt.say "\n\n Aborted\n", color: :yellow
|
113
|
-
end
|
114
|
-
|
5
|
+
# Operations
|
6
|
+
# 1. [i]nit - Copy sample spec into project dir
|
7
|
+
# 2. [r]un - Run the spec (default without params)
|
8
|
+
# 3. [d]elete [c]ontainer - Delete container (using image name inside spec)
|
9
|
+
# 4. [d]elete [i]mage - Delete image (Using container name inside spec)
|
10
|
+
# 5. reset - Delete container and image
|
115
11
|
|
116
|
-
|
117
|
-
|
118
|
-
STDOUT.puts cmd.help
|
119
|
-
end
|
120
|
-
end
|
12
|
+
cli = Dockerun::CliEngine.new
|
13
|
+
cli.parse_argv(ARGV)
|
121
14
|
|
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
require 'tty/command'
|
3
|
+
require 'tty/prompt'
|
4
|
+
require 'tty/which'
|
5
|
+
|
6
|
+
require 'toolrack'
|
7
|
+
|
8
|
+
require_relative 'command_result'
|
9
|
+
|
10
|
+
module Dockerun
|
11
|
+
module Cli
|
12
|
+
class Command
|
13
|
+
include TR::CondUtils
|
14
|
+
|
15
|
+
class CommandError < StandardError; end
|
16
|
+
|
17
|
+
attr_accessor :command_buffer
|
18
|
+
def initialize(cmd, required_interaction = false)
|
19
|
+
|
20
|
+
cmdOut = ENV["DOCKERUN_COMMAND_OUT"]
|
21
|
+
if not_empty?(cmdOut)
|
22
|
+
@runner = TTY::Command.new(printer: cmdOut.to_sym)
|
23
|
+
else
|
24
|
+
@runner = TTY::Command.new(printer: :null)
|
25
|
+
end
|
26
|
+
|
27
|
+
#@runner = TTY::Command.new
|
28
|
+
@command_buffer = cmd
|
29
|
+
@required_interaction = required_interaction
|
30
|
+
@required_interaction = false if not_bool?(@required_interaction)
|
31
|
+
end
|
32
|
+
|
33
|
+
def interactive_session?
|
34
|
+
@required_interaction
|
35
|
+
end
|
36
|
+
|
37
|
+
def run(&block)
|
38
|
+
|
39
|
+
if interactive_session?
|
40
|
+
|
41
|
+
pmt = TTY::Prompt.new
|
42
|
+
terminal = pmt.select " Command is an interactive command. New terminal session is required. Please select one of the session below to proceed:" do |m|
|
43
|
+
detect_terminal.each do |t|
|
44
|
+
m.choice t, t
|
45
|
+
end
|
46
|
+
|
47
|
+
m.choice "Quit", :quit
|
48
|
+
end
|
49
|
+
|
50
|
+
if terminal != :quit
|
51
|
+
case terminal
|
52
|
+
when "terminator"
|
53
|
+
`#{terminal} -e "#{@command_buffer.join(" ")}; bash"`
|
54
|
+
when "gnome-terminal"
|
55
|
+
`#{terminal} -- bash -c "#{@command_buffer.join(" ")}; exec bash"`
|
56
|
+
when "konsole"
|
57
|
+
`#{terminal} --hold -e "#{@command_buffer.join(" ")}" &`
|
58
|
+
when "iTerm2"
|
59
|
+
`osascript -e \
|
60
|
+
'tell application "iTerm"
|
61
|
+
activate
|
62
|
+
|
63
|
+
create window with default profile
|
64
|
+
delay 0.5
|
65
|
+
|
66
|
+
set currentWindow to current window
|
67
|
+
|
68
|
+
tell current session of currentWindow
|
69
|
+
write text "#{@command_buffer.join(" ")}"
|
70
|
+
end tell
|
71
|
+
|
72
|
+
end tell'
|
73
|
+
`
|
74
|
+
when "Terminal"
|
75
|
+
`osascript -e \
|
76
|
+
'tell application "Terminal"
|
77
|
+
activate
|
78
|
+
do script "#{@command_buffer.join(" ")}"
|
79
|
+
end tell'
|
80
|
+
`
|
81
|
+
else
|
82
|
+
raise Error, "Unfinished supporting terminal : #{terminal}"
|
83
|
+
end
|
84
|
+
|
85
|
+
pmt.puts "\n Prompt running inside the Docker shall be opened in a new window\n\n"
|
86
|
+
end
|
87
|
+
|
88
|
+
else
|
89
|
+
@outStream = []
|
90
|
+
@errStream = []
|
91
|
+
result = @runner.run!(@command_buffer.join(" ")) do |out, err|
|
92
|
+
if block
|
93
|
+
block.call(:outstream, out)
|
94
|
+
block.call(:errstream, err)
|
95
|
+
else
|
96
|
+
@outStream << out if not_empty?(out)
|
97
|
+
@errStream << err if not_empty?(err)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
CommandResult.new(result, @outStream, @errStream)
|
102
|
+
#{ outStream: @outStream, errStream: @errStream, result: @result }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_string
|
107
|
+
@command_buffer
|
108
|
+
end
|
109
|
+
def to_s
|
110
|
+
to_string.join(" ")
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
def detect_terminal
|
115
|
+
avail = []
|
116
|
+
if TR::RTUtils.on_linux?
|
117
|
+
#possible = [ "gnome-terminal","konsole","tilix", "terminator" ]
|
118
|
+
possible = [ "gnome-terminal", "terminator" ]
|
119
|
+
possible.each do |app|
|
120
|
+
avail << app if not TTY::Which.which(app).nil?
|
121
|
+
end
|
122
|
+
elsif TR::RTUtils.on_windows?
|
123
|
+
avail << "cmd.exe"
|
124
|
+
elsif TR::RTUtils.on_mac?
|
125
|
+
avail << "Terminal"
|
126
|
+
avail << "iTerm2"
|
127
|
+
end
|
128
|
+
avail
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|