Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
Support HEAD /v2/<team>/<artifact>/manifests/<name>
Browse files Browse the repository at this point in the history
Adds support for responding to `HEAD /v2/<team>/<artifact>/manifests/<name>` requests.
This is required by containerd and described in the opencontainers spec: https://github.com/opencontainers/distribution-spec/blob/master/spec.md

Signed-off-by: Mikkel Oscar Lyderik Larsen <m@moscar.net>
  • Loading branch information
mikkeloscar committed Jun 7, 2018
1 parent e35dc66 commit 053e6f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions resources/api/pierone-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,21 @@ paths:
responses:
"200":
description: OK
head:
summary: check for existing image manifest
tags:
- Docker Registry API v2
operationId: org.zalando.stups.pierone.api-v2/head-manifest
security: # remove for HTTP_ALLOW_PUBLIC_READ
- oauth2: [uid] # remove for HTTP_ALLOW_PUBLIC_READ
- iid: # remove for HTTP_ALLOW_PUBLIC_READ
parameters:
- $ref: '#/parameters/team'
- $ref: '#/parameters/artifact'
- $ref: '#/parameters/name'
responses:
"200":
description: OK
/v2/{team}/{artifact}/tags/list:
get:
summary: list tags
Expand Down
14 changes: 14 additions & 0 deletions src/org/zalando/stups/pierone/api_v2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,20 @@
(log/info "docker pull: manifest not found: %s" pretty-name)
(resp (get-error-response :MANIFEST_UNKNOWN {"Parameters" parameters}) request :status 404)))))

(defn head-manifest
"Check whether image metadata (a.k.a. manifest) exists."
[parameters request db _ _ _]
(if-let [manifest (load-manifest parameters db)]
(let [parsed-manifest (adjust-manifest (json/decode manifest))
size (get-in parsed-manifest ["config", "size"])
digest (get-in parsed-manifest ["config", "digest"])]
(log/info "getting head manifest %s - %s" size digest)
(-> (resp "OK" request)
(ring/header "Docker-Content-Digest" digest)
(ring/header "Content-Length" size)))
(do
(resp "manifest not found" request :status 404))))

(defn list-tags
[{:keys [team artifact] :as parameters} request db _ _ _]
(let [tags (map :name (sql/cmd-list-tag-names parameters {:connection db}))]
Expand Down
4 changes: 4 additions & 0 deletions test/org/zalando/stups/pierone/v2_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
(client/get (u/v2-url "/myteam/myart/manifests/1.0")
(u/http-opts)))))

(expect 200
(client/head (u/v2-url "/myteam/myart/manifests/1.0")
(u/http-opts))))

(is (= (:pretty d/manifest-v1)
(expect 200
(client/get (u/v2-url "/myteam/myart/manifests/sha256:b0ebea73273b4d5a334d74cd826a2327f260fe5212613937add8b5e171bf49bd")
Expand Down

0 comments on commit 053e6f9

Please sign in to comment.