Skip to content

Commit 333a247

Browse files
committed
first commit
0 parents  commit 333a247

File tree

18 files changed

+466
-0
lines changed

18 files changed

+466
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
/docker-distribution-api.iml

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--format documentation
2+
--color

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: ruby
2+
rvm:
3+
- 1.9.3
4+
before_install: gem install bundler -v 1.11.2

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in docker-distribution-api.gemspec
4+
gemspec

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Docker::Distribution::Api
2+
3+
Simple swipley/docker-api like API client for docker-distribution with limited support of endpoints
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'docker-distribution-api'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install docker-distribution-api
20+
21+
## Usage
22+
23+
API:
24+
25+
```ruby
26+
Docker::Distribution::Api.logger # to set your logger
27+
Docker::Distribution::Api.url= # set registry url
28+
Docker::Distribution::Api.options= # set registry connection options
29+
Docker::Distribution::Api.version # get registry version
30+
Docker::Distribution::Api.tags('test') # get tags for repository 'test'
31+
```
32+
33+
Manifest:
34+
35+
```ruby
36+
Docker::Distribution::Api.url='http://localhost:5000'
37+
Docker::Distribution::Api.options={:user => 'username', :password => 'password'} # basic auth
38+
manifest = Docker::Distribution::Api::Manifest.find_by_tag('repository', 'tag') # get manifest
39+
manifest.delete # delete manifest
40+
```
41+
42+
## Development
43+
44+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45+
46+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47+
48+
## Contributing
49+
50+
Bug reports and pull requests are welcome on GitHub at https://github.com/bazilio91/docker-distribution-api.
51+

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task :default => :spec

bin/console

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "docker/distribution/api"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

docker-distribution-api.gemspec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'docker/distribution/api/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = 'docker-distribution-api'
8+
spec.version = Docker::Distribution::Api::VERSION
9+
spec.authors = ['Vasily Ostanin']
10+
spec.email = ['bazilio91@gmail.com']
11+
12+
spec.summary = %q{API client for docker distribution.}
13+
spec.description = %q{docker-api like client for docker self-hosted registry (distribution).}
14+
spec.homepage = 'https://github.com/bazilio91/docker-distribution-api'
15+
spec.license = 'MIT'
16+
17+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18+
spec.bindir = 'exe'
19+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20+
spec.require_paths = ['lib']
21+
22+
spec.add_dependency 'excon', '>= 0.38.0'
23+
spec.add_development_dependency 'bundler', '~> 1.11'
24+
spec.add_development_dependency 'rake', '~> 10.0'
25+
spec.add_development_dependency 'rspec', '~> 3.0'
26+
end

lib/docker/distribution/api.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
require "docker/distribution/api/version"
2+
3+
module Docker
4+
module Distribution
5+
module Api
6+
attr_accessor :creds, :logger
7+
8+
require 'docker/distribution/api/version'
9+
require 'docker/distribution/api/connection'
10+
require 'docker/distribution/api/util'
11+
12+
def version(connection = self.connection)
13+
response = connection.get('/')
14+
response.headers['Docker-Distribution-Api-Version']
15+
end
16+
17+
def tags(repository, connection = self.connection)
18+
response = connection.get("/#{repository}/tags/list")
19+
Util.parse_json(response.body)['tags']
20+
end
21+
22+
def url
23+
@url ||= 'localhost:5000'
24+
end
25+
26+
def url=(new_url)
27+
@url = new_url
28+
reset_connection!
29+
end
30+
31+
def options
32+
@options ||= {}
33+
end
34+
35+
def options=(new_options)
36+
@options = @options.merge(new_options || {})
37+
reset_connection!
38+
end
39+
40+
def connection
41+
@connection ||= Connection.new(url, options)
42+
end
43+
44+
def reset_connection!
45+
@connection = nil
46+
end
47+
48+
module_function :url, :url=,
49+
:options, :options=,
50+
:connection, :reset_connection!,
51+
:logger, :logger=,
52+
:version, :tags
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)