1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #21949 from aaronlehmann/vendor-distribution-1622

Vendor distribution to correct config blob media type in schema2 manifest
This commit is contained in:
Brian Goff 2016-04-12 21:23:22 -04:00
commit 40502e3813
17 changed files with 134 additions and 113 deletions

View file

@ -17,7 +17,6 @@ import (
"github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/registry/api/errcode" "github.com/docker/distribution/registry/api/errcode"
"github.com/docker/distribution/registry/client"
"github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/auth"
"github.com/docker/distribution/registry/client/transport" "github.com/docker/distribution/registry/client/transport"
"github.com/docker/docker/distribution/metadata" "github.com/docker/docker/distribution/metadata"
@ -338,7 +337,7 @@ func (p *v2Puller) pullV2Tag(ctx context.Context, ref reference.Named) (tagUpdat
// NOTE: not using TagService.Get, since it uses HEAD requests // NOTE: not using TagService.Get, since it uses HEAD requests
// against the manifests endpoint, which are not supported by // against the manifests endpoint, which are not supported by
// all registry versions. // all registry versions.
manifest, err = manSvc.Get(ctx, "", client.WithTag(tagged.Tag())) manifest, err = manSvc.Get(ctx, "", distribution.WithTag(tagged.Tag()))
if err != nil { if err != nil {
return false, allowV1Fallback(err) return false, allowV1Fallback(err)
} }

View file

@ -166,7 +166,7 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, ima
return err return err
} }
putOptions := []distribution.ManifestServiceOption{client.WithTag(ref.Tag())} putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())}
if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil { if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil {
logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err) logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err)

View file

@ -49,7 +49,7 @@ clone git github.com/boltdb/bolt v1.2.0
clone git github.com/miekg/dns 75e6e86cc601825c5dbcd4e0c209eab180997cd7 clone git github.com/miekg/dns 75e6e86cc601825c5dbcd4e0c209eab180997cd7
# get graph and distribution packages # get graph and distribution packages
clone git github.com/docker/distribution d06d6d3b093302c02a93153ac7b06ebc0ffd1793 clone git github.com/docker/distribution 467fc068d88aa6610691b7f1a677271a3fac4aac
clone git github.com/vbatts/tar-split v0.9.11 clone git github.com/vbatts/tar-split v0.9.11
# get desired notary commit, might also need to be updated in Dockerfile # get desired notary commit, might also need to be updated in Dockerfile

View file

@ -1,38 +0,0 @@
image: dmp42/go:stable
script:
# To be spoofed back into the test image
- go get github.com/modocache/gover
- go get -t ./...
# Go fmt
- test -z "$(gofmt -s -l -w . | tee /dev/stderr)"
# Go lint
- test -z "$(golint ./... | tee /dev/stderr)"
# Go vet
- go vet ./...
# Go test
- go test -v -race -cover ./...
# Helper to concatenate reports
- gover
# Send to coverall
- goveralls -service drone.io -coverprofile=gover.coverprofile -repotoken {{COVERALLS_TOKEN}}
# Do we want these as well?
# - go get code.google.com/p/go.tools/cmd/goimports
# - test -z "$(goimports -l -w ./... | tee /dev/stderr)"
# http://labix.org/gocheck
notify:
email:
recipients:
- distribution@docker.com
slack:
team: docker
channel: "#dt"
username: mom
token: {{SLACK_TOKEN}}
on_success: true
on_failure: true

View file

@ -13,3 +13,4 @@ Sharif Nassar <sharif@mrwacky.com> Sharif Nassar <mrwacky42@users.noreply.github
Sven Dowideit <SvenDowideit@home.org.au> Sven Dowideit <SvenDowideit@users.noreply.github.com> Sven Dowideit <SvenDowideit@home.org.au> Sven Dowideit <SvenDowideit@users.noreply.github.com>
Vincent Giersch <vincent.giersch@ovh.net> Vincent Giersch <vincent@giersch.fr> Vincent Giersch <vincent.giersch@ovh.net> Vincent Giersch <vincent@giersch.fr>
davidli <wenquan.li@hp.com> davidli <wenquan.li@hpe.com> davidli <wenquan.li@hp.com> davidli <wenquan.li@hpe.com>
Omer Cohen <git@omer.io> Omer Cohen <git@omerc.net>

View file

@ -8,12 +8,15 @@ Alex Elman <aelman@indeed.com>
amitshukla <ashukla73@hotmail.com> amitshukla <ashukla73@hotmail.com>
Amy Lindburg <amy.lindburg@docker.com> Amy Lindburg <amy.lindburg@docker.com>
Andrew Meredith <andymeredith@gmail.com> Andrew Meredith <andymeredith@gmail.com>
Andrew T Nguyen <andrew.nguyen@docker.com>
Andrey Kostov <kostov.andrey@gmail.com> Andrey Kostov <kostov.andrey@gmail.com>
Andy Goldstein <agoldste@redhat.com> Andy Goldstein <agoldste@redhat.com>
Anton Tiurin <noxiouz@yandex.ru> Anton Tiurin <noxiouz@yandex.ru>
Antonio Mercado <amercado@thinknode.com> Antonio Mercado <amercado@thinknode.com>
Antonio Murdaca <runcom@redhat.com>
Arnaud Porterie <arnaud.porterie@docker.com> Arnaud Porterie <arnaud.porterie@docker.com>
Arthur Baars <arthur@semmle.com> Arthur Baars <arthur@semmle.com>
Asuka Suzuki <hello@tanksuzuki.com>
Avi Miller <avi.miller@oracle.com> Avi Miller <avi.miller@oracle.com>
Ayose Cazorla <ayosec@gmail.com> Ayose Cazorla <ayosec@gmail.com>
BadZen <dave.trombley@gmail.com> BadZen <dave.trombley@gmail.com>
@ -37,7 +40,9 @@ Diogo Mónica <diogo.monica@gmail.com>
DJ Enriquez <dj.enriquez@infospace.com> DJ Enriquez <dj.enriquez@infospace.com>
Donald Huang <don.hcd@gmail.com> Donald Huang <don.hcd@gmail.com>
Doug Davis <dug@us.ibm.com> Doug Davis <dug@us.ibm.com>
Eric Yang <windfarer@gmail.com>
farmerworking <farmerworking@gmail.com> farmerworking <farmerworking@gmail.com>
Felix Yan <felixonmars@archlinux.org>
Florentin Raud <florentin.raud@gmail.com> Florentin Raud <florentin.raud@gmail.com>
Frederick F. Kautz IV <fkautz@alumni.cmu.edu> Frederick F. Kautz IV <fkautz@alumni.cmu.edu>
gabriell nascimento <gabriell@bluesoft.com.br> gabriell nascimento <gabriell@bluesoft.com.br>
@ -45,29 +50,36 @@ harche <p.harshal@gmail.com>
Henri Gomez <henri.gomez@gmail.com> Henri Gomez <henri.gomez@gmail.com>
Hu Keping <hukeping@huawei.com> Hu Keping <hukeping@huawei.com>
Hua Wang <wanghua.humble@gmail.com> Hua Wang <wanghua.humble@gmail.com>
HuKeping <hukeping@huawei.com>
Ian Babrou <ibobrik@gmail.com> Ian Babrou <ibobrik@gmail.com>
igayoso <igayoso@gmail.com>
Jack Griffin <jackpg14@gmail.com> Jack Griffin <jackpg14@gmail.com>
Jason Freidman <jason.freidman@gmail.com> Jason Freidman <jason.freidman@gmail.com>
Jeff Nickoloff <jeff@allingeek.com> Jeff Nickoloff <jeff@allingeek.com>
Jessie Frazelle <jessie@docker.com> Jessie Frazelle <jessie@docker.com>
Jianqing Wang <tsing@jianqing.org> Jianqing Wang <tsing@jianqing.org>
John Starks <jostarks@microsoft.com>
Jon Poler <jonathan.poler@apcera.com> Jon Poler <jonathan.poler@apcera.com>
Jonathan Boulle <jonathanboulle@gmail.com> Jonathan Boulle <jonathanboulle@gmail.com>
Jordan Liggitt <jliggitt@redhat.com> Jordan Liggitt <jliggitt@redhat.com>
Josh Hawn <josh.hawn@docker.com> Josh Hawn <josh.hawn@docker.com>
Julien Fernandez <julien.fernandez@gmail.com> Julien Fernandez <julien.fernandez@gmail.com>
Keerthan Mala <kmala@engineyard.com>
Kelsey Hightower <kelsey.hightower@gmail.com> Kelsey Hightower <kelsey.hightower@gmail.com>
Kenneth Lim <kennethlimcp@gmail.com> Kenneth Lim <kennethlimcp@gmail.com>
Kenny Leung <kleung@google.com> Kenny Leung <kleung@google.com>
Li Yi <denverdino@gmail.com> Li Yi <denverdino@gmail.com>
Liu Hua <sdu.liu@huawei.com> Liu Hua <sdu.liu@huawei.com>
liuchang0812 <liuchang0812@gmail.com>
Louis Kottmann <louis.kottmann@gmail.com> Louis Kottmann <louis.kottmann@gmail.com>
Luke Carpenter <x@rubynerd.net> Luke Carpenter <x@rubynerd.net>
Mary Anthony <mary@docker.com> Mary Anthony <mary@docker.com>
Matt Bentley <mbentley@mbentley.net> Matt Bentley <mbentley@mbentley.net>
Matt Duch <matt@learnmetrics.com>
Matt Moore <mattmoor@google.com> Matt Moore <mattmoor@google.com>
Matt Robenolt <matt@ydekproductions.com> Matt Robenolt <matt@ydekproductions.com>
Michael Prokop <mika@grml.org> Michael Prokop <mika@grml.org>
Michal Minar <miminar@redhat.com>
Miquel Sabaté <msabate@suse.com> Miquel Sabaté <msabate@suse.com>
Morgan Bauer <mbauer@us.ibm.com> Morgan Bauer <mbauer@us.ibm.com>
moxiegirl <mary@docker.com> moxiegirl <mary@docker.com>
@ -78,6 +90,7 @@ Nuutti Kotivuori <nuutti.kotivuori@poplatek.fi>
Oilbeater <liumengxinfly@gmail.com> Oilbeater <liumengxinfly@gmail.com>
Olivier Gambier <olivier@docker.com> Olivier Gambier <olivier@docker.com>
Olivier Jacques <olivier.jacques@hp.com> Olivier Jacques <olivier.jacques@hp.com>
Omer Cohen <git@omer.io>
Patrick Devine <patrick.devine@docker.com> Patrick Devine <patrick.devine@docker.com>
Philip Misiowiec <philip@atlashealth.com> Philip Misiowiec <philip@atlashealth.com>
Richard Scothern <richard.scothern@docker.com> Richard Scothern <richard.scothern@docker.com>
@ -90,6 +103,7 @@ Shawn Falkner-Horine <dreadpirateshawn@gmail.com>
Shreyas Karnik <karnik.shreyas@gmail.com> Shreyas Karnik <karnik.shreyas@gmail.com>
Simon Thulbourn <simon+github@thulbourn.com> Simon Thulbourn <simon+github@thulbourn.com>
Spencer Rinehart <anubis@overthemonkey.com> Spencer Rinehart <anubis@overthemonkey.com>
Stefan Weil <sw@weilnetz.de>
Stephen J Day <stephen.day@docker.com> Stephen J Day <stephen.day@docker.com>
Sungho Moon <sungho.moon@navercorp.com> Sungho Moon <sungho.moon@navercorp.com>
Sven Dowideit <SvenDowideit@home.org.au> Sven Dowideit <SvenDowideit@home.org.au>
@ -111,3 +125,4 @@ xg.song <xg.song@venusource.com>
xiekeyang <xiekeyang@huawei.com> xiekeyang <xiekeyang@huawei.com>
Yann ROBERT <yann.robert@anantaplex.fr> Yann ROBERT <yann.robert@anantaplex.fr>
yuzou <zouyu7@huawei.com> yuzou <zouyu7@huawei.com>
姜继忠 <jizhong.jiangjz@alibaba-inc.com>

View file

@ -1,11 +1,10 @@
FROM golang:1.5.3 FROM golang:1.6
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y apache2-utils && \ apt-get install -y apache2-utils && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution
ENV GOPATH $DISTRIBUTION_DIR/Godeps/_workspace:$GOPATH
ENV DOCKER_BUILDTAGS include_oss include_gcs ENV DOCKER_BUILDTAGS include_oss include_gcs
WORKDIR $DISTRIBUTION_DIR WORKDIR $DISTRIBUTION_DIR

View file

@ -15,7 +15,7 @@ GO_LDFLAGS=-ldflags "-X `go list ./version`.Version=$(VERSION)"
.PHONY: clean all fmt vet lint build test binaries .PHONY: clean all fmt vet lint build test binaries
.DEFAULT: all .DEFAULT: all
all: fmt vet fmt lint build test binaries all: fmt vet lint build test binaries
AUTHORS: .mailmap .git/HEAD AUTHORS: .mailmap .git/HEAD
git log --format='%aN <%aE>' | sort -fu > $@ git log --format='%aN <%aE>' | sort -fu > $@
@ -24,51 +24,83 @@ AUTHORS: .mailmap .git/HEAD
version/version.go: version/version.go:
./version/version.sh > $@ ./version/version.sh > $@
${PREFIX}/bin/registry: version/version.go $(shell find . -type f -name '*.go') # Required for go 1.5 to build
GO15VENDOREXPERIMENT := 1
# Package list
PKGS := $(shell go list -tags "${DOCKER_BUILDTAGS}" ./... | grep -v ^github.com/docker/distribution/vendor/)
# Resolving binary dependencies for specific targets
GOLINT := $(shell which golint || echo '')
GODEP := $(shell which godep || echo '')
${PREFIX}/bin/registry: $(wildcard **/*.go)
@echo "+ $@" @echo "+ $@"
@go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/registry @go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/registry
${PREFIX}/bin/digest: version/version.go $(shell find . -type f -name '*.go') ${PREFIX}/bin/digest: $(wildcard **/*.go)
@echo "+ $@" @echo "+ $@"
@go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/digest @go build -tags "${DOCKER_BUILDTAGS}" -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/digest
${PREFIX}/bin/registry-api-descriptor-template: version/version.go $(shell find . -type f -name '*.go') ${PREFIX}/bin/registry-api-descriptor-template: $(wildcard **/*.go)
@echo "+ $@" @echo "+ $@"
@go build -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/registry-api-descriptor-template @go build -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./cmd/registry-api-descriptor-template
docs/spec/api.md: docs/spec/api.md.tmpl ${PREFIX}/bin/registry-api-descriptor-template docs/spec/api.md: docs/spec/api.md.tmpl ${PREFIX}/bin/registry-api-descriptor-template
./bin/registry-api-descriptor-template $< > $@ ./bin/registry-api-descriptor-template $< > $@
# Depends on binaries because vet will silently fail if it can't load compiled vet:
# imports
vet: binaries
@echo "+ $@" @echo "+ $@"
@go vet ./... @go vet -tags "${DOCKER_BUILDTAGS}" $(PKGS)
fmt: fmt:
@echo "+ $@" @echo "+ $@"
@test -z "$$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" || \ @test -z "$$(gofmt -s -l . 2>&1 | grep -v ^vendor/ | tee /dev/stderr)" || \
echo "+ please format Go code with 'gofmt -s'" (echo >&2 "+ please format Go code with 'gofmt -s'" && false)
lint: lint:
@echo "+ $@" @echo "+ $@"
@test -z "$$(golint ./... | grep -v Godeps/_workspace/src/ | tee /dev/stderr)" $(if $(GOLINT), , \
$(error Please install golint: `go get -u github.com/golang/lint/golint`))
@test -z "$$($(GOLINT) ./... 2>&1 | grep -v ^vendor/ | tee /dev/stderr)"
build: build:
@echo "+ $@" @echo "+ $@"
@go build -tags "${DOCKER_BUILDTAGS}" -v ${GO_LDFLAGS} ./... @go build -tags "${DOCKER_BUILDTAGS}" -v ${GO_LDFLAGS} $(PKGS)
test: test:
@echo "+ $@" @echo "+ $@"
@go test -test.short -tags "${DOCKER_BUILDTAGS}" ./... @go test -test.short -tags "${DOCKER_BUILDTAGS}" $(PKGS)
test-full: test-full:
@echo "+ $@" @echo "+ $@"
@go test ./... @go test -tags "${DOCKER_BUILDTAGS}" $(PKGS)
binaries: ${PREFIX}/bin/registry ${PREFIX}/bin/digest ${PREFIX}/bin/registry-api-descriptor-template binaries: ${PREFIX}/bin/registry ${PREFIX}/bin/digest ${PREFIX}/bin/registry-api-descriptor-template
@echo "+ $@" @echo "+ $@"
clean: clean:
@echo "+ $@" @echo "+ $@"
@rm -rf "${PREFIX}/bin/registry" "${PREFIX}/bin/registry-api-descriptor-template" @rm -rf "${PREFIX}/bin/registry" "${PREFIX}/bin/digest" "${PREFIX}/bin/registry-api-descriptor-template"
dep-save:
@echo "+ $@"
$(if $(GODEP), , \
$(error Please install godep: go get github.com/tools/godep))
@$(GODEP) save $(PKGS)
dep-restore:
@echo "+ $@"
$(if $(GODEP), , \
$(error Please install godep: go get github.com/tools/godep))
@$(GODEP) restore -v
dep-validate: dep-restore
@echo "+ $@"
@rm -Rf .vendor.bak
@mv vendor .vendor.bak
@rm -Rf Godeps
@$(GODEP) save ./...
@test -z "$$(diff -r vendor .vendor.bak 2>&1 | tee /dev/stderr)" || \
(echo >&2 "+ borked dependencies! what you have in Godeps/Godeps.json does not match with what you have in vendor" && false)
@rm -Rf .vendor.bak

View file

@ -17,7 +17,7 @@ This repository contains the following components:
|**Component** |Description | |**Component** |Description |
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **registry** | An implementation of the [Docker Registry HTTP API V2](docs/spec/api.md) for use with docker 1.6+. | | **registry** | An implementation of the [Docker Registry HTTP API V2](docs/spec/api.md) for use with docker 1.6+. |
| **libraries** | A rich set of libraries for interacting with,distribution components. Please see [godoc](https://godoc.org/github.com/docker/distribution) for details. **Note**: These libraries are **unstable**. | | **libraries** | A rich set of libraries for interacting with distribution components. Please see [godoc](https://godoc.org/github.com/docker/distribution) for details. **Note**: These libraries are **unstable**. |
| **specifications** | _Distribution_ related specifications are available in [docs/spec](docs/spec) | | **specifications** | _Distribution_ related specifications are available in [docs/spec](docs/spec) |
| **documentation** | Docker's full documentation set is available at [docs.docker.com](https://docs.docker.com). This repository [contains the subset](docs/index.md) related just to the registry. | | **documentation** | Docker's full documentation set is available at [docs.docker.com](https://docs.docker.com). This repository [contains the subset](docs/index.md) related just to the registry. |

View file

@ -8,7 +8,7 @@ machine:
post: post:
# go # go
- gvm install go1.5.3 --prefer-binary --name=stable - gvm install go1.6 --prefer-binary --name=stable
environment: environment:
# Convenient shortcuts to "common" locations # Convenient shortcuts to "common" locations
@ -49,26 +49,30 @@ test:
# - gvm use old && go version # - gvm use old && go version
- gvm use stable && go version - gvm use stable && go version
# Ensure validation of dependencies
- gvm use stable && if test -n "`git diff --stat=1000 master | grep -Ei \"vendor|godeps\"`"; then make dep-validate; fi:
pwd: $BASE_STABLE
# First thing: build everything. This will catch compile errors, and it's # First thing: build everything. This will catch compile errors, and it's
# also necessary for go vet to work properly (see #807). # also necessary for go vet to work properly (see #807).
- gvm use stable && godep go install ./...: - gvm use stable && godep go install $(go list ./... | grep -v "/vendor/"):
pwd: $BASE_STABLE pwd: $BASE_STABLE
# FMT # FMT
- gvm use stable && test -z "$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)": - gvm use stable && make fmt:
pwd: $BASE_STABLE pwd: $BASE_STABLE
# VET # VET
- gvm use stable && go vet ./...: - gvm use stable && make vet:
pwd: $BASE_STABLE pwd: $BASE_STABLE
# LINT # LINT
- gvm use stable && test -z "$(golint ./... | grep -v Godeps/_workspace/src/ | tee /dev/stderr)": - gvm use stable && make lint:
pwd: $BASE_STABLE pwd: $BASE_STABLE
override: override:
# Test stable, and report # Test stable, and report
- gvm use stable; export ROOT_PACKAGE=$(go list .); go list -tags "$DOCKER_BUILDTAGS" ./... | xargs -L 1 -I{} bash -c 'export PACKAGE={}; godep go test -tags "$DOCKER_BUILDTAGS" -test.short -coverprofile=$GOPATH/src/$PACKAGE/coverage.out -coverpkg=$(./coverpkg.sh $PACKAGE $ROOT_PACKAGE) $PACKAGE': - gvm use stable; export ROOT_PACKAGE=$(go list .); go list -tags "$DOCKER_BUILDTAGS" ./... | grep -v "/vendor/" | xargs -L 1 -I{} bash -c 'export PACKAGE={}; godep go test -tags "$DOCKER_BUILDTAGS" -test.short -coverprofile=$GOPATH/src/$PACKAGE/coverage.out -coverpkg=$(./coverpkg.sh $PACKAGE $ROOT_PACKAGE) $PACKAGE':
timeout: 600 timeout: 600
pwd: $BASE_STABLE pwd: $BASE_STABLE

View file

@ -8,25 +8,17 @@ import (
// since that time. If the key is not found, the value returned will be zero. // since that time. If the key is not found, the value returned will be zero.
// This is helpful when inferring metrics related to context execution times. // This is helpful when inferring metrics related to context execution times.
func Since(ctx Context, key interface{}) time.Duration { func Since(ctx Context, key interface{}) time.Duration {
startedAtI := ctx.Value(key) if startedAt, ok := ctx.Value(key).(time.Time); ok {
if startedAtI != nil { return time.Since(startedAt)
if startedAt, ok := startedAtI.(time.Time); ok {
return time.Since(startedAt)
}
} }
return 0 return 0
} }
// GetStringValue returns a string value from the context. The empty string // GetStringValue returns a string value from the context. The empty string
// will be returned if not found. // will be returned if not found.
func GetStringValue(ctx Context, key interface{}) (value string) { func GetStringValue(ctx Context, key interface{}) (value string) {
stringi := ctx.Value(key) if valuev, ok := ctx.Value(key).(string); ok {
if stringi != nil { value = valuev
if valuev, ok := stringi.(string); ok {
value = valuev
}
} }
return value return value
} }

View file

@ -3,5 +3,5 @@
# need to be passed to `go test -coverpkg`: this includes all of the # need to be passed to `go test -coverpkg`: this includes all of the
# subpackage's dependencies within the containing package, as well as the # subpackage's dependencies within the containing package, as well as the
# subpackage itself. # subpackage itself.
DEPENDENCIES="$(go list -f $'{{range $f := .Deps}}{{$f}}\n{{end}}' ${1} | grep ${2})" DEPENDENCIES="$(go list -f $'{{range $f := .Deps}}{{$f}}\n{{end}}' ${1} | grep ${2} | grep -v github.com/docker/distribution/vendor)"
echo "${1} ${DEPENDENCIES}" | xargs echo -n | tr ' ' ',' echo "${1} ${DEPENDENCIES}" | xargs echo -n | tr ' ' ','

View file

@ -47,11 +47,19 @@ type PlatformSpec struct {
// OS specifies the operating system, for example `linux` or `windows`. // OS specifies the operating system, for example `linux` or `windows`.
OS string `json:"os"` OS string `json:"os"`
// OSVersion is an optional field specifying the operating system
// version, for example `10.0.10586`.
OSVersion string `json:"os.version,omitempty"`
// OSFeatures is an optional field specifying an array of strings,
// each listing a required OS feature (for example on Windows `win32k`).
OSFeatures []string `json:"os.features,omitempty"`
// Variant is an optional field specifying a variant of the CPU, for // Variant is an optional field specifying a variant of the CPU, for
// example `ppc64le` to specify a little-endian version of a PowerPC CPU. // example `ppc64le` to specify a little-endian version of a PowerPC CPU.
Variant string `json:"variant,omitempty"` Variant string `json:"variant,omitempty"`
// Features is an optional field specifuing an array of strings, each // Features is an optional field specifying an array of strings, each
// listing a required CPU feature (for example `sse4` or `aes`). // listing a required CPU feature (for example `sse4` or `aes`).
Features []string `json:"features,omitempty"` Features []string `json:"features,omitempty"`
} }

View file

@ -55,6 +55,9 @@ func (mb *builder) Build(ctx context.Context) (distribution.Manifest, error) {
// Add config to the blob store // Add config to the blob store
m.Config, err = mb.bs.Put(ctx, MediaTypeConfig, mb.configJSON) m.Config, err = mb.bs.Put(ctx, MediaTypeConfig, mb.configJSON)
// Override MediaType, since Put always replaces the specified media
// type with application/octet-stream in the descriptor it returns.
m.Config.MediaType = MediaTypeConfig
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -58,6 +58,20 @@ type ManifestServiceOption interface {
Apply(ManifestService) error Apply(ManifestService) error
} }
// WithTag allows a tag to be passed into Put
func WithTag(tag string) ManifestServiceOption {
return WithTagOption{tag}
}
// WithTagOption holds a tag
type WithTagOption struct{ Tag string }
// Apply conforms to the ManifestServiceOption interface
func (o WithTagOption) Apply(m ManifestService) error {
// no implementation
return nil
}
// Repository is a named collection of manifests and layers. // Repository is a named collection of manifests and layers.
type Repository interface { type Repository interface {
// Named returns the name of the repository. // Named returns the name of the repository.

View file

@ -17,33 +17,35 @@ import (
// under "/foo/v2/...". Most application will only provide a schema, host and // under "/foo/v2/...". Most application will only provide a schema, host and
// port, such as "https://localhost:5000/". // port, such as "https://localhost:5000/".
type URLBuilder struct { type URLBuilder struct {
root *url.URL // url root (ie http://localhost/) root *url.URL // url root (ie http://localhost/)
router *mux.Router router *mux.Router
relative bool
} }
// NewURLBuilder creates a URLBuilder with provided root url object. // NewURLBuilder creates a URLBuilder with provided root url object.
func NewURLBuilder(root *url.URL) *URLBuilder { func NewURLBuilder(root *url.URL, relative bool) *URLBuilder {
return &URLBuilder{ return &URLBuilder{
root: root, root: root,
router: Router(), router: Router(),
relative: relative,
} }
} }
// NewURLBuilderFromString workes identically to NewURLBuilder except it takes // NewURLBuilderFromString workes identically to NewURLBuilder except it takes
// a string argument for the root, returning an error if it is not a valid // a string argument for the root, returning an error if it is not a valid
// url. // url.
func NewURLBuilderFromString(root string) (*URLBuilder, error) { func NewURLBuilderFromString(root string, relative bool) (*URLBuilder, error) {
u, err := url.Parse(root) u, err := url.Parse(root)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return NewURLBuilder(u), nil return NewURLBuilder(u, relative), nil
} }
// NewURLBuilderFromRequest uses information from an *http.Request to // NewURLBuilderFromRequest uses information from an *http.Request to
// construct the root url. // construct the root url.
func NewURLBuilderFromRequest(r *http.Request) *URLBuilder { func NewURLBuilderFromRequest(r *http.Request, relative bool) *URLBuilder {
var scheme string var scheme string
forwardedProto := r.Header.Get("X-Forwarded-Proto") forwardedProto := r.Header.Get("X-Forwarded-Proto")
@ -85,7 +87,7 @@ func NewURLBuilderFromRequest(r *http.Request) *URLBuilder {
u.Path = requestPath[0 : index+1] u.Path = requestPath[0 : index+1]
} }
return NewURLBuilder(u) return NewURLBuilder(u, relative)
} }
// BuildBaseURL constructs a base url for the API, typically just "/v2/". // BuildBaseURL constructs a base url for the API, typically just "/v2/".
@ -194,12 +196,13 @@ func (ub *URLBuilder) cloneRoute(name string) clonedRoute {
*route = *ub.router.GetRoute(name) // clone the route *route = *ub.router.GetRoute(name) // clone the route
*root = *ub.root *root = *ub.root
return clonedRoute{Route: route, root: root} return clonedRoute{Route: route, root: root, relative: ub.relative}
} }
type clonedRoute struct { type clonedRoute struct {
*mux.Route *mux.Route
root *url.URL root *url.URL
relative bool
} }
func (cr clonedRoute) URL(pairs ...string) (*url.URL, error) { func (cr clonedRoute) URL(pairs ...string) (*url.URL, error) {
@ -208,6 +211,10 @@ func (cr clonedRoute) URL(pairs ...string) (*url.URL, error) {
return nil, err return nil, err
} }
if cr.relative {
return routeURL, nil
}
if routeURL.Scheme == "" && routeURL.User == nil && routeURL.Host == "" { if routeURL.Scheme == "" && routeURL.User == nil && routeURL.Host == "" {
routeURL.Path = routeURL.Path[1:] routeURL.Path = routeURL.Path[1:]
} }

View file

@ -62,7 +62,7 @@ func checkHTTPRedirect(req *http.Request, via []*http.Request) error {
// NewRegistry creates a registry namespace which can be used to get a listing of repositories // NewRegistry creates a registry namespace which can be used to get a listing of repositories
func NewRegistry(ctx context.Context, baseURL string, transport http.RoundTripper) (Registry, error) { func NewRegistry(ctx context.Context, baseURL string, transport http.RoundTripper) (Registry, error) {
ub, err := v2.NewURLBuilderFromString(baseURL) ub, err := v2.NewURLBuilderFromString(baseURL, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -133,7 +133,7 @@ func (r *registry) Repositories(ctx context.Context, entries []string, last stri
// NewRepository creates a new Repository for the given repository name and base URL. // NewRepository creates a new Repository for the given repository name and base URL.
func NewRepository(ctx context.Context, name reference.Named, baseURL string, transport http.RoundTripper) (distribution.Repository, error) { func NewRepository(ctx context.Context, name reference.Named, baseURL string, transport http.RoundTripper) (distribution.Repository, error) {
ub, err := v2.NewURLBuilderFromString(baseURL) ub, err := v2.NewURLBuilderFromString(baseURL, false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -402,9 +402,9 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis
) )
for _, option := range options { for _, option := range options {
if opt, ok := option.(withTagOption); ok { if opt, ok := option.(distribution.WithTagOption); ok {
digestOrTag = opt.tag digestOrTag = opt.Tag
ref, err = reference.WithTag(ms.name, opt.tag) ref, err = reference.WithTag(ms.name, opt.Tag)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -465,21 +465,6 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis
return nil, HandleErrorResponse(resp) return nil, HandleErrorResponse(resp)
} }
// WithTag allows a tag to be passed into Put which enables the client
// to build a correct URL.
func WithTag(tag string) distribution.ManifestServiceOption {
return withTagOption{tag}
}
type withTagOption struct{ tag string }
func (o withTagOption) Apply(m distribution.ManifestService) error {
if _, ok := m.(*manifests); ok {
return nil
}
return fmt.Errorf("withTagOption is a client-only option")
}
// Put puts a manifest. A tag can be specified using an options parameter which uses some shared state to hold the // Put puts a manifest. A tag can be specified using an options parameter which uses some shared state to hold the
// tag name in order to build the correct upload URL. // tag name in order to build the correct upload URL.
func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) { func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options ...distribution.ManifestServiceOption) (digest.Digest, error) {
@ -487,9 +472,9 @@ func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options .
var tagged bool var tagged bool
for _, option := range options { for _, option := range options {
if opt, ok := option.(withTagOption); ok { if opt, ok := option.(distribution.WithTagOption); ok {
var err error var err error
ref, err = reference.WithTag(ref, opt.tag) ref, err = reference.WithTag(ref, opt.Tag)
if err != nil { if err != nil {
return "", err return "", err
} }