This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1502337: Initial support for docker-worker payloads
This commit implements the initial support for docker-worker payloads. So far, only the Image, Command, Env and MaxRunTime fields are supported. It hasn't been extensive tested so features like task cancellation may not work. Also, it doesn't implement custom artifacts and more extensive tests. The support for docker-worker payloads is achieved through build flags. To build with docker-worker paylod, build it with the "docker" flag, like so: $ go build -tags=docker Notice that generic-worker will not be supported in this build. We also needed to upgrade golang due to a bug in the go compiler [1]. [1] golang/go#25908
- Loading branch information
Wander Lairson Costa
committed
Nov 19, 2018
1 parent
098193c
commit a315186
Showing
46 changed files
with
2,167 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,6 @@ directory-caches.json | |
file-caches.json | ||
tasks-resolved-count.txt | ||
/revision.txt | ||
|
||
# binary file | ||
generic-worker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: go | ||
go: | ||
- "1.10.3" | ||
- "1.10.4" | ||
|
||
env: | ||
- "CGO_ENABLED=0 GIMME_OS=linux GIMME_ARCH=386" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !docker | ||
|
||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// +build !windows | ||
// +build !windows,!docker | ||
|
||
package main | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// +build docker | ||
|
||
package main | ||
|
||
func (cot *ChainOfTrustTaskFeature) ensureTaskUserCantReadPrivateCotKey() error { | ||
return nil | ||
} | ||
|
||
func secureSigningKey() error { | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// +build docker | ||
|
||
package dockerworker | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/cenkalti/backoff" | ||
"github.com/mattetti/filebuffer" | ||
"github.com/mitchellh/ioprogress" | ||
) | ||
|
||
// DownloadArtifact downloads an artifact using exponential backoff algorithm | ||
func (d *DockerWorker) DownloadArtifact(taskID, runID, name string, out io.WriteSeeker) (ret error) { | ||
var u *url.URL | ||
|
||
backoffError := backoff.Retry(func() (err error) { | ||
// rewind out stream | ||
_, ret = out.Seek(0, io.SeekStart) | ||
if ret != nil { | ||
return | ||
} | ||
|
||
if runID == "" { | ||
u, ret = d.Queue.GetLatestArtifact_SignedURL(taskID, name, 24*time.Hour) | ||
} else { | ||
u, ret = d.Queue.GetArtifact_SignedURL(taskID, runID, name, 24*time.Hour) | ||
} | ||
|
||
if ret != nil { | ||
return | ||
} | ||
|
||
d.TaskLogger.Printf("Downloading %s/%s/%s from %s\n", taskID, runID, name, u.String()) | ||
|
||
// Build a custom request object so we can embed a context into it | ||
var req *http.Request | ||
req, ret = http.NewRequest(http.MethodGet, u.String(), nil) | ||
if ret != nil { | ||
return | ||
} | ||
req = req.WithContext(d.Context) | ||
|
||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
buff := filebuffer.New([]byte{}) | ||
|
||
// Build the error message with the status code and the response body | ||
errorMessage := fmt.Sprintf("Error downloading %s/%s, status=%s", taskID, name, resp.Status) | ||
if _, err2 := io.Copy(buff, resp.Body); err2 == nil { | ||
errorMessage += "\n" + buff.String() | ||
} | ||
|
||
// For status codes other than 5XX there is no point in issuing a retry | ||
if resp.StatusCode >= 300 && resp.StatusCode < 500 { | ||
ret = errors.New(errorMessage) | ||
} else { | ||
err = errors.New(errorMessage) | ||
} | ||
|
||
return | ||
} | ||
|
||
size, err2 := strconv.Atoi(resp.Header.Get("Content-Length")) | ||
if err2 != nil { | ||
ret = err2 | ||
return | ||
} | ||
|
||
// Depending on the implementation, the body can also issue network requests, | ||
// that's why we need to retry if io.Copy fails | ||
_, err = io.Copy(out, &ioprogress.Reader{ | ||
Reader: resp.Body, | ||
Size: int64(size), | ||
DrawFunc: ioprogress.DrawTerminal(d.LivelogWriter), | ||
}) | ||
|
||
return | ||
}, backoff.WithMaxRetries(backoff.WithContext(backoff.NewExponentialBackOff(), d.Context), 3)) | ||
|
||
if ret == nil { | ||
ret = backoffError | ||
} | ||
|
||
return | ||
} |
Oops, something went wrong.