Class: Gantree::Docker

Inherits:
Base
  • Object
show all
Defined in:
lib/gantree/docker.rb

Instance Method Summary collapse

Methods inherited from Base

#authenticate_librato, #cfm, #check_credentials, check_for_updates, #check_template_bucket, #create_default_env, #eb, #env_type, #error_msg, #escape_characters_in_string, #get_latest_docker_solution, #print_options, #s3, #set_aws_keys, #tag, update_configuration, #upload_templates

Constructor Details

#initialize(options) ⇒ Docker

Returns a new instance of Docker.



6
7
8
9
10
11
12
13
14
# File 'lib/gantree/docker.rb', line 6

def initialize options
  check_credentials
  set_aws_keys
  @options = options
  @image_path = @options[:image_path] 
  @image_path||= get_image_path
  @tag = @options[:tag] ||= tag
  @base_image_tag = @options[:base_image_tag]
end

Instance Method Details

#buildObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gantree/docker.rb', line 35

def build
  puts "Building..."
  
  if system("git rev-parse --short HEAD > version.txt")
    puts "Outputting short hash to version.txt"
  else
    puts "Error: Could not output commit hash to version.txt (is this a git repository?)"
  end

  if system("docker build -t #{@image_path}:#{@tag} .")
    puts "Image Built: #{@image_path}:#{@tag}".green
    puts "gantree push --image-path #{@image_path} -t #{@tag}" unless @options[:hush]
    puts "gantree deploy app_name -t #{@tag}" unless @options[:hush]
  else
    puts "Error: Image was not built successfully".red
    exit 1
  end

  if system("rm -f version.txt")
    puts "Removing version.txt after docker build"
  else
    puts "Error: Can't remove version.txt after docker build"
  end
end

#get_image_pathObject



16
17
18
19
20
21
22
# File 'lib/gantree/docker.rb', line 16

def get_image_path
  dockerrun = JSON.parse(IO.read("Dockerrun.aws.json"))
  image = dockerrun["Image"]["Name"]
  image.gsub!(/:(.*)$/, "") if image.include? ":"
  puts "Image Path: #{image}".light_blue
  image
end

#pullObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/gantree/docker.rb', line 24

def pull
  puts "Pulling Image First..."
  if @base_image_tag
    puts "Pulled Image: #{@image_path}:#{@base_image_tag}".green if system("docker pull #{@image_path}:#{@base_image_tag}")
  elsif system("docker pull #{@image_path}")
    puts "Pulled Image: #{@image_path}".green
  else 
    puts "Failed to Pull Image #{@image_path}".red
  end
end

#pushObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/gantree/docker.rb', line 60

def push
  puts "Pushing to #{@image_path}:#{@tag} ..."
  if system("docker push #{@image_path}:#{@tag}")
    puts "Image Pushed: #{@image_path}:#{@tag}".green
    puts "gantree deploy app_name -t #{@tag}" unless @options[:hush]
  else
    puts "Error: Image was not pushed successfully".red
    exit 1
  end
end