dockerun 0.1.18 → 0.2.1

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: 9cbcf4c70d28a02673f788a731f9a7317a5ffc0c538afb361a8390174b015efe
4
- data.tar.gz: d0771b907dda8d1e2a1158829684b15c5bcdb5a4c08332ec24a7111dbabc0c14
3
+ metadata.gz: 7ead5589eb4e3bb3a0fecefc1cccc9205efc2e20a72077c78916ad4b3baf3630
4
+ data.tar.gz: aae134574147ba68372ac437b91d72f4d0588fde4d9cd9018a4958148677b00c
5
5
  SHA512:
6
- metadata.gz: 4f506a0572240746fbfcc3d2946454f534b54c6ab922f21f6cc2c004421a16a60b0adf0b11e38efef22b1f58adf69ea5509de8c0fe7ecb037ccbf6ec48ae5aab
7
- data.tar.gz: 93cac69a37122f6aff3baa234a617036d29b590fe0bc81b8dcf18767c71f35a55eebbf09f8ce0ef6a2e09eadd469d1132dc11bc2b0b8224aca1f45f18ec13ae5
6
+ metadata.gz: a8f1b851ea681c872cd7942896857473e30ea3df971e551afb884380882919f5b374327dc6b358565040baae82f2f8eb185bc2ce34ad1618aa139439febb78d4
7
+ data.tar.gz: 6932af98445ab8e388be8a0f7a0479cc15b88cf23196f5a3080822d5490899f8966bab4751b114b673d43d6767c8c9c18dace517616c89892dc7c6e0582c7012
data/.release_history.yml CHANGED
@@ -36,3 +36,7 @@ dockerun:
36
36
  :timestamp: 1680096788.8148112
37
37
  - :version: 0.1.17
38
38
  :timestamp: 1680413747.3876462
39
+ - :version: 0.1.18
40
+ :timestamp: 1680413850.243007
41
+ - :version: 0.2.0
42
+ :timestamp: 1680589830.9123309
data/Dockerfile.dockerun CHANGED
@@ -6,7 +6,7 @@ LABEL description="Dockerfile generated by dockerun"
6
6
  LABEL dockerun-info="https://github.com/chrisliaw/dockerun"
7
7
 
8
8
 
9
- RUN apt-get update && apt-get install -y sudo git curl build-essential
9
+ RUN apt-get update && apt-get install -y sudo git curl build-essential vim
10
10
 
11
11
 
12
12
 
@@ -22,6 +22,16 @@ USER chris
22
22
  #RUN sudo apt-get install -y curl build-essential
23
23
 
24
24
 
25
+ COPY on_docker_config /home/chris/docker_init.rb
26
+ #RUN chown chris:chris /home/chris/docker_init.rb
27
+ RUN ruby /home/chris/docker_init.rb
28
+
29
+
30
+
31
+
32
+
33
+ WORKDIR /opt
34
+
25
35
 
26
36
  # other Dockerfile entries starts here
27
37
 
data/Gemfile CHANGED
@@ -9,5 +9,6 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- #gem 'docker-cli', git: "docker-cli", branch: "master"
12
+ gem 'docker-cli', git: "docker-cli", branch: "master"
13
+
13
14
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,21 @@
1
+ GIT
2
+ remote: docker-cli
3
+ revision: a3fc5811299f71c2b0847bec10d3582f965b72b5
4
+ branch: master
5
+ specs:
6
+ docker-cli (0.1.2)
7
+ ptools
8
+ teLogger
9
+ toolrack
10
+ tty-command
11
+ tty-prompt
12
+
1
13
  PATH
2
14
  remote: .
3
15
  specs:
4
- dockerun (0.1.18)
5
- docker-cli
16
+ dockerun (0.2.1)
17
+ colorize
18
+ docker-cli (>= 0.1.2)
6
19
  teLogger (> 0.2.0)
7
20
  toolrack (> 0.19.1)
8
21
  tty-command
@@ -11,6 +24,7 @@ PATH
11
24
  GEM
12
25
  remote: https://rubygems.org/
13
26
  specs:
27
+ colorize (0.8.1)
14
28
  devops_assist (0.3.11)
15
29
  git_cli
16
30
  git_cli_prompt (~> 0.3.3)
@@ -19,11 +33,6 @@ GEM
19
33
  toolrack
20
34
  tty-prompt
21
35
  diff-lcs (1.5.0)
22
- docker-cli (0.2.0)
23
- ptools
24
- teLogger
25
- tty-command
26
- tty-prompt
27
36
  git_cli (0.11.2)
28
37
  gvcs
29
38
  ptools (~> 1.4.0)
@@ -69,10 +78,12 @@ GEM
69
78
  wisper (2.0.1)
70
79
 
71
80
  PLATFORMS
81
+ ruby
72
82
  x86_64-linux
73
83
 
74
84
  DEPENDENCIES
75
85
  devops_assist
86
+ docker-cli!
76
87
  dockerun!
77
88
  rake (~> 13.0)
78
89
  rspec (~> 3.0)
data/dockerun.gemspec CHANGED
@@ -35,8 +35,9 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_dependency 'tty-command' #, "> 0.10.1"
37
37
  spec.add_dependency 'tty-option' #, "> 0.2.0"
38
+ spec.add_dependency 'colorize'
38
39
 
39
- spec.add_dependency 'docker-cli'
40
+ spec.add_dependency 'docker-cli', ">= 0.1.2"
40
41
 
41
42
  spec.add_development_dependency 'devops_assist'
42
43
 
data/exe/dockerun CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'bundler/setup'
3
4
  require 'toolrack'
4
5
  include TR::CondUtils
5
6
 
@@ -0,0 +1,25 @@
1
+
2
+ require 'bundler'
3
+
4
+ module Dockerun
5
+ module CommandHelper
6
+ module BundlerHelper
7
+
8
+ def find_local_dev_gems
9
+
10
+ res = {}
11
+ Bundler.load.dependencies.each do |d|
12
+ if not d.source.nil?
13
+ src = d.source
14
+ if src.path.to_s != "."
15
+ res[d.name] = src.path.to_s
16
+ end
17
+ end
18
+ end
19
+ res
20
+
21
+ end # find_local_dev_gem
22
+
23
+ end
24
+ end
25
+ end
@@ -42,7 +42,7 @@ module Dockerun
42
42
  m.choice n,n
43
43
  end
44
44
  end
45
- end
45
+ end # find imageName
46
46
 
47
47
  if is_empty?(config.container_names(imageName))
48
48
  STDOUT.puts "There is no container registered under image '#{imageName}'"
@@ -62,14 +62,88 @@ module Dockerun
62
62
  end
63
63
 
64
64
 
65
- imageName = build_image_if_not_exist(imageName) do |ops, val|
65
+ imageName, mount_points = build_image_if_not_exist(imageName) do |ops, *val|
66
66
  case ops
67
67
  when :new_image_name
68
- cli.ask("Please provide a new image name : ", required: true)
68
+ cli.ask("Please provide a new image name : ".yellow, required: true)
69
+
69
70
  when :image_exist
70
- reuse = cli.yes? "Image '#{val}' already exist. Using existing image?"
71
+ reuse = cli.yes? "Image '#{val.first}' already exist. Using existing image?"
71
72
  # proceed or not , new name
72
- [reuse, val]
73
+ [reuse, val.first]
74
+
75
+ when :prompt_mount_points_starting
76
+ cli.say "\n Mount Directory into Docker : \n", color: :yellow
77
+
78
+ when :transfer_dev_gem_mapping?
79
+ found = val.first
80
+ cli.say(" It seems that the project has development gem attached to it : \n Found development gems (#{found.length}) : \n", color: :yellow)
81
+ if not found.nil?
82
+ found.each do |name, path|
83
+ cli.say(" * #{name} [#{path}]\n", color: :yellow)
84
+ end
85
+ end
86
+ cli.yes?(" Do you want to map the above development gems inside the docker? : ".yellow)
87
+
88
+ when :workspace_root_inside_docker
89
+ cli.ask("\n Workspace '#{val[2]}' shall be mapped to which directory inside the docker? : ".yellow, required: true, value: File.join(val.first, val[1]))
90
+
91
+ when :map_project_dir
92
+ res = cli.ask("\n Please provide path inside docker for current directory [Empty to skip mounting current directory] : ".yellow, value: File.join(val.first, File.basename(Dir.getwd)) )
93
+ if is_empty?(res)
94
+ cli.puts "\n Current directory '#{Dir.getwd}' shall not be available inside the docker".red
95
+ end
96
+ res
97
+
98
+ when :volume_mapping_required?
99
+ cli.yes?("\n Is there any other volume mapping required? ".yellow)
100
+
101
+ when :source_prompt
102
+ param = val.first
103
+ msg = []
104
+ if not param.nil?
105
+ msg = param[:control]
106
+ end
107
+ cli.ask("\n Directory to share with docker [#{msg.join(", ")}] : ".yellow, required: true)
108
+
109
+ when :destination_prompt
110
+ src = val.first
111
+ srcDir = File.basename(src)
112
+ cli.ask("\n Directory inside docker : ".yellow, required: true, value: "/opt/#{srcDir}")
113
+
114
+ when :add_to_bundle?
115
+ cli.yes?("\n Add directory '#{val.first}' to bundler config local? ".yellow)
116
+
117
+ when :add_mount_to_container
118
+ config.add_mount_to_container(imageName, *val)
119
+
120
+ when :add_more_volume_mapping?
121
+ cli.yes?("\n Add more volume mapping? ".yellow)
122
+
123
+ when :prompt_user_configurables
124
+ vv = val.first
125
+ cli.say "\n The following are the configurable items for the template '#{vv[:template]}' : \n".yellow
126
+ res = { }
127
+ vv[:userFields].each do |k,v|
128
+ case v[:type]
129
+ when :ask
130
+ res[k] = cli.ask(v[:desc].yellow) do |s|
131
+ s.required v[:required] if not_empty?(v[:required]) and is_bool?(v[:required])
132
+ s.value v[:default].to_s if not_empty?(v[:default])
133
+ end
134
+
135
+ when :select
136
+ res[k] = cli.select(v[:desc].yellow) do |m|
137
+ v[:options].each do |opt, key|
138
+ m.choice opt, key
139
+ end
140
+ #m.default v[:default] if not_empty?(v[:default])
141
+ end
142
+ end
143
+ end
144
+
145
+ res
146
+
73
147
  else
74
148
 
75
149
  end
@@ -101,24 +175,38 @@ module Dockerun
101
175
  end
102
176
  end
103
177
 
104
- selContName = run_docker_container(imageName, selContName) do |ops, *args|
178
+ selContName = run_docker_container(imageName, selContName, mount_points) do |ops, *args|
105
179
  case ops
106
180
  when :new_container_name
107
- cli.ask("Please provide a new container name : ", required: true)
181
+ cli.ask("\n Please provide a new container name : ".yellow, required: true)
108
182
  when :container_name_exist
109
- cli.yes?("Container name '#{args.first}' already exist. Proceed with existing?")
110
- when :volume_mapping_required?
111
- cli.yes?("Is there any volume mapping required? ")
112
- when :source_prompt
113
- cli.ask("Directory to share with docker : ", required: true)
114
- when :destination_prompt
115
- src = args.first
116
- srcDir = File.basename(src)
117
- cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
118
- when :add_mount_to_container
119
- config.add_mount_to_container(imageName, *args)
120
- when :add_more_volume_mapping?
121
- cli.yes?("Add more volume mapping?")
183
+ cli.yes?(" ** Container name '#{args.first}' already exist. Proceed with existing?".red)
184
+
185
+ #when :transfer_dev_gem_mapping?
186
+ # cli.yes?("It seems that the project has development gem attached to it. Do you want to map those development gems too inside the docker? ")
187
+
188
+ #when :workspace_root_inside_docker
189
+ # cli.ask(" Workspace '#{args[2]}' shall be mapped to which directory inside the docker? ", required: true, value: File.join(args.first, args[1]))
190
+
191
+ #when :map_project_dir
192
+ # cli.ask(" Please provide path inside docker for current directory [Empty to skip mounting current directory] : ", value: File.join(args.first, File.basename(Dir.getwd)), required: true)
193
+
194
+ #when :volume_mapping_required?
195
+ # cli.yes?("Is there any volume mapping required? ")
196
+ #when :source_prompt
197
+ # cli.ask("Directory to share with docker : ", required: true)
198
+ #when :destination_prompt
199
+ # src = args.first
200
+ # srcDir = File.basename(src)
201
+ # cli.ask("Directory to show inside docker : ", required: true, value: "/opt/#{srcDir}")
202
+
203
+ #when :add_to_bundle?
204
+ # cli.yes?(" Add directory '#{args.first}' to bundler config local? ")
205
+
206
+ #when :add_mount_to_container
207
+ # config.add_mount_to_container(imageName, *args)
208
+ #when :add_more_volume_mapping?
209
+ # cli.yes?("Add more volume mapping?")
122
210
  end
123
211
  end
124
212
 
@@ -38,7 +38,7 @@ module Dockerun
38
38
  # find history file
39
39
  config = ::Dockerun::Config.from_storage
40
40
 
41
- imageName = build_image_if_not_exist(imageName) do |ops, val|
41
+ imageName, mount_points = build_image_if_not_exist(imageName) do |ops, val|
42
42
  case ops
43
43
  when :new_image_name
44
44
  cli.ask("Please provide a new image name : ", required: true)
@@ -1,15 +1,17 @@
1
1
 
2
2
  require_relative 'docker_command_factory_helper'
3
+ require_relative 'bundler_helper'
3
4
 
4
5
  module Dockerun
5
6
  module CommandHelper
6
7
  module DockerContainerHelper
7
8
  include DockerCommandFactoryHelper
9
+ include BundlerHelper
8
10
 
9
11
  class DockerContainerBuildFailed < StandardError; end
10
12
  class DockerContainerStartFailed < StandardError; end
11
13
 
12
- def run_docker_container(image_name, container_name, &block)
14
+ def run_docker_container(image_name, container_name, mount_points = [], &block)
13
15
 
14
16
  raise DockerContainerBuildFailed, "block is required" if not block
15
17
  raise DockerContainerBuildFailed, "Image name is required" if is_empty?(image_name)
@@ -39,7 +41,10 @@ module Dockerun
39
41
  end
40
42
 
41
43
  if reuse == true
42
-
44
+
45
+ #
46
+ # container already exist so no configuration is required
47
+ #
43
48
  res = dcFact.find_running_container(container_name).run
44
49
  if not res.failed? and res.is_out_stream_empty?
45
50
  # not running
@@ -56,24 +61,81 @@ module Dockerun
56
61
 
57
62
  else
58
63
 
59
- reqVolMap = block.call(:volume_mapping_required?)
60
- mount = []
61
- if reqVolMap
64
+ #@workspace_root = "/opt"
65
+ #@shared_dirs = {}
62
66
 
63
- loop do
67
+ #mount = []
68
+ #sharedInsideDocker = []
69
+ #res = find_local_dev_gems
70
+ #puts "Found #{res.length} local gems #{res}"
71
+ #if not res.empty?
72
+ #
73
+ # transferMapping = block.call(:transfer_dev_gem_mapping?)
74
+ # if transferMapping
75
+ # res.each do |name, path|
76
+ # tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
77
+ # inPath = File.join(tsrc, name)
78
+ # mount << { path => inPath }
79
+ # @shared_dirs[name] = inPath
80
+ # end
81
+ # end
64
82
 
65
- src = block.call(:source_prompt)
66
- dest = block.call(:destination_prompt, src)
67
- mount << { src => dest }
68
- block.call(:add_mount_to_container, container_name, mount.last)
69
- repeat = block.call(:add_more_volume_mapping?)
70
- break if not repeat
83
+ #end
84
+
85
+ #mapProjectDir = block.call(:map_project_dir, @workspace_root)
86
+ #if not_empty?(mapProjectDir)
87
+ # mount << { Dir.getwd => mapProjectDir }
88
+ #end
89
+
90
+ #reqVolMap = block.call(:volume_mapping_required?)
91
+ #if reqVolMap
92
+
93
+ # loop do
94
+ #
95
+ # block.call(:already_mapped, mount)
96
+
97
+ # src = block.call(:source_prompt)
98
+ # dest = block.call(:destination_prompt, src)
99
+ # mount << { src => dest }
100
+ #
101
+ # add_to_bundle = block.call(:add_to_bundle?, dest)
102
+ # if add_to_bundle
103
+ # @shared_dirs[File.basename(dest)] = dest
104
+ # end
105
+
106
+ # block.call(:add_mount_to_container, container_name, mount.last)
107
+ # repeat = block.call(:add_more_volume_mapping?)
108
+ # break if not repeat
109
+
110
+ # end
111
+
112
+ #end
113
+
114
+
115
+ #insideDockerConfig = File.join(File.dirname(__FILE__),"..","..","template","setup_ruby_devenv.rb.erb")
116
+ #if File.exist?(insideDockerConfig)
117
+ #
118
+ # @docker_init_file_path = File.join(Dir.getwd,"on_docker_config")
119
+
120
+ # cont = File.read(insideDockerConfig)
121
+ #
122
+ # b = binding
123
+
124
+ # res = ERB.new(cont)
125
+ # out = res.result(b)
126
+
127
+ # # fixed this name to be used inside Dockerfile
128
+ # File.open(@docker_init_file_path, "w") do |f|
129
+ # f.write out
130
+ # end
131
+
132
+ # block.call(:on_docker_init_file_path,@docker_init_file_path)
133
+
134
+ #end
71
135
 
72
- end
73
136
 
74
- end
75
137
 
76
- dcFact.create_container_from_image(image_name, interactive: true, tty: true, container_name: container_name, mount: mount).run
138
+ dcFact.create_container_from_image(image_name, interactive: true, tty: true, container_name: container_name, mount: mount_points).run
77
139
 
78
140
  end
79
141
 
@@ -84,9 +146,10 @@ module Dockerun
84
146
  private
85
147
  def is_container_exist?(name)
86
148
  if not_empty?(name)
87
- res = dcFact.find_from_all_container(name).run
149
+ res = dcFact.find_from_all_container("^#{name}\\z").run
88
150
  raise DockerContainerBuildFailed, "Failed to find container. Error was : #{res.err_stream}" if res.failed?
89
151
 
152
+ p res.out_stream
90
153
  if res.is_out_stream_empty?
91
154
  # nothing found
92
155
  [false, ""]
@@ -1,20 +1,27 @@
1
1
 
2
2
  require_relative 'cli_prompt'
3
3
  require_relative 'docker_command_factory_helper'
4
+ require_relative 'bundler_helper'
5
+ require_relative 'template/template_writer'
4
6
 
5
7
  module Dockerun
6
8
  module CommandHelper
7
9
  module DockerImageHelper
8
10
  include CliHelper::CliPrompt
9
11
  include DockerCommandFactoryHelper
12
+ include BundlerHelper
10
13
 
11
14
  class DockerfileNotExist < StandardError; end
12
15
  class DockerImageBuildFailed < StandardError; end
13
16
  class DockerImageDeleteFailed < StandardError; end
17
+ class DockerImagePrebuiltConfigFailed < StandardError; end
14
18
 
15
- def load_dockerfile(root = Dir.getwd)
19
+ def load_dockerfile(root = Dir.getwd, dockerInitPath = nil, &block)
16
20
 
17
- df = Dir.glob(File.join(root,"Dockerfile*"))
21
+ #avail = ::Dockerun::Template::TemplateEngine.available_templates
22
+ df = ::Dockerun::Template::TemplateEngine.available_templates
23
+
24
+ #df = Dir.glob(File.join(root,"Dockerfile*"))
18
25
  if df.length == 0
19
26
  raise DockerfileNotExist, "Dockerfile not yet available. Please create one or run init first."
20
27
  end
@@ -30,7 +37,32 @@ module Dockerun
30
37
  selectedDf = df.first
31
38
  end
32
39
 
33
- selectedDf
40
+ tw = ::Dockerun::Template::TemplateWriter.new(selectedDf)
41
+ tw.docker_init_file_path = dockerInitPath
42
+ userFields = tw.user_configurables
43
+ if block
44
+ tw.user_configurables = block.call(:prompt_user_configurables, { template: selectedDf, userFields: userFields })
45
+ end
46
+ res = tw.compile
47
+
48
+ loc = "."
49
+ #loc = params[:location] if not_empty?(params[:location])
50
+
51
+ loc = File.expand_path(loc)
52
+ out = nil
53
+ if File.directory?(loc)
54
+ out = File.join(loc, "Dockerfile.dockerun")
55
+ else
56
+ out = File.join(File.dirname(loc), "Dockerfile.dockerun")
57
+ end
58
+
59
+ File.open(out, "w") do |f|
60
+ f.write res
61
+ end
62
+
63
+
64
+ #selectedDf
65
+ File.basename(out)
34
66
 
35
67
  end
36
68
 
@@ -38,6 +70,7 @@ module Dockerun
38
70
 
39
71
  raise DockerImageBuildFailed, "block is required" if not block
40
72
 
73
+ mountPoints = []
41
74
  if is_empty?(name)
42
75
  reuse = false
43
76
  loop do
@@ -50,20 +83,184 @@ module Dockerun
50
83
  if reuse
51
84
 
52
85
  else
53
- dockerfile = load_dockerfile(Dir.getwd)
86
+
87
+ #@workspace_root = "/opt"
88
+ #@shared_dirs = {}
89
+
90
+ #mount = []
91
+ #sharedInsideDocker = []
92
+ #res = find_local_dev_gems
93
+ #puts "Found #{res.length} local gems #{res}"
94
+ #if not res.empty?
95
+
96
+ # transferMapping = block.call(:transfer_dev_gem_mapping?)
97
+ # if transferMapping
98
+ # res.each do |name, path|
99
+ # tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
100
+ # inPath = File.join(tsrc, name)
101
+ # mount << { path => inPath }
102
+ # @shared_dirs[name] = inPath
103
+ # end
104
+ # end
105
+
106
+ #end
107
+
108
+ #mapProjectDir = block.call(:map_project_dir, @workspace_root)
109
+ #if not_empty?(mapProjectDir)
110
+ # mount << { Dir.getwd => mapProjectDir }
111
+ #end
112
+
113
+ #reqVolMap = block.call(:volume_mapping_required?)
114
+ #if reqVolMap
115
+
116
+ # loop do
117
+
118
+ # block.call(:already_mapped, mount)
119
+
120
+ # src = block.call(:source_prompt)
121
+ # dest = block.call(:destination_prompt, src)
122
+ # mount << { src => dest }
123
+
124
+ # add_to_bundle = block.call(:add_to_bundle?, dest)
125
+ # if add_to_bundle
126
+ # @shared_dirs[File.basename(dest)] = dest
127
+ # end
128
+
129
+ # block.call(:add_mount_to_container, container_name, mount.last)
130
+ # repeat = block.call(:add_more_volume_mapping?)
131
+ # break if not repeat
132
+
133
+ # end
134
+
135
+ #end
136
+
137
+
138
+ #insideDockerConfig = File.join(File.dirname(__FILE__),"..","..","template","setup_ruby_devenv.rb.erb")
139
+ #if File.exist?(insideDockerConfig)
140
+
141
+ # @docker_init_file_path = File.join(Dir.getwd,"on_docker_config")
142
+
143
+ # cont = File.read(insideDockerConfig)
144
+
145
+ # b = binding
146
+
147
+ # res = ERB.new(cont)
148
+ # out = res.result(b)
149
+
150
+ # # fixed this name to be used inside Dockerfile
151
+ # File.open(@docker_init_file_path, "w") do |f|
152
+ # f.write out
153
+ # end
154
+
155
+ # block.call(:on_docker_init_file_path,@docker_init_file_path)
156
+
157
+ #end
158
+
159
+ mountPoints, dockerinit = prompt_mount_points(&block)
160
+
161
+
162
+ dockerfile = load_dockerfile(Dir.getwd, dockerinit, &block)
54
163
  build_docker_image(name, dockerfile: dockerfile)
55
164
  end
56
165
 
57
166
  else
58
167
 
59
168
  if not is_image_existed?(name)
60
- dockerfile = load_dockerfile(Dir.getwd)
169
+
170
+ mountPoints, dockerinit = prompt_mount_points(&block)
171
+
172
+ dockerfile = load_dockerfile(Dir.getwd, dockerinit, &block)
61
173
  build_docker_image(name, dockerfile: dockerfile)
62
174
  end
63
175
 
64
176
  end
65
177
 
66
- name
178
+ [name, mountPoints]
179
+
180
+ end
181
+
182
+ def prompt_mount_points(&block)
183
+
184
+ raise DockerImagePrebuiltConfigFailed, "block is mandatory" if not block
185
+
186
+ @workspace_root = "/opt"
187
+ @shared_dirs = {}
188
+
189
+ block.call(:prompt_mount_points_starting)
190
+
191
+ mount = []
192
+ res = find_local_dev_gems
193
+ #puts "Found #{res.length} local gems #{res}"
194
+ if not res.empty?
195
+
196
+ transferMapping = block.call(:transfer_dev_gem_mapping?, res)
197
+ if transferMapping
198
+ res.each do |name, path|
199
+ tsrc = block.call(:workspace_root_inside_docker, @workspace_root, name, path)
200
+ mount << { path => tsrc }
201
+ @shared_dirs[name] = tsrc
202
+ end
203
+ end
204
+
205
+ end
206
+
207
+ mapProjectDir = block.call(:map_project_dir, @workspace_root)
208
+ if not_empty?(mapProjectDir)
209
+ mount << { Dir.getwd => mapProjectDir }
210
+ end
211
+
212
+ reqVolMap = block.call(:volume_mapping_required?)
213
+ if reqVolMap
214
+
215
+ loop do
216
+
217
+ block.call(:already_mapped, mount)
218
+
219
+ src = block.call(:source_prompt, { control: [ "Type 's' to skip" ] })
220
+ if src == "s"
221
+ block.call(:volume_mapping_skipped)
222
+ break
223
+ end
224
+
225
+ dest = block.call(:destination_prompt, src)
226
+ mount << { src => dest }
227
+
228
+ add_to_bundle = block.call(:add_to_bundle?, dest)
229
+ if add_to_bundle
230
+ @shared_dirs[File.basename(dest)] = dest
231
+ end
232
+
233
+ block.call(:add_mount_to_container, container_name, mount.last)
234
+ repeat = block.call(:add_more_volume_mapping?)
235
+ break if not repeat
236
+
237
+ end
238
+
239
+ end
240
+
241
+
242
+ insideDockerConfig = File.join(File.dirname(__FILE__),"..","..","template","setup_ruby_devenv.rb.erb")
243
+ if File.exist?(insideDockerConfig)
244
+
245
+ @docker_init_file_path = File.join(Dir.getwd,"on_docker_config")
246
+
247
+ cont = File.read(insideDockerConfig)
248
+
249
+ b = binding
250
+
251
+ res = ERB.new(cont)
252
+ out = res.result(b)
253
+
254
+ # fixed this name to be used inside Dockerfile
255
+ File.open(@docker_init_file_path, "w") do |f|
256
+ f.write out
257
+ end
258
+
259
+ block.call(:on_docker_init_file_path,@docker_init_file_path)
260
+
261
+ end
262
+
263
+ [mount, @docker_init_file_path]
67
264
 
68
265
  end
69
266
 
@@ -13,6 +13,8 @@ module Dockerun
13
13
 
14
14
  attr_accessor :image, :user_group_id, :user_group_name, :user_id, :user_login, :maintainer, :image_base
15
15
  attr_writer :user_configurables
16
+ attr_accessor :docker_init_file_path
17
+ attr_accessor :match_user, :working_dir
16
18
 
17
19
  def self.instance(template)
18
20
  tmp = template.to_s.downcase
@@ -34,21 +36,26 @@ module Dockerun
34
36
  @user_id = user[:user_id]
35
37
  @user_login = user[:login]
36
38
  @image_base = :ubuntu
39
+ @match_user = TR::RTUtils.on_linux?
40
+ @working_dir = "/opt"
37
41
  end
38
42
 
39
43
  def user_configurables
40
44
  fields = {
41
- image: { desc: "Image name of the docker based on", required: true },
42
- image_base: { desc: "Image is based on which OS? Assumption with be on Debian based. ", default: :ubuntu },
43
- maintainer: { desc: "Maintainer of the Dockerfile", default: @maintainer }
45
+ image: { desc: " Docker image name : ", required: true, type: :ask },
46
+ image_base: { desc: " Docker image OS : ", default: :debian, type: :select, options: { debian: "Ubuntu/Debian based", not_sure: "Not sure which distro" }.invert },
47
+ working_dir: { desc: " Default directory after login : ", type: :ask, default: @working_dir }
44
48
  }
45
49
 
46
50
  if TR::RTUtils.on_linux?
47
51
  f2 = {
48
- user_group_id: { desc: "User group ID that shall be created in docker. Default to current running user's ID", default: @user_group_id.to_s },
49
- user_group_name: { desc: "User group name that shall be created in docker. Default to current running user's group", default: @user_group_name },
50
- user_id: { desc: "User ID that shall be created in docker. Default to current running user ID", default: @user_id.to_s },
51
- user_login: { desc: "User login name that shall be created in docker. Default to current running user's login", default: @user_login }
52
+ match_user: { desc: " Match host user with docker user? ", type: :yes? },
53
+ #maintainer: { desc: "Maintainer of the Dockerfile", default: @maintainer }
54
+
55
+ #user_group_id: { desc: "User group ID that shall be created in docker. Default to current running user's ID", default: @user_group_id.to_s },
56
+ #user_group_name: { desc: "User group name that shall be created in docker. Default to current running user's group", default: @user_group_name },
57
+ #user_id: { desc: "User ID that shall be created in docker. Default to current running user ID", default: @user_id.to_s },
58
+ #user_login: { desc: "User login name that shall be created in docker. Default to current running user's login", default: @user_login }
52
59
  }
53
60
  fields.merge!(f2)
54
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dockerun
4
- VERSION = "0.1.18"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/dockerun.rb CHANGED
@@ -3,6 +3,9 @@
3
3
  require 'toolrack'
4
4
  require 'teLogger'
5
5
 
6
+ require 'tty/prompt'
7
+ require 'colorize'
8
+
6
9
  require_relative "dockerun/version"
7
10
 
8
11
  require_relative 'dockerun/command/dockerun'
@@ -8,11 +8,11 @@ LABEL dockerun-info="https://github.com/chrisliaw/dockerun"
8
8
  <% case @image_base.to_sym
9
9
  when :fedora %>
10
10
  RUN dnf update && dnf install sudo git curl
11
- <% else %>
12
- RUN apt-get update && apt-get install -y sudo git curl build-essential
11
+ <% when :debian %>
12
+ RUN apt-get update && apt-get install -y sudo git curl build-essential vim
13
13
  <% end %>
14
14
 
15
- <% if TR::RTUtils.on_linux? %>
15
+ <% if TR::RTUtils.on_linux? and @match_user == true %>
16
16
 
17
17
  RUN groupadd -f -g <%= @user_group_id %> <%= @user_group_name %> && \
18
18
  useradd -u <%= @user_id %> -g <%= @user_group_id %> -m <%= @user_login %> && \
@@ -24,6 +24,16 @@ USER <%= @user_login %>
24
24
  # from this point onwards, sudo is required for privileaged operation
25
25
  #RUN sudo apt-get install -y curl build-essential
26
26
 
27
+ <% if not (@docker_init_file_path.nil? or @docker_init_file_path.empty?) %>
28
+ COPY <%= File.basename(@docker_init_file_path) %> /home/<%= @user_login %>/docker_init.rb
29
+ #RUN chown <%= @user_login %>:<%= @user_group_name %> /home/<%= @user_login %>/docker_init.rb
30
+ RUN ruby /home/<%= @user_login %>/docker_init.rb
31
+ <% end %>
32
+
33
+ <% end %>
34
+
35
+ <% if not_empty?(@working_dir) %>
36
+ WORKDIR <%= @working_dir %>
27
37
  <% end %>
28
38
 
29
39
  # other Dockerfile entries starts here
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## This file is auto-generated. Changes on this file will be overwritten by newly generate file on next run
4
+
5
+ # setup env
6
+ WS_ROOT = "<%= @ws_root.nil? ? "/opt" : @ws_root %>"
7
+
8
+ <% if not (@shared_dirs.nil? or @shared_dirs.empty?) %>
9
+ <% @shared_dirs.each do |name, pa| %>
10
+ `bundle config --global local.<%= name %> <%= pa %>`
11
+ <% end %>
12
+ <% end %>
13
+
14
+ bashrc = File.join(Dir.home,".bashrc")
15
+ if File.exist?(bashrc)
16
+ cont = File.read(bashrc)
17
+ if not cont =~ /^alias be/
18
+ `echo "alias be=\\"bundle exec\\"" >> #{bashrc}`
19
+ end
20
+ end
21
+
22
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockerun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-02 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toolrack
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: docker-cli
70
+ name: colorize
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: docker-cli
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.2
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: devops_assist
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +128,7 @@ files:
114
128
  - dockerun.gemspec
115
129
  - exe/dockerun
116
130
  - lib/dockerun.rb
131
+ - lib/dockerun/bundler_helper.rb
117
132
  - lib/dockerun/cli_prompt.rb
118
133
  - lib/dockerun/command/dockerun.rb
119
134
  - lib/dockerun/command/init.rb
@@ -133,6 +148,7 @@ files:
133
148
  - lib/dockerun/user_info.rb
134
149
  - lib/dockerun/version.rb
135
150
  - template/Dockerfile_general.erb
151
+ - template/setup_ruby_devenv.rb.erb
136
152
  homepage: ''
137
153
  licenses: []
138
154
  metadata: {}