Skip to content

Commit

Permalink
Merge pull request zendesk#675 from zendesk/shender/docker_hub_compat…
Browse files Browse the repository at this point in the history
…ibility

Make compatible with main docker hub registry.
  • Loading branch information
henders committed Dec 14, 2015
2 parents d136acc + d9644c8 commit 10e5912
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
13 changes: 11 additions & 2 deletions app/models/docker_builder_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def build_image(tmp_dir)

def push_image(tag)
build.docker_ref = tag || build.label.try(:parameterize) || 'latest'
build.docker_repo_digest = nil
build.docker_image.tag(repo: project.docker_repo, tag: build.docker_ref, force: true)

output_buffer.puts("### Pushing Docker image to #{project.docker_repo}:#{build.docker_ref}")

build.docker_image.push do |output_chunk|
build.docker_image.push(registry_credentials) do |output_chunk|
parsed_chunk = handle_output_chunk(output_chunk)

status = parsed_chunk.fetch('status', '')
Expand All @@ -62,7 +63,6 @@ def push_image(tag)
end

build.save!

build
rescue Docker::Error::DockerError => e
output_buffer.puts("Docker push failed: #{e.message}\n")
Expand Down Expand Up @@ -98,4 +98,13 @@ def send_after_notifications
Samson::Hooks.fire(:after_docker_build, build)
SseRailsEngine.send_event('builds', { type: 'finish', build: BuildSerializer.new(build, root: nil) })
end

def registry_credentials
return nil unless ENV['DOCKER_REGISTRY_USER'].present? || ENV['DOCKER_REGISTRY_EMAIL'].present?
{
username: ENV['DOCKER_REGISTRY_USER'],
password: ENV['DOCKER_REGISTRY_PASS'],
email: ENV['DOCKER_REGISTRY_EMAIL']
}
end
end
8 changes: 1 addition & 7 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ def repo_name
def docker_repo
@docker_repo ||= begin
registry = Rails.application.config.samson.docker.registry
if Rails.env.production?
"#{registry}/#{permalink_base}"
else
host, namespace = registry.split '/'
namespace ||= 'samson'
"#{host}/#{namespace}_non_prod/#{permalink_base}"
end
"#{registry}/#{permalink_base}"
end
end

Expand Down
21 changes: 11 additions & 10 deletions config/initializers/docker.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
require 'docker'

if ENV['DOCKER_URL'].present? && !Rails.env.test? && !ENV['PRECOMPILE']
Docker.url = ENV['DOCKER_URL']
Docker.options = { read_timeout: 600 }

# Confirm the Docker daemon is a recent enough version
Docker.validate_version!
end
if !Rails.env.test? && !ENV['PRECOMPILE']
if ENV['DOCKER_URL'].present?
Docker.url = ENV['DOCKER_URL']
Docker.options = { read_timeout: 600 }

# Confirm the Docker daemon is a recent enough version
Docker.validate_version!
end

if ENV['DOCKER_FEATURE'] && !ENV['DOCKER_REGISTRY'].present?
puts '*** DOCKER_REGISTRY environment variable must be configured when DOCKER_FEATURE is enabled ***'
exit(1)
if ENV['DOCKER_FEATURE'] && !ENV['DOCKER_REGISTRY'].present?
puts '*** DOCKER_REGISTRY environment variable must be configured when DOCKER_FEATURE is enabled ***'
exit(1)
end
end

0 comments on commit 10e5912

Please sign in to comment.