Class: Pipely::Deploy::BootstrapContext::Ec2Context

Inherits:
Object
  • Object
show all
Defined in:
lib/pipely/deploy/bootstrap_context.rb

Overview

Context for EC2 instances

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Ec2Context

Returns a new instance of Ec2Context.



28
29
30
31
# File 'lib/pipely/deploy/bootstrap_context.rb', line 28

def initialize(parent)
  @parent = parent
  @ssh_initialized = false
end

Instance Method Details

#as_root(init_ssh = true) ⇒ Object



37
38
39
40
41
42
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
# File 'lib/pipely/deploy/bootstrap_context.rb', line 37

def as_root(init_ssh=true)
  script = ""

  if init_ssh && !@ssh_initialized
    @ssh_initialized = true
    script << %{
# Set up ssh access
if [ ! -f ~/.ssh/id_rsa ]; then
  mkdir -p ~/.ssh
  ssh-keygen -P '' -f ~/.ssh/id_rsa
  cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  chmod 600 ~/.ssh/authorized_keys
fi
}
  end

  script << %{
# Use ssh to bypass the sudo "require tty" setting
ssh -o "StrictHostKeyChecking no" -t -t ec2-user@localhost <<- EOF
  sudo su -;
}

  # The yield to be run as root
  script << yield

  script << %{
  # exit twice, once for su and once for ssh
  exit;
  exit;
EOF
}
end

#install_gems_script(&blk) ⇒ Object



33
34
35
# File 'lib/pipely/deploy/bootstrap_context.rb', line 33

def install_gems_script(&blk)
  @parent.install_gems_script(:awscli, &blk)
end