Class: Armada::Image
- Inherits:
-
Object
- Object
- Armada::Image
- Defined in:
- lib/armada/docker/image.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #error(message) ⇒ Object
- #extract_credentials(options) ⇒ Object
- #generate_auth(options) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(docker_host, options) ⇒ Image
constructor
do not use this method directly, instead call create.
- #pull ⇒ Object
- #valid? ⇒ Boolean
- #valid_credentials?(m) ⇒ Boolean
- #warn(message) ⇒ Object
Constructor Details
#initialize(docker_host, options) ⇒ Image
do not use this method directly, instead call create
6 7 8 9 10 11 12 13 14 |
# File 'lib/armada/docker/image.rb', line 6 def initialize(docker_host, ) @name = [:image] @tag = [:tag] @pull = [:pull] @docker_host = docker_host @image = [:docker_image] @id = @image.id if @image @auth = generate_auth() end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
4 5 6 |
# File 'lib/armada/docker/image.rb', line 4 def auth @auth end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/armada/docker/image.rb', line 4 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
4 5 6 |
# File 'lib/armada/docker/image.rb', line 4 def image @image end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/armada/docker/image.rb', line 4 def name @name end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
4 5 6 |
# File 'lib/armada/docker/image.rb', line 4 def tag @tag end |
Instance Method Details
#error(message) ⇒ Object
82 83 84 |
# File 'lib/armada/docker/image.rb', line 82 def error() Armada.ui.error "#{@docker_host.host} -- #{message}" end |
#extract_credentials(options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/armada/docker/image.rb', line 36 def extract_credentials() = .select { |k, v| [:username, :password, :email].include? k } unless .empty? return else dockercfg = [:dockercfg].for_image @name if [:dockercfg] if dockercfg.nil? return {} else return { :username => dockercfg.username, :password => dockercfg.password, :email => dockercfg.email } end end end |
#generate_auth(options) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/armada/docker/image.rb', line 64 def generate_auth() credentials = extract_credentials() if valid_credentials? credentials return credentials else return nil end end |
#info(message) ⇒ Object
74 75 76 |
# File 'lib/armada/docker/image.rb', line 74 def info() Armada.ui.info "#{@docker_host.host} -- #{message}" end |
#pull ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/armada/docker/image.rb', line 20 def pull if @pull begin info "Pulling image [#{@name}] with tag [#{@tag}]" @image = ::Docker::Image.create({:fromImage => @name, :tag => @tag}, @auth, @docker_host.connection) @id = @image.id rescue Exception => e raise "An error occurred while trying to pull image [#{@name}] with tag [#{@tag}] -- #{e.message}" end else info "Not pulling image [#{@name}] with tag [#{@tag}] because `--no-pull` was specified." @id = "#{@name}:#{@tag}" raise "The image id is not set, you cannot proceed with the deploy until a valid image is found -- [#{@name}:#{@tag}]" unless valid? end end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/armada/docker/image.rb', line 16 def valid? return @id && @image end |
#valid_credentials?(m) ⇒ Boolean
54 55 56 57 58 59 60 61 62 |
# File 'lib/armada/docker/image.rb', line 54 def valid_credentials?(m) [:username, :password].each do |k| unless m.include? k return false end end return true end |
#warn(message) ⇒ Object
78 79 80 |
# File 'lib/armada/docker/image.rb', line 78 def warn() Armada.ui.warn "#{@docker_host.host} -- #{message}" end |