Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: distribution/distribution
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.8.1
Choose a base ref
...
head repository: distribution/distribution
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.8.2
Choose a head ref

Commits on May 26, 2022

  1. Fix CVE-2022-28391 by bumping alpine from 3.15 to 3.16

    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit 9f2bc25)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    silvin-lubecki authored and thaJeztah committed May 26, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    38018ae View commit details
  2. Merge pull request #3650 from thaJeztah/2.8_bump_alpine

    [release/2.8 backport] Fix CVE-2022-28391 by bumping alpine from 3.14 to 3.16
    deleteriousEffect authored May 26, 2022
    Copy the full SHA
    dc5b207 View commit details

Commits on Dec 4, 2022

  1. Fix panic in inmemory driver

    Signed-off-by: Shengjing Zhu <zhsj@debian.org>
    zhsj authored and wy65701436 committed Dec 4, 2022
    Copy the full SHA
    ad5991d View commit details

Commits on Apr 17, 2023

  1. Merge pull request #3815 from wy65701436/release/2.8-cp-3615

    [release/2.8] Fix panic in inmemory driver
    milosgajdos authored Apr 17, 2023
    Copy the full SHA
    82d6c3d View commit details

Commits on Apr 24, 2023

  1. Fix runaway allocation on /v2/_catalog

    Introduced a Catalog entry in the configuration struct. With it,
    it's possible to control the maximum amount of entries returned
    by /v2/catalog (`GetCatalog` in registry/handlers/catalog.go).
    
    It's set to a default value of 1000.
    
    `GetCatalog` returns 100 entries by default if no `n` is
    provided. When provided it will be validated to be between `0`
    and `MaxEntries` defined in Configuration. When `n` is outside
    the aforementioned boundary, ErrorCodePaginationNumberInvalid is
    returned.
    
    `GetCatalog` now handles `n=0` gracefully with an empty response
    as well.
    
    Signed-off-by: José D. Gómez R. <1josegomezr@gmail.com>
    Co-authored-by: Cory Snider <corhere@gmail.com>
    josegomezr and corhere committed Apr 24, 2023
    Copy the full SHA
    521ea3d View commit details

Commits on May 9, 2023

  1. Merge pull request #2815 from bainsy88/issue_2814

    Add code to handle pagination of parts. Fixes max layer size of 10GB bug
    
    Signed-off-by: David van der Spek <vanderspek.david@gmail.com>
    dmcgowan authored and davidspek committed May 9, 2023
    Copy the full SHA
    1d52366 View commit details
  2. fix(ci): use go install instead of go get

    Signed-off-by: David van der Spek <vanderspek.david@gmail.com>
    davidspek committed May 9, 2023
    Copy the full SHA
    22a8050 View commit details
  3. [release/2.8] fix package name in Dockerfile

    The 2.8 release is still named github.com/docker/distribution.
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed May 9, 2023
    Copy the full SHA
    092a219 View commit details
  4. bump up golang v1.17

    Signed-off-by: Wang Yan <wangyan@vmware.com>
    (cherry picked from commit 3f4c558)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    wy65701436 authored and thaJeztah committed May 9, 2023
    Copy the full SHA
    2392893 View commit details
  5. Dockerfile: switch to xx

    Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
    (cherry picked from commit 87f93ed)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    crazy-max authored and thaJeztah committed May 9, 2023
    Copy the full SHA
    14bd72b View commit details
  6. Update to xx 1.1.1

    Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
    (cherry picked from commit 52a88c5)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    crazy-max authored and thaJeztah committed May 9, 2023
    Copy the full SHA
    19b3feb View commit details
  7. dockerfiles: set ALPINE_VERSION

    Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
    (cherry picked from commit b066451)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    crazy-max authored and thaJeztah committed May 9, 2023
    Copy the full SHA
    018472d View commit details
  8. dockerfiles: formatting

    Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
    (cherry picked from commit 0e17e54)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    crazy-max authored and thaJeztah committed May 9, 2023
    Copy the full SHA
    db1389e View commit details
  9. bump up golang version

    upgrade go version to v1.18.8
    
    Signed-off-by: Wang Yan <wangyan@vmware.com>
    wy65701436 authored and thaJeztah committed May 9, 2023
    Copy the full SHA
    70db3a4 View commit details
  10. Merge pull request #3903 from thaJeztah/2.8_bump_go_118

    [release/2.8] bump up golang version (alternative)
    milosgajdos authored May 9, 2023
    Copy the full SHA
    d3fac54 View commit details
  11. Dockerfile: update xx to v1.2.1

    full diff: tonistiigi/xx@v1.1.1...v1.2.1
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit 8c4d2b9)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed May 9, 2023
    Copy the full SHA
    3d8f3cc View commit details
  12. Merge pull request #3907 from thaJeztah/2.8_backport_update_xx

    [release/2.8 backport] Dockerfile: update xx to v1.2.1
    milosgajdos authored May 9, 2023
    Copy the full SHA
    b791fdc View commit details
  13. [release/2.8] ignore deprecation of io/ioutil

    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed May 9, 2023
    Copy the full SHA
    9c04409 View commit details
  14. update to go1.19.9

    Added back minor versions in these, so that we have a somewhat more
    reproducible state in the repository when tagging releases.
    
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit 322eb4e)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed May 9, 2023
    Copy the full SHA
    3f2a4e2 View commit details
  15. Fix gofmt warnings

    Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
    milosgajdos committed May 9, 2023
    Copy the full SHA
    ae58bde View commit details
  16. Merge pull request #3908 from thaJeztah/2.8_backport_bump_go1.19.9

    [release/2.8 backport] update to go1.19.9
    milosgajdos authored May 9, 2023
    Copy the full SHA
    4a35c45 View commit details
  17. Merge pull request #3893 from pluralsh/part-pagination

    [release/2.8] Add code to handle pagination of parts. Fixes max layer size of 10GB bug
    milosgajdos authored May 9, 2023
    Copy the full SHA
    08f5645 View commit details
  18. Merge pull request from GHSA-hqxw-f8mx-cpmw

    [release/2.8] Fix runaway allocation on /v2/_catalog
    milosgajdos authored May 9, 2023
    Copy the full SHA
    dcb637d View commit details
  19. Add 2.8.2-beta.1 release notes

    Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
    milosgajdos committed May 9, 2023
    Copy the full SHA
    ac6c72b View commit details
  20. Merge pull request #3909 from distribution/2.8.2-beta-release-notes

    Add 2.8.2-beta.1 release notes
    milosgajdos authored May 9, 2023
    Copy the full SHA
    963c199 View commit details
  21. Dockerfile: fix filenames of artifacts

    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    (cherry picked from commit 435c7b9)
    Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    thaJeztah committed May 9, 2023
    Copy the full SHA
    e884644 View commit details
  22. Merge pull request #3911 from thaJeztah/2.8_backport_fix_releaser_fil…

    …enames
    
    [release/2.8 backport] Dockerfile: fix filenames of artifacts
    milosgajdos authored May 9, 2023
    Copy the full SHA
    cb840f6 View commit details
  23. Add release notes for 2.8.2-beta.2 release

    Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
    milosgajdos committed May 9, 2023
    Copy the full SHA
    5f3ca1b View commit details
  24. Merge pull request #3912 from distribution/2.8.2-beta.2-release-notes

    Add 2.8.2 beta.2 release notes
    milosgajdos authored May 9, 2023
    Copy the full SHA
    320d6a1 View commit details

Commits on May 10, 2023

  1. Revert "registry/client: set Accept: identity header when getting lay…

    …ers"
    
    This reverts commit 16f086a.
    
    Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
    ndeloof authored and thaJeztah committed May 10, 2023
    Copy the full SHA
    2b0f84d View commit details

Commits on May 11, 2023

  1. registry/errors: Parse http forbidden as denied

    Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
    (cherry picked from commit 5f1df02)
    Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
    vvoland committed May 11, 2023
    Copy the full SHA
    483ad69 View commit details
  2. Merge pull request #3783 from ndeloof/accept-encoding-28

    [release/2.8 backport] revert "registry/client: set Accept: identity header when getting layers
    milosgajdos authored May 11, 2023
    Copy the full SHA
    f067f66 View commit details
  3. Merge pull request #3914 from vvoland/handle-forbidden-28

    [release/2.8 backport] registry/errors: Parse http forbidden as denied
    milosgajdos authored May 11, 2023
    Copy the full SHA
    4894d35 View commit details
  4. Add v2.8.2 release notes

    Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
    milosgajdos committed May 11, 2023
    Copy the full SHA
    a173a9c View commit details
  5. Merge pull request #3915 from distribution/2.8.2-release-notes

    Add v2.8.2 release notes
    milosgajdos authored May 11, 2023
    Copy the full SHA
    7c354a4 View commit details
Showing with 695 additions and 275 deletions.
  1. +1 −0 .dockerignore
  2. +0 −1 .github/workflows/build.yml
  3. +4 −4 .github/workflows/ci.yml
  4. +7 −0 .golangci.yml
  5. +4 −2 .mailmap
  6. +44 −34 Dockerfile
  7. +1 −1 Makefile
  8. +1 −1 cmd/registry-api-descriptor-template/main.go
  9. +18 −2 configuration/configuration.go
  10. +4 −0 configuration/configuration_test.go
  11. +16 −16 context/doc.go
  12. +1 −5 context/http.go
  13. +6 −6 context/trace.go
  14. +6 −15 docker-bake.hcl
  15. +39 −39 health/doc.go
  16. +1 −1 project/dev-image/Dockerfile
  17. +2 −2 reference/reference.go
  18. +17 −0 registry/api/v2/descriptors.go
  19. +9 −0 registry/api/v2/errors.go
  20. +16 −17 registry/auth/auth.go
  21. +9 −7 registry/auth/token/token.go
  22. +4 −4 registry/auth/token/token_test.go
  23. +2 −0 registry/client/errors.go
  24. +15 −0 registry/client/errors_test.go
  25. +1 −3 registry/client/repository.go
  26. +0 −1 registry/client/transport/http_reader.go
  27. +288 −28 registry/handlers/api_test.go
  28. +1 −0 registry/handlers/basicauth.go
  29. +1 −0 registry/handlers/basicauth_prego14.go
  30. +41 −13 registry/handlers/catalog.go
  31. +1 −0 registry/storage/blobwriter_nonresumable.go
  32. +1 −0 registry/storage/blobwriter_resumable.go
  33. +10 −10 registry/storage/driver/base/base.go
  34. +1 −1 registry/storage/driver/base/regulator.go
  35. +1 −0 registry/storage/driver/gcs/gcs.go
  36. +1 −0 registry/storage/driver/gcs/gcs_test.go
  37. +3 −0 registry/storage/driver/inmemory/mfs.go
  38. +3 −2 registry/storage/driver/middleware/cloudfront/middleware.go
  39. +1 −0 registry/storage/driver/oss/oss.go
  40. +1 −0 registry/storage/driver/oss/oss_test.go
  41. +17 −8 registry/storage/driver/s3-aws/s3.go
  42. +1 −1 registry/storage/ocimanifesthandler.go
  43. +40 −41 registry/storage/paths.go
  44. +1 −1 registry/storage/schema2manifesthandler.go
  45. +46 −0 releases/v2.8.2.toml
  46. +3 −3 script/setup/install-dev-tools
  47. +1 −1 script/validate/dco
  48. +2 −3 version/print.go
  49. +1 −1 version/version.go
  50. +1 −1 version/version.sh
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -87,7 +87,6 @@ jobs:
draft: true
files: |
bin/*.tar.gz
bin/*.zip
bin/*.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -25,26 +25,26 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.*
go-version: 1.19.9

- name: Dependencies
run: |
sudo apt-get -q update
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install python2-minimal
cd /tmp && go get -u github.com/vbatts/git-validation
cd /tmp && go install github.com/vbatts/git-validation@latest
- name: Build
working-directory: ./src/github.com/docker/distribution
run: |
DCO_VERBOSITY=-q script/validate/dco
GO111MODULE=on script/setup/install-dev-tools
script/validate/vendor
go build -i .
go build .
make check
make build
make binaries
if [ "$GOOS" = "linux" ]; then make coverage ; fi
- uses: codecov/codecov-action@v1
with:
directory: ./src/github.com/docker/distribution
directory: ./src/github.com/docker/distribution
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -18,3 +18,10 @@ run:
deadline: 2m
skip-dirs:
- vendor

issues:
exclude-rules:
# io/ioutil is deprecated, but won't be removed until Go v2. It's safe to ignore for the release/2.8 branch.
- text: "SA1019: \"io/ioutil\" has been deprecated since Go 1.16"
linters:
- staticcheck
6 changes: 4 additions & 2 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ Thomas Berger <loki@lokis-chaos.de> Thomas Berger <tbe@users.noreply.github.com>
Samuel Karp <skarp@amazon.com> Samuel Karp <samuelkarp@users.noreply.github.com>
Justin Cormack <justin.cormack@docker.com>
sayboras <sayboras@yahoo.com>
CrazyMax <github@crazymax.dev>
CrazyMax <github@crazymax.dev> <1951866+crazy-max@users.noreply.github.com>
CrazyMax <github@crazymax.dev> <crazy-max@users.noreply.github.com>
Hayley Swimelar <hswimelar@gmail.com>
Jose D. Gomez R <jose.gomez@suse.com>
Shengjing Zhu <zhsj@debian.org>
Silvin Lubecki <31478878+silvin-lubecki@users.noreply.github.com>
78 changes: 44 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,49 +1,59 @@
# syntax=docker/dockerfile:1.3
# syntax=docker/dockerfile:1

ARG GO_VERSION=1.16.15
ARG GORELEASER_XX_VERSION=1.2.5
ARG GO_VERSION=1.19.9
ARG ALPINE_VERSION=3.16
ARG XX_VERSION=1.2.1

FROM --platform=$BUILDPLATFORM crazymax/goreleaser-xx:${GORELEASER_XX_VERSION} AS goreleaser-xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
COPY --from=goreleaser-xx / /
RUN apk add --no-cache file git
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
COPY --from=xx / /
RUN apk add --no-cache bash coreutils file git
ENV GO111MODULE=auto
ENV CGO_ENABLED=0
WORKDIR /go/src/github.com/docker/distribution

FROM base AS version
ARG PKG="github.com/docker/distribution"
RUN --mount=target=. \
VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \
echo "-X ${PKG}/version.Version=${VERSION#v} -X ${PKG}/version.Revision=${REVISION} -X ${PKG}/version.Package=${PKG}" | tee /tmp/.ldflags; \
echo -n "${VERSION}" | tee /tmp/.version;

FROM base AS build
ENV GO111MODULE=auto
ENV CGO_ENABLED=0
# GIT_REF is used by goreleaser-xx to handle the proper git ref when available.
# It will fallback to the working tree info if empty and use "git tag --points-at"
# or "git describe" to define the version info.
ARG GIT_REF
ARG TARGETPLATFORM
ARG PKG="github.com/distribution/distribution"
ARG LDFLAGS="-s -w"
ARG BUILDTAGS="include_oss include_gcs"
RUN --mount=type=bind,rw \
--mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \
goreleaser-xx --debug \
--name="registry" \
--dist="/out" \
--main="./cmd/registry" \
--flags="-v" \
--ldflags="-s -w -X '$PKG/version.Version={{.Version}}' -X '$PKG/version.Revision={{.Commit}}' -X '$PKG/version.Package=$PKG'" \
--tags="$BUILDTAGS" \
--files="LICENSE" \
--files="README.md"

FROM scratch AS artifact
COPY --from=build /out/*.tar.gz /
COPY --from=build /out/*.zip /
COPY --from=build /out/*.sha256 /
RUN --mount=type=bind,target=/go/src/github.com/docker/distribution,rw \
--mount=type=cache,target=/root/.cache/go-build \
--mount=target=/go/pkg/mod,type=cache \
--mount=type=bind,source=/tmp/.ldflags,target=/tmp/.ldflags,from=version \
set -x ; xx-go build -trimpath -ldflags "$(cat /tmp/.ldflags) ${LDFLAGS}" -o /usr/bin/registry ./cmd/registry \
&& xx-verify --static /usr/bin/registry

FROM scratch AS binary
COPY --from=build /usr/local/bin/registry* /
COPY --from=build /usr/bin/registry /

FROM base AS releaser
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
WORKDIR /work
RUN --mount=from=binary,target=/build \
--mount=type=bind,target=/src \
--mount=type=bind,source=/tmp/.version,target=/tmp/.version,from=version \
VERSION=$(cat /tmp/.version) \
&& mkdir -p /out \
&& cp /build/registry /src/README.md /src/LICENSE . \
&& tar -czvf "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.gz" * \
&& sha256sum -z "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.gz" | awk '{ print $1 }' > "/out/registry_${VERSION#v}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}.tar.gz.sha256"

FROM scratch AS artifact
COPY --from=releaser /out /

FROM alpine:3.14
FROM alpine:${ALPINE_VERSION}
RUN apk add --no-cache ca-certificates
COPY cmd/registry/config-dev.yml /etc/docker/registry/config.yml
COPY --from=build /usr/local/bin/registry /bin/registry
COPY --from=binary /registry /bin/registry
VOLUME ["/var/lib/registry"]
EXPOSE 5000
ENTRYPOINT ["registry"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ version/version.go:

check: ## run all linters (TODO: enable "unused", "varcheck", "ineffassign", "unconvert", "staticheck", "goimports", "structcheck")
@echo "$(WHALE) $@"
golangci-lint run
@GO111MODULE=off golangci-lint run

test: ## run tests, except integration test with test.short
@echo "$(WHALE) $@"
2 changes: 1 addition & 1 deletion cmd/registry-api-descriptor-template/main.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
// For example, to generate a new API specification, one would execute the
// following command from the repo root:
//
// $ registry-api-descriptor-template docs/spec/api.md.tmpl > docs/spec/api.md
// $ registry-api-descriptor-template docs/spec/api.md.tmpl > docs/spec/api.md
//
// The templates are passed in the api/v2.APIDescriptor object. Please see the
// package documentation for fields available on that object. The template
20 changes: 18 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
@@ -193,7 +193,8 @@ type Configuration struct {
} `yaml:"pool,omitempty"`
} `yaml:"redis,omitempty"`

Health Health `yaml:"health,omitempty"`
Health Health `yaml:"health,omitempty"`
Catalog Catalog `yaml:"catalog,omitempty"`

Proxy Proxy `yaml:"proxy,omitempty"`

@@ -244,6 +245,16 @@ type Configuration struct {
} `yaml:"policy,omitempty"`
}

// Catalog is composed of MaxEntries.
// Catalog endpoint (/v2/_catalog) configuration, it provides the configuration
// options to control the maximum number of entries returned by the catalog endpoint.
type Catalog struct {
// Max number of entries returned by the catalog endpoint. Requesting n entries
// to the catalog endpoint will return at most MaxEntries entries.
// An empty or a negative value will set a default of 1000 maximum entries by default.
MaxEntries int `yaml:"maxentries,omitempty"`
}

// LogHook is composed of hook Level and Type.
// After hooks configuration, it can execute the next handling automatically,
// when defined levels of log message emitted.
@@ -584,7 +595,7 @@ type Events struct {
IncludeReferences bool `yaml:"includereferences"` // include reference data in manifest events
}

//Ignore configures mediaTypes and actions of the event, that it won't be propagated
// Ignore configures mediaTypes and actions of the event, that it won't be propagated
type Ignore struct {
MediaTypes []string `yaml:"mediatypes"` // target media types to ignore
Actions []string `yaml:"actions"` // ignore action types
@@ -670,6 +681,11 @@ func Parse(rd io.Reader) (*Configuration, error) {
if v0_1.Loglevel != Loglevel("") {
v0_1.Loglevel = Loglevel("")
}

if v0_1.Catalog.MaxEntries <= 0 {
v0_1.Catalog.MaxEntries = 1000
}

if v0_1.Storage.Type() == "" {
return nil, errors.New("no storage configuration provided")
}
4 changes: 4 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
@@ -71,6 +71,9 @@ var configStruct = Configuration{
},
},
},
Catalog: Catalog{
MaxEntries: 1000,
},
HTTP: struct {
Addr string `yaml:"addr,omitempty"`
Net string `yaml:"net,omitempty"`
@@ -524,6 +527,7 @@ func copyConfig(config Configuration) *Configuration {
configCopy.Version = MajorMinorVersion(config.Version.Major(), config.Version.Minor())
configCopy.Loglevel = config.Loglevel
configCopy.Log = config.Log
configCopy.Catalog = config.Catalog
configCopy.Log.Fields = make(map[string]interface{}, len(config.Log.Fields))
for k, v := range config.Log.Fields {
configCopy.Log.Fields[k] = v
32 changes: 16 additions & 16 deletions context/doc.go
Original file line number Diff line number Diff line change
@@ -4,82 +4,82 @@
//
// The easiest way to get started is to get the background context:
//
// ctx := context.Background()
// ctx := context.Background()
//
// The returned context should be passed around your application and be the
// root of all other context instances. If the application has a version, this
// line should be called before anything else:
//
// ctx := context.WithVersion(context.Background(), version)
// ctx := context.WithVersion(context.Background(), version)
//
// The above will store the version in the context and will be available to
// the logger.
//
// Logging
// # Logging
//
// The most useful aspect of this package is GetLogger. This function takes
// any context.Context interface and returns the current logger from the
// context. Canonical usage looks like this:
//
// GetLogger(ctx).Infof("something interesting happened")
// GetLogger(ctx).Infof("something interesting happened")
//
// GetLogger also takes optional key arguments. The keys will be looked up in
// the context and reported with the logger. The following example would
// return a logger that prints the version with each log message:
//
// ctx := context.Context(context.Background(), "version", version)
// GetLogger(ctx, "version").Infof("this log message has a version field")
// ctx := context.Context(context.Background(), "version", version)
// GetLogger(ctx, "version").Infof("this log message has a version field")
//
// The above would print out a log message like this:
//
// INFO[0000] this log message has a version field version=v2.0.0-alpha.2.m
// INFO[0000] this log message has a version field version=v2.0.0-alpha.2.m
//
// When used with WithLogger, we gain the ability to decorate the context with
// loggers that have information from disparate parts of the call stack.
// Following from the version example, we can build a new context with the
// configured logger such that we always print the version field:
//
// ctx = WithLogger(ctx, GetLogger(ctx, "version"))
// ctx = WithLogger(ctx, GetLogger(ctx, "version"))
//
// Since the logger has been pushed to the context, we can now get the version
// field for free with our log messages. Future calls to GetLogger on the new
// context will have the version field:
//
// GetLogger(ctx).Infof("this log message has a version field")
// GetLogger(ctx).Infof("this log message has a version field")
//
// This becomes more powerful when we start stacking loggers. Let's say we
// have the version logger from above but also want a request id. Using the
// context above, in our request scoped function, we place another logger in
// the context:
//
// ctx = context.WithValue(ctx, "http.request.id", "unique id") // called when building request context
// ctx = WithLogger(ctx, GetLogger(ctx, "http.request.id"))
// ctx = context.WithValue(ctx, "http.request.id", "unique id") // called when building request context
// ctx = WithLogger(ctx, GetLogger(ctx, "http.request.id"))
//
// When GetLogger is called on the new context, "http.request.id" will be
// included as a logger field, along with the original "version" field:
//
// INFO[0000] this log message has a version field http.request.id=unique id version=v2.0.0-alpha.2.m
// INFO[0000] this log message has a version field http.request.id=unique id version=v2.0.0-alpha.2.m
//
// Note that this only affects the new context, the previous context, with the
// version field, can be used independently. Put another way, the new logger,
// added to the request context, is unique to that context and can have
// request scoped variables.
//
// HTTP Requests
// # HTTP Requests
//
// This package also contains several methods for working with http requests.
// The concepts are very similar to those described above. We simply place the
// request in the context using WithRequest. This makes the request variables
// available. GetRequestLogger can then be called to get request specific
// variables in a log line:
//
// ctx = WithRequest(ctx, req)
// GetRequestLogger(ctx).Infof("request variables")
// ctx = WithRequest(ctx, req)
// GetRequestLogger(ctx).Infof("request variables")
//
// Like above, if we want to include the request data in all log messages in
// the context, we push the logger to a new context and use that one:
//
// ctx = WithLogger(ctx, GetRequestLogger(ctx))
// ctx = WithLogger(ctx, GetRequestLogger(ctx))
//
// The concept is fairly powerful and ensures that calls throughout the stack
// can be traced in log messages. Using the fields like "http.request.id", one
6 changes: 1 addition & 5 deletions context/http.go
Original file line number Diff line number Diff line change
@@ -246,11 +246,7 @@ func (ctx *muxVarsContext) Value(key interface{}) interface{} {
return ctx.vars
}

if strings.HasPrefix(keyStr, "vars.") {
keyStr = strings.TrimPrefix(keyStr, "vars.")
}

if v, ok := ctx.vars[keyStr]; ok {
if v, ok := ctx.vars[strings.TrimPrefix(keyStr, "vars.")]; ok {
return v
}
}
12 changes: 6 additions & 6 deletions context/trace.go
Original file line number Diff line number Diff line change
@@ -24,16 +24,16 @@ import (
//
// Here is an example of the usage:
//
// func timedOperation(ctx Context) {
// ctx, done := WithTrace(ctx)
// defer done("this will be the log message")
// // ... function body ...
// }
// func timedOperation(ctx Context) {
// ctx, done := WithTrace(ctx)
// defer done("this will be the log message")
// // ... function body ...
// }
//
// If the function ran for roughly 1s, such a usage would emit a log message
// as follows:
//
// INFO[0001] this will be the log message trace.duration=1.004575763s trace.func=github.com/docker/distribution/context.traceOperation trace.id=<id> ...
// INFO[0001] this will be the log message trace.duration=1.004575763s trace.func=github.com/docker/distribution/context.traceOperation trace.id=<id> ...
//
// Notice that the function name is automatically resolved, along with the
// package and a trace id is emitted that can be linked with parent ids.
Loading