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

Commit

Permalink
read layer (tar.gz)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed May 11, 2015
1 parent e3a79a4 commit 6b9c8a5
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"Starts the system running, sets the Var #'system."
[]
(alter-var-root #'system
(constantly (org.zalando.stups.pierone.core/run {:system-log-level "DEBUG"}))))
(constantly (org.zalando.stups.pierone.core/run {:system-stups-log-level "DEBUG"}))))

(defn stop
"Stops the system if it is currently running, updates the Var
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
:min-lein-version "2.0.0"

:dependencies [[org.clojure/clojure "1.6.0"]
[org.zalando.stups/friboo "0.9.0"]
[org.zalando.stups/friboo "0.11.0"]

[yesql "0.5.0-rc2"]
[org.postgresql/postgresql "9.3-1102-jdbc41"]
[org.apache.commons/commons-compress "1.9"]

[amazonica "0.3.19"]]

Expand Down
44 changes: 44 additions & 0 deletions resources/api/pierone-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ produces:
- application/json

definitions:
ScmSourceInformation:
type: object
properties:
url:
type: string
example: "git:git@github.com:zalando-stups/pierone.git"
revision:
type: string
example: cd768599e1bb41c38279c26254feff5cf57bf967
author:
type: string
example: hjacobs
status:
type: string
example: ""
TagSummary:
type: object
properties:
Expand Down Expand Up @@ -382,3 +397,32 @@ paths:
items:
$ref: "#/definitions/TagSummary"

/teams/{team}/artifacts/{artifact}/tags/{tag}/scm-source:
get:
summary: Get scm-source.json
description: Get artifact's SCM source information (e.g. GIT commit)
tags:
- Pier One API
operationId: org.zalando.stups.pierone.api/get-scm-source
parameters:
- name: team
in: path
required: true
type: string
- name: artifact
in: path
required: true
type: string
- name: tag
in: path
required: true
type: string
responses:
"200":
description: Return scm-source.json
schema:
$ref: "#/definitions/ScmSourceInformation"




17 changes: 17 additions & 0 deletions resources/db/migration/V1__Basic_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ CREATE TABLE images (
PRIMARY KEY (i_id)
);

CREATE TABLE scm_source_data (
ssd_image_id TEXT NOT NULL,

ssd_url TEXT NOT NULL,

ssd_revision TEXT NOT NULL,

ssd_author TEXT NOT NULL,

ssd_status TEXT NOT NULL,

ssd_created timestamp NOT NULL DEFAULT now(),

PRIMARY KEY (ssd_image_id),
FOREIGN KEY (ssd_image_id) REFERENCES images (i_id)
);

-- base entity: tags
CREATE TABLE tags (
--the team ID
Expand Down
5 changes: 5 additions & 0 deletions resources/db/v1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ UPDATE images
SET i_accepted = TRUE
WHERE i_id = :image;

-- name: create-scm-source-data!
INSERT INTO scm_source_data
(ssd_image_id, ssd_url, ssd_revision, ssd_author, ssd_status)
VALUES (:image, :url, :revision, :author, :status);

-- name: get-image-metadata
SELECT i_metadata AS metadata
FROM images
Expand Down
6 changes: 6 additions & 0 deletions src/org/zalando/stups/pierone/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@
(let [result (sql/list-tags parameters {:connection db})]
(-> (ring/response result)
(fring/content-type-json))))

(defn get-scm-source
"Get SCM source information"
[parameters _ db _]
(-> (ring/response {})
(fring/content-type-json)))
31 changes: 29 additions & 2 deletions src/org/zalando/stups/pierone/api_v1.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
[ring.util.response :as ring]
[clojure.data.json :as json]
[org.zalando.stups.pierone.sql :as sql]
[clojure.java.io :as io]
[org.zalando.stups.pierone.storage :as s])
(:import (java.sql SQLException)))
(:import (java.sql SQLException)

(java.util UUID)
(org.apache.commons.compress.compressors.gzip GzipCompressorInputStream)
(org.apache.commons.compress.archivers.tar TarArchiveInputStream)
(java.io FileInputStream File)))

(defn- resp
"Returns a response including various Docker headers set."
Expand Down Expand Up @@ -104,10 +110,31 @@
(resp "image not found" request :status 404)
(resp (-> result first :metadata json/read-str) request))))

(defn get-scm-source-data
[tmp-file]
(try
(let [fis (FileInputStream. tmp-file)
tar (TarArchiveInputStream. (GzipCompressorInputStream. fis))]
(loop []
(when-let [entry (.getNextTarEntry tar)]
(log/info "Entry: %s" (.getName entry))
(recur))))
nil
(catch Exception e
(log/error e "Failed to read image layer")
nil)))


(defn put-image-binary
"Stores an image's binary data. Second call in upload sequence."
[{:keys [image data]} request db storage]
(s/write-data storage image data)
(let [^File tmp-file (io/file (:directory storage) (str image ".tmp-" (UUID/randomUUID)))]
(io/copy data tmp-file)
(s/write-data storage image tmp-file)
(when-let [scm-source (get-scm-source-data tmp-file)]
(log/info "Found scm-source.json in image %s: %s" image scm-source)
(sql/create-scm-source-data! (assoc scm-source :image image) {:connection db}))
(io/delete-file tmp-file true))
(sql/accept-image! {:image image} {:connection db})
(log/info "Stored new image %s." image)
(resp "OK" request))
Expand Down

0 comments on commit 6b9c8a5

Please sign in to comment.