dockerun 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -11
  3. data/Rakefile +0 -2
  4. data/Rakefile.bak +8 -0
  5. data/dockerspec.sample +104 -0
  6. data/{dockerun.gemspec → dockerun.gemspec.bak} +20 -22
  7. data/exe/dockerun +8 -115
  8. data/lib/dockerun/cli/command.rb +133 -0
  9. data/lib/dockerun/cli/command_factory.rb +313 -0
  10. data/lib/dockerun/cli/command_result.rb +67 -0
  11. data/lib/dockerun/cli/delete_container.rb +55 -0
  12. data/lib/dockerun/cli/delete_image.rb +99 -0
  13. data/lib/dockerun/cli/run.rb +39 -0
  14. data/lib/dockerun/cli/user_info.rb +39 -0
  15. data/lib/dockerun/cli_engine.rb +104 -0
  16. data/lib/dockerun/config.rb +40 -70
  17. data/lib/dockerun/context/rubygems.rb +142 -0
  18. data/lib/dockerun/dfile.rb +204 -0
  19. data/lib/dockerun/docker_cli.rb +124 -0
  20. data/lib/dockerun/dsl.rb +291 -0
  21. data/lib/dockerun/version.rb +1 -1
  22. data/lib/dockerun.rb +31 -24
  23. data/sig/dockerun.rbs +4 -0
  24. metadata +62 -73
  25. data/.release_history.yml +0 -56
  26. data/Dockerfile.dockerun +0 -38
  27. data/Gemfile +0 -15
  28. data/Gemfile.lock +0 -94
  29. data/bin/console +0 -15
  30. data/bin/setup +0 -8
  31. data/lib/dockerun/bundler_helper.rb +0 -25
  32. data/lib/dockerun/cli_prompt.rb +0 -18
  33. data/lib/dockerun/command/dockerun.rb +0 -30
  34. data/lib/dockerun/command/init.rb +0 -79
  35. data/lib/dockerun/command/remove_container.rb +0 -99
  36. data/lib/dockerun/command/reset_image.rb +0 -107
  37. data/lib/dockerun/command/run.rb +0 -221
  38. data/lib/dockerun/command/run_new_container.rb +0 -94
  39. data/lib/dockerun/command/run_new_image.rb +0 -89
  40. data/lib/dockerun/command/stop_container.rb +0 -90
  41. data/lib/dockerun/docker_command_factory_helper.rb +0 -19
  42. data/lib/dockerun/docker_container_helper.rb +0 -204
  43. data/lib/dockerun/docker_image_helper.rb +0 -381
  44. data/lib/dockerun/template/general_template_writer.rb +0 -14
  45. data/lib/dockerun/template/jruby_template_writer.rb +0 -24
  46. data/lib/dockerun/template/template_engine.rb +0 -27
  47. data/lib/dockerun/template/template_writer.rb +0 -102
  48. data/lib/dockerun/user_info.rb +0 -37
  49. data/template/Dockerfile_general.erb +0 -41
  50. data/template/setup_ruby_devenv.rb.erb +0 -22
@@ -1,102 +0,0 @@
1
-
2
- require 'erb'
3
-
4
- require_relative '../user_info'
5
-
6
- module Dockerun
7
- module Template
8
-
9
- class TemplateWriter
10
- include UserInfo
11
-
12
- class TemplateNotFound < StandardError; end
13
-
14
- attr_accessor :image, :user_group_id, :user_group_name, :user_id, :user_login, :maintainer, :image_base
15
- attr_writer :user_configurables
16
- attr_accessor :docker_init_file_path
17
- attr_accessor :match_user, :working_dir
18
-
19
- def self.instance(template)
20
- tmp = template.to_s.downcase
21
- if tmp =~ /jruby/
22
- JrubyTemplateWriter.new
23
- else
24
- TemplateWriter.new
25
- end
26
- end
27
-
28
- def initialize(template = :general)
29
- @template = template
30
- @image = "<Replace me>"
31
- user = user_info
32
- group = group_info
33
- @maintainer = user[:login]
34
- @user_group_id = group[:group_id]
35
- @user_group_name = group[:group_name]
36
- @user_id = user[:user_id]
37
- @user_login = user[:login]
38
- @image_base = :ubuntu
39
- @match_user = TR::RTUtils.on_linux?
40
- @working_dir = "/opt"
41
- end
42
-
43
- def user_configurables
44
- fields = {
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 }
48
- }
49
-
50
- if TR::RTUtils.on_linux?
51
- f2 = {
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 }
59
- }
60
- fields.merge!(f2)
61
- end
62
- fields
63
- end
64
-
65
- def compile(&block)
66
-
67
- if not_empty?(@user_configurables)
68
- @user_configurables.each do |k,v|
69
- begin
70
- self.send("#{k}=", v)
71
- rescue Exception => ex
72
- STDERR.puts "Setting value exception : #{ex}"
73
- end
74
- end
75
- end
76
-
77
- tmp = find_template
78
- cont = nil
79
- File.open(tmp,"r") do |f|
80
- cont = f.read
81
- end
82
-
83
- b = binding
84
-
85
- res = ERB.new(cont)
86
- res.result(b)
87
- end
88
-
89
- protected
90
- def find_template
91
- @template = :general if is_empty?(@template)
92
-
93
- root = TemplateEngine.template_root
94
- templateFile = File.join(root,"Dockerfile_#{@template}.erb")
95
- raise TemplateNotFound, "Given template '#{@template}' could not be found" if not File.exist?(templateFile)
96
-
97
- templateFile
98
- end
99
-
100
- end
101
- end
102
- end
@@ -1,37 +0,0 @@
1
-
2
- require 'etc'
3
-
4
- module Dockerun
5
-
6
- module UserInfo
7
- include TR::CondUtils
8
-
9
- def user_info(login = nil)
10
- login = Etc.getlogin if is_empty?(login)
11
- res = { login: login }
12
- begin
13
- res[:user_id] = Etc.getpwnam(login).uid
14
- rescue Exception => ex
15
- res[:user_id] = nil
16
- end
17
- res
18
- end
19
-
20
- def group_info(login = nil)
21
- login = Etc.getlogin if is_empty?(login)
22
- res = { }
23
- begin
24
- gnm = Etc.getgrnam(login)
25
- res[:group_name] = gnm.name
26
- res[:group_id] = gnm.gid
27
- rescue Exception => ex
28
- p ex
29
- res[:group_name] = ""
30
- res[:group_id] = nil
31
- end
32
- res
33
- end
34
-
35
- end
36
-
37
- end
@@ -1,41 +0,0 @@
1
-
2
- FROM <%= @image %>
3
- LABEL version="0.1"
4
- LABEL maintainer="<%= @maintainer %>"
5
- LABEL description="Dockerfile generated by dockerun"
6
- LABEL dockerun-info="https://github.com/chrisliaw/dockerun"
7
-
8
- <% case @image_base.to_sym
9
- when :fedora %>
10
- RUN dnf update && dnf install sudo git curl
11
- <% when :debian %>
12
- RUN apt-get update && apt-get install -y sudo git curl build-essential vim
13
- <% end %>
14
-
15
- <% if TR::RTUtils.on_linux? and @match_user == true %>
16
-
17
- RUN groupadd -f -g <%= @user_group_id %> <%= @user_group_name %> && \
18
- useradd -u <%= @user_id %> -g <%= @user_group_id %> -m <%= @user_login %> && \
19
- usermod -aG sudo <%= @user_login %> && \
20
- echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
21
-
22
- USER <%= @user_login %>
23
-
24
- # from this point onwards, sudo is required for privileaged operation
25
- #RUN sudo apt-get install -y curl build-essential
26
-
27
- <% end %>
28
-
29
- <% if not (@docker_init_file_path.nil? or @docker_init_file_path.empty?) %>
30
- COPY <%= File.basename(@docker_init_file_path) %> /tmp/docker_init.rb
31
- RUN ruby /tmp/docker_init.rb
32
- <% end %>
33
-
34
- <% if not_empty?(@working_dir) %>
35
- WORKDIR <%= @working_dir %>
36
- <% end %>
37
-
38
- # other Dockerfile entries starts here
39
-
40
- CMD [ "/bin/bash", "--login" ]
41
-
@@ -1,22 +0,0 @@
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
-