This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.1.0 | ||
2.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
ruby '2.1.0' | ||
ruby '2.1.2' | ||
|
||
gem 'rake' | ||
gem 'unicorn', '~> 4.6.2' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
module Shipr::Provider | ||
class Empire < Base | ||
attr_reader :empire_client, :registry | ||
|
||
def initialize(empire_client, registry) | ||
@empire_client = empire_client | ||
@registry = registry | ||
end | ||
|
||
def start(job) | ||
image_id = registry.resolve_tag(job.repo.name, job.sha) | ||
empire_client.create_deploy id: image_id, repo: job.repo.name | ||
end | ||
|
||
class EmpireClient | ||
attr_reader :url | ||
|
||
def initialize(url) | ||
@url = url | ||
end | ||
|
||
def create_deploy(image) | ||
connection.post '/v1/deploys', image: image | ||
end | ||
|
||
private | ||
|
||
def connection | ||
@connection ||= Faraday.new(url) do |builder| | ||
builder.request :json | ||
builder.response :json | ||
builder.adapter Faraday.default_adapter | ||
end | ||
end | ||
end | ||
|
||
class RegistryClient | ||
attr_reader :url, :auth | ||
|
||
def initialize(url, auth) | ||
@url = url || 'https://registry.hub.docker.com' | ||
@auth = auth | ||
end | ||
|
||
def resolve_tag(repo, tag) | ||
resp = connection.get "/v1/repositories/#{repo}/tags/#{tag}" | ||
resp.body.gsub(/^"(.*)"/, '\\1') | ||
end | ||
|
||
private | ||
|
||
def connection | ||
@connection ||= Faraday.new(url) do |builder| | ||
builder.request :json | ||
builder.adapter Faraday.default_adapter | ||
end.tap do |connection| | ||
connection.basic_auth(*auth.split(':')) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
require 'spec_helper' | ||
|
||
describe Shipr::Provider::Empire::EmpireClient do | ||
let(:client) { described_class.new 'https://empire.remind.com' } | ||
|
||
describe '#create_deploy' do | ||
it 'post a url' do | ||
stub_request(:post, 'https://empire.remind.com/v1/deploys').with( | ||
body: '{"image":{"id":"1234","repo":"remind101/r101-api"}}' | ||
) | ||
client.create_deploy id: '1234', repo: 'remind101/r101-api' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'spec_helper' | ||
|
||
describe Shipr::Provider::Empire::RegistryClient do | ||
let(:client) { described_class.new 'https://quay.io', 'foo:bar' } | ||
|
||
describe '#resolve_tag' do | ||
it 'resolves a tag to an image id' do | ||
stub_request(:get, 'https://foo:bar@quay.io/v1/repositories/remind101/r101-api/tags/af2a2').to_return( | ||
status: 200, | ||
body: '"abcdefg"' | ||
) | ||
image_id = client.resolve_tag 'remind101/r101-api', 'af2a2' | ||
expect(image_id).to eq 'abcdefg' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe Shipr::Provider::Empire do | ||
let(:empire_client) { double(Shipr::Provider::Empire::EmpireClient)} | ||
let(:registry_client) { double(Shipr::Provider::Empire::RegistryClient) } | ||
let(:service) { described_class.new empire_client, registry_client } | ||
|
||
describe '#start' do | ||
let(:repo) { Shipr::Repo.new name: 'remind101/r101-api' } | ||
let(:job) { Shipr::Job.new repo: repo, sha: 1234 } | ||
|
||
it 'creates a deploy task' do | ||
expect(registry_client).to receive(:resolve_tag).with('remind101/r101-api', '1234').and_return('abcdefg') | ||
expect(empire_client).to receive(:create_deploy).with(id: 'abcdefg', repo: 'remind101/r101-api') | ||
service.start(job) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind sucks that the docker registry produces invalid json. Go can parse this, but ruby's JSON can't by default, unless you specify
quirks_mode: true
, but the faraday middleware doesn't allow this to be provided very easily. Oh well.