Sha256: 6b930cb09df57be528807b20ff2381d7279d84fbfac2ad86d0757c3ce7807dc7

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

require 'droplet_kit'
require 'yaml'

module Docker
  SPECIAL_OPTS = ["image", "ports", "command", "post-conditions"]

  def self.containers_for(host_name)
    config_file = "#{Ops::CONTAINERS_DIR}/#{host_name}.yml"
    begin
      config = YAML.load_file config_file
    rescue
      raise "Please, create '#{config_file}' file with all containers configured"
    end
  end

  def self.copy_ssh_credentials_command(container_name)
    <<-EOH
      ID=$(docker inspect -f   '{{.Id}}' #{container_name})
      # Container folder
      if sudo test -d "/var/lib/docker/aufs"; then
        CONTAINERS_DIR=/var/lib/docker/aufs/mnt
        SSH_DIR=$CONTAINERS_DIR/$ID/root/.ssh
      elif sudo test -d "/var/lib/docker/btrfs"; then
        CONTAINERS_DIR=/var/lib/docker/btrfs/subvolumes
        SSH_DIR=$CONTAINERS_DIR/$ID/root/.ssh
      elif sudo test -d "/var/lib/docker/devicemapper"; then
        CONTAINERS_DIR=/var/lib/docker/devicemapper/mnt
        SSH_DIR=$CONTAINERS_DIR/$ID/rootfs/root/.ssh
      fi

      echo SSH container folder: $SSH_DIR
      if sudo test ! -d "$SSH_DIR" ; then
        sudo mkdir $SSH_DIR
      fi

      echo Copying authorized_keys and id_rsa.pub files
      sudo touch $SSH_DIR/authorized_keys
      sudo cat ~/.ssh/authorized_keys | sudo tee -a $SSH_DIR/authorized_keys
      sudo cat ~/.ssh/id_rsa.pub | sudo tee -a $SSH_DIR/authorized_keys
      sudo chmod 600 $SSH_DIR/authorized_keys
    EOH
  end


  def self.get_container_port(container_config)
    container_config["ports"].select{|port| port.end_with? ":22"}[0].split(':')[0]
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
open-dock-0.1.18 lib/open-dock/docker.rb
open-dock-0.1.17 lib/open-dock/docker.rb
open-dock-0.1.16 lib/open-dock/docker.rb
open-dock-0.1.15 lib/open-dock/docker.rb
open-dock-0.1.14 lib/open-dock/docker.rb
open-dock-0.1.13 lib/open-dock/docker.rb
open-dock-0.1.11 lib/open-dock/docker.rb
open-dock-0.1.10 lib/open-dock/docker.rb
open-dock-0.1.9 lib/open-dock/docker.rb
open-dock-0.1.8 lib/open-dock/docker.rb
open-dock-0.1.7 lib/open-dock/docker.rb