lib/odania_ops/cli/docker.rb in odania_ops-0.0.13 vs lib/odania_ops/cli/docker.rb in odania_ops-0.0.14
- old
+ new
@@ -42,9 +42,25 @@
puts failed_images.inspect
exit 1
end
end
+ desc 'push <image_name> <local_image_tag>', 'Pushes the image'
+ def push(image_name, local_image_tag)
+ OdaniaOps::Helper::Docker.login
+
+ build_number = get_highest_build_number(image_name) + 1
+ build_tag = "v#{build_number}"
+
+ $logger.info "Tagging #{build_tag} as latest"
+ OdaniaOps::Helper::Docker.remote_tag "#{image_name}:#{local_image_tag}", "#{image_name}:#{build_tag}"
+ OdaniaOps::Helper::Docker.remote_tag "#{image_name}:#{local_image_tag}", "#{image_name}:latest"
+
+ $logger.info "Pushing #{build_tag}"
+ OdaniaOps::Helper::Docker.push image_name, build_tag
+ OdaniaOps::Helper::Docker.push image_name, 'latest'
+ end
+
private
def get_highest_build_number(image_name)
build_numbers = OdaniaOps::Helper::Docker.image_tags(image_name).map { |tag| tag.gsub('v', '').to_i }.sort
$logger.debug "Build numbers: #{build_numbers.inspect}"