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]
  raise "Please provide an image path name in .gantreecfg ex. { 'image_path' : 'bleacher/cms' }" unless @image_path
  @tag = @options[:tag] ||= tag
  @base_image_tag = @options[:base_image_tag]
end

Instance Method Details

#buildObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gantree/docker.rb', line 27

def build
  puts "Building..."
  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
end

#pullObject



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

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



39
40
41
42
43
44
45
46
47
48
# File 'lib/gantree/docker.rb', line 39

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