diff --git a/.gitignore b/.gitignore index 6873ae9e..19d536fa 100644 --- a/.gitignore +++ b/.gitignore @@ -23,11 +23,12 @@ drone *_bindata.go # generate binaries -cmd/drone/drone -cmd/drone-build/drone-build cmd/drone-agent/drone-agent +cmd/drone-build/drone-build +cmd/drone-agent/drone-server # generated binaries bin/drone -bin/drone-build bin/drone-agent +bin/drone-build +bin/drone-server diff --git a/Makefile b/Makefile index caa49caa..882484ac 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,11 @@ concat: cmd/drone-server/static/scripts/controllers/*.js \ cmd/drone-server/static/scripts/term.js > cmd/drone-server/static/scripts/drone.min.js +# installs the drone binaries into bin +install: + install -t /usr/local/bin bin/drone + install -t /usr/local/bin bin/drone-agent + # embeds all the static files directly # into the drone binary file bindata: diff --git a/cmd/drone-build/Dockerfile b/cmd/drone-build/Dockerfile index 8adb479d..dcc086b7 100644 --- a/cmd/drone-build/Dockerfile +++ b/cmd/drone-build/Dockerfile @@ -7,4 +7,3 @@ FROM gliderlabs/alpine:3.1 RUN apk-install ca-certificates ADD drone-build /bin/ ENTRYPOINT ["/bin/drone-build"] - diff --git a/cmd/drone-build/client.go b/cmd/drone-build/client.go index 235df542..a191060c 100644 --- a/cmd/drone-build/client.go +++ b/cmd/drone-build/client.go @@ -5,6 +5,7 @@ import ( "os" log "github.com/Sirupsen/logrus" + "github.com/drone/drone/pkg/docker" "github.com/samalba/dockerclient" ) @@ -154,7 +155,7 @@ func run(client dockerclient.Client, conf *dockerclient.ContainerConfig, pull bo return } defer rc.Close() - StdCopy(os.Stdout, os.Stdout, rc) + docker.StdCopy(os.Stdout, os.Stdout, rc) // fetches the container information info, err := client.InspectContainer(id) diff --git a/doc/swagger.json b/doc/swagger.json deleted file mode 100644 index fb1825bf..00000000 --- a/doc/swagger.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "version": "1.0.0", - "title": "Drone API", - "contact": { - "name": "Team Drone", - "url": "https://github.com/drone/drone" - }, - "license": { - "name": "Creative Commons 4.0 International", - "url": "http://creativecommons.org/licenses/by/4.0/" - } - }, - "host": "localhost:8080", - "basePath": "/api", - "schemes": [ - "http" - ], - "paths": { - "/user": { - "get": { - "description": "Returns the currently authenticated user.", - "produces": [ - "application/json" - ], - "responses": { - "200": { - "description": "The currently authenticated user.", - "schema": { - "$ref": "#/definitions/User" - } - } - } - }, - "patch": { - "description": "Updates the currently authenticated user.", - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "pet", - "in": "body", - "description": "Updates to the user.", - "required": true, - "schema": { - "$ref": "#/definitions/User" - } - } - ], - "responses": { - "200": { - "description": "The updated user.", - "schema": { - "$ref": "#/definitions/User" - } - } - } - } - } - }, - "definitions": { - "User": { - "required": [ - "login" - ], - "properties": { - "login": { - "type": "string" - }, - "name": { - "type": "string" - }, - "email": { - "type": "string" - }, - "gravatar_id": { - "type": "string" - }, - "admin": { - "type": "boolean" - }, - "active": { - "type": "boolean" - }, - "created_at": { - "type": "integer", - "format": "int64" - }, - "updated_at": { - "type": "integer", - "format": "int64" - } - } - } - } -} diff --git a/doc/swagger.yml b/doc/swagger.yml new file mode 100644 index 00000000..0b861707 --- /dev/null +++ b/doc/swagger.yml @@ -0,0 +1,129 @@ +swagger: "2.0" +info: + version: 1.0.0 + title: Drone API + contact: + name: Team Drone + url: "https://github.com/drone/drone" + license: + name: Creative Commons 4.0 International + url: "http://creativecommons.org/licenses/by/4.0/" +host: "localhost:8080" +basePath: /api +schemes: + - http +paths: + /user: + get: + description: Returns the currently authenticated user. + produces: + - application/json + responses: + "200": + description: The currently authenticated user. + schema: + $ref: "#/definitions/User" + patch: + description: Updates the currently authenticated user. + produces: + - application/json + parameters: + - name: user + in: body + description: Updates to the user. + required: true + schema: + $ref: "#/definitions/User" + responses: + "200": + description: The updated user. + schema: + $ref: "#/definitions/User" +definitions: + User: + properties: + login: + type: string + name: + type: string + email: + type: string + gravatar_id: + type: string + admin: + type: boolean + active: + type: boolean + created_at: + type: integer + format: int64 + updated_at: + type: integer + format: int64 + Repo: + properties: + owner: + type: string + name: + type: string + created_at: + type: integer + format: int64 + updated_at: + type: integer + format: int64 + Commit: + properties: + sequence: + type: integer + state: + type: string + sha: + type: string + ref: + type: string + branch: + type: string + author: + type: string + gravatar_id: + type: string + message: + type: string + pull_request: + type: boolean + started_at: + type: integer + format: int64 + finished_at: + type: integer + format: int64 + created_at: + type: integer + format: int64 + updated_at: + type: integer + format: int64 + Build: + properties: + sequence: + type: integer + state: + type: string + exit_code: + type: integer + duration: + type: integer + format: int64 + started_at: + type: integer + format: int64 + finished_at: + type: integer + format: int64 + created_at: + type: integer + format: int64 + updated_at: + type: integer + format: int64 \ No newline at end of file diff --git a/cmd/drone-build/copy.go b/pkg/docker/copy.go similarity index 99% rename from cmd/drone-build/copy.go rename to pkg/docker/copy.go index 7764f582..806b6fa5 100644 --- a/cmd/drone-build/copy.go +++ b/pkg/docker/copy.go @@ -1,4 +1,4 @@ -package main +package docker import ( "encoding/binary" diff --git a/pkg/runner/builtin/copy.go b/pkg/runner/builtin/copy.go deleted file mode 100644 index e43cf8ce..00000000 --- a/pkg/runner/builtin/copy.go +++ /dev/null @@ -1,124 +0,0 @@ -package builtin - -import ( - "encoding/binary" - "errors" - "io" -) - -const ( - StdWriterPrefixLen = 8 - StdWriterFdIndex = 0 - StdWriterSizeIndex = 4 -) - -type StdType [StdWriterPrefixLen]byte - -var ( - Stdin StdType = StdType{0: 0} - Stdout StdType = StdType{0: 1} - Stderr StdType = StdType{0: 2} -) - -type StdWriter struct { - io.Writer - prefix StdType - sizeBuf []byte -} - -var ErrInvalidStdHeader = errors.New("Unrecognized input header") - -// StdCopy is a modified version of io.Copy. -// -// StdCopy will demultiplex `src`, assuming that it contains two streams, -// previously multiplexed together using a StdWriter instance. -// As it reads from `src`, StdCopy will write to `dstout` and `dsterr`. -// -// StdCopy will read until it hits EOF on `src`. It will then return a nil error. -// In other words: if `err` is non nil, it indicates a real underlying error. -// -// `written` will hold the total number of bytes written to `dstout` and `dsterr`. -func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error) { - var ( - buf = make([]byte, 32*1024+StdWriterPrefixLen+1) - bufLen = len(buf) - nr, nw int - er, ew error - out io.Writer - frameSize int - ) - - for { - // Make sure we have at least a full header - for nr < StdWriterPrefixLen { - var nr2 int - nr2, er = src.Read(buf[nr:]) - nr += nr2 - if er == io.EOF { - if nr < StdWriterPrefixLen { - return written, nil - } - break - } - if er != nil { - return 0, er - } - } - - // Check the first byte to know where to write - switch buf[StdWriterFdIndex] { - case 0: - fallthrough - case 1: - // Write on stdout - out = dstout - case 2: - // Write on stderr - out = dsterr - default: - return 0, ErrInvalidStdHeader - } - - // Retrieve the size of the frame - frameSize = int(binary.BigEndian.Uint32(buf[StdWriterSizeIndex : StdWriterSizeIndex+4])) - - // Check if the buffer is big enough to read the frame. - // Extend it if necessary. - if frameSize+StdWriterPrefixLen > bufLen { - buf = append(buf, make([]byte, frameSize+StdWriterPrefixLen-bufLen+1)...) - bufLen = len(buf) - } - - // While the amount of bytes read is less than the size of the frame + header, we keep reading - for nr < frameSize+StdWriterPrefixLen { - var nr2 int - nr2, er = src.Read(buf[nr:]) - nr += nr2 - if er == io.EOF { - if nr < frameSize+StdWriterPrefixLen { - return written, nil - } - break - } - if er != nil { - return 0, er - } - } - - // Write the retrieved frame (without header) - nw, ew = out.Write(buf[StdWriterPrefixLen : frameSize+StdWriterPrefixLen]) - if ew != nil { - return 0, ew - } - // If the frame has not been fully written: error - if nw != frameSize { - return 0, io.ErrShortWrite - } - written += int64(nw) - - // Move the rest of the buffer to the beginning - copy(buf, buf[frameSize+StdWriterPrefixLen:]) - // Move the index - nr -= frameSize + StdWriterPrefixLen - } -} diff --git a/pkg/runner/builtin/runner.go b/pkg/runner/builtin/runner.go index 06b7fb12..8bba9f45 100644 --- a/pkg/runner/builtin/runner.go +++ b/pkg/runner/builtin/runner.go @@ -9,6 +9,7 @@ import ( "os" "time" + "github.com/drone/drone/pkg/docker" "github.com/drone/drone/pkg/queue" common "github.com/drone/drone/pkg/types" "github.com/samalba/dockerclient" @@ -153,7 +154,7 @@ func (r *Runner) Run(w *queue.Work) error { return err } else { defer rc.Close() - StdCopy(&buf, &buf, rc) + docker.StdCopy(&buf, &buf, rc) } err = r.SetLogs(w.Repo, w.Commit, task, ioutil.NopCloser(&buf)) if err != nil { @@ -248,7 +249,7 @@ func (r *Runner) Logs(build *common.Build) (io.ReadCloser, error) { pr, pw := io.Pipe() go func() { defer rc.Close() - StdCopy(pw, pw, rc) + docker.StdCopy(pw, pw, rc) }() return pr, nil }