Class: DevDock::DevContainer
- Inherits:
-
Object
- Object
- DevDock::DevContainer
- Defined in:
- lib/dev_dock/container.rb
Instance Method Summary collapse
- #enable_x11(arguments) ⇒ Object
- #exist? ⇒ Boolean
- #image ⇒ Object
-
#initialize(image_name) ⇒ DevContainer
constructor
A new instance of DevContainer.
-
#kill ⇒ Object
kill container.
- #run ⇒ Object
- #volumes ⇒ Object
Constructor Details
#initialize(image_name) ⇒ DevContainer
Returns a new instance of DevContainer.
10 11 12 13 14 |
# File 'lib/dev_dock/container.rb', line 10 def initialize(image_name) @image = DevDock::DevImage.new(image_name) @volumes = DevDock::DevVolumes.new(@image) @name = DevDock::Util::snake_case("dev_dock_" + image_name) end |
Instance Method Details
#enable_x11(arguments) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/dev_dock/container.rb', line 36 def enable_x11(arguments) arguments.push '-v' arguments.push '/tmp/.X11-unix:/tmp/.X11-unix:ro' arguments.push '-e' arguments.push 'DISPLAY' end |
#exist? ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/dev_dock/container.rb', line 24 def exist? Docker::Container.get(@name) true rescue Docker::Error::NotFoundError false end |
#image ⇒ Object
16 17 18 |
# File 'lib/dev_dock/container.rb', line 16 def image @image end |
#kill ⇒ Object
kill container
32 33 34 |
# File 'lib/dev_dock/container.rb', line 32 def kill Docker::Container.get(@name).kill end |
#run ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dev_dock/container.rb', line 43 def run arguments = [ '/usr/local/bin/docker', 'run', '--privileged', '--name', @name, '--net=host', '--rm', '-ti', '--detach-keys', 'ctrl-q,ctrl-q', '-e', 'GH_USER', '-e', 'GH_PASS', '-v', '/run/docker.sock:/var/run/docker.sock' ] ['workspaces', '.gitconfig', '.ssh'].each do |directory| arguments.push '-v', "#{ENV['HOME']}/#{directory}:/home/#{@image.user}/#{directory}" end if RUBY_PLATFORM == "x86_64-linux" enable_x11(arguments) arguments.push '-v', '/etc/localhost:/etc/localhost:ro' end @volumes.list.each do |volume| arguments.push '--mount', "source=#{volume.name},target=#{volume.path}" end arguments.push @image.name arguments.push 'tmux' arguments.push 'new' exec *arguments end |
#volumes ⇒ Object
20 21 22 |
# File 'lib/dev_dock/container.rb', line 20 def volumes @volumes end |