Skip to content

Commit 91106a1

Browse files
committed
tools/server, docker: use downloaded version of artifact
Signed-off-by: deadprogram <[email protected]>
1 parent 6562dfc commit 91106a1

File tree

6 files changed

+65
-9
lines changed

6 files changed

+65
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build
22
keys/*.pem
3+
tools/docker/versions/*.tar.gz

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.15
44

55
require (
66
github.com/bradleyfalzon/ghinstallation v1.1.1
7+
github.com/cavaliercoder/grab v2.0.0+incompatible // indirect
78
github.com/google/go-github/v40 v40.0.0
89
github.com/mattermost/go-circleci v0.7.1
910
go.bug.st/serial v1.1.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/bradleyfalzon/ghinstallation v1.1.1 h1:pmBXkxgM1WeF8QYvDLT5kuQiHMcmf+X015GI0KM/E3I=
22
github.com/bradleyfalzon/ghinstallation v1.1.1/go.mod h1:vyCmHTciHx/uuyN82Zc3rXN3X2KTK8nUTCrTMwAhcug=
3+
github.com/cavaliercoder/grab v2.0.0+incompatible h1:wZHbBQx56+Yxjx2TCGDcenhh3cJn7cCLMfkEPmySTSE=
4+
github.com/cavaliercoder/grab v2.0.0+incompatible/go.mod h1:tTBkfNqSBfuMmMBFaO2phgyhdYhiZQ/+iXCZDzcDsMI=
35
github.com/creack/goselect v0.1.1 h1:tiSSgKE1eJtxs1h/VgGQWuXUP0YS4CDIFMp6vaI1ls0=
46
github.com/creack/goselect v0.1.1/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
57
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=

tools/docker/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ RUN wget https://dl.google.com/go/go${GO_RELEASE}.linux-amd64.tar.gz && \
1717
ENV PATH=${PATH}:/usr/local/go/bin
1818

1919
FROM tinygohci-base AS tinygohci-build
20-
ENV TINYGO_RELEASE=0.19.0
21-
ARG TINYGO_DOWNLOAD_URL=https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_RELEASE}/tinygo${TINYGO_RELEASE}.linux-amd64.tar.gz
22-
RUN wget ${TINYGO_DOWNLOAD_URL} -O tinygo.zip && \
23-
unzip tinygo.zip tinygo.linux-amd64.tar.gz && \
24-
tar -xzf tinygo.linux-amd64.tar.gz -C /usr/local && \
25-
rm tinygo.zip tinygo.linux-amd64.tar.gz
20+
ENV TINYGO_RELEASE=0.21.0
21+
ARG TINYGO_DOWNLOAD_SHA=1234
22+
23+
COPY versions/${TINYGO_DOWNLOAD_SHA}.tar.gz tinygo.linux-amd64.tar.gz
24+
RUN tar -xzf tinygo.linux-amd64.tar.gz -C /usr/local && \
25+
rm tinygo.linux-amd64.tar.gz
2626
ENV PATH=${PATH}:/usr/local/tinygo/bin
2727
RUN go get -d tinygo.org/x/drivers
2828

tools/docker/versions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is to hold downloaded version of the TinyGo executable.

tools/server/main.go

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"net/http"
1212

13+
"github.com/cavaliercoder/grab"
1314
"github.com/google/go-github/v40/github"
1415
)
1516

@@ -207,7 +208,14 @@ func processBuilds(builds chan *Build) {
207208
}
208209

209210
log.Printf("Building docker image using TinyGo from %s\n", url)
210-
err := buildDocker(url, build.sha)
211+
err := downloadBinary(url, build.sha)
212+
if err != nil {
213+
log.Println(err)
214+
build.failCheckSuite("binary download failed")
215+
continue
216+
}
217+
218+
err = buildDocker(build.sha)
211219
if err != nil {
212220
log.Println(err)
213221
build.failCheckSuite("docker build failed")
@@ -233,8 +241,8 @@ func processBuilds(builds chan *Build) {
233241

234242
// buildDocker does the docker build for the binary download
235243
// with this SHA.
236-
func buildDocker(url, sha string) error {
237-
buildarg := fmt.Sprintf("TINYGO_DOWNLOAD_URL=%s", url)
244+
func buildDocker(sha string) error {
245+
buildarg := fmt.Sprintf("TINYGO_DOWNLOAD_SHA=%s", sha)
238246
buildtag := "tinygohci:" + sha[:7]
239247
out, err := exec.Command("docker", "build",
240248
"-t", buildtag,
@@ -249,6 +257,49 @@ func buildDocker(url, sha string) error {
249257
return nil
250258
}
251259

260+
// downloadBinary does the download for the binary build
261+
// with this SHA.
262+
func downloadBinary(url, sha string) error {
263+
// check if the file is already downloaded for this sha
264+
if !fileExists("tools/docker/versions/" + sha + ".tar.gz") {
265+
log.Println("Downloading binary for", sha)
266+
267+
_, err := grab.Get("tinygo-latest.zip", url)
268+
if err != nil {
269+
return err
270+
}
271+
272+
// unzip
273+
_, err = exec.Command("unzip", "tinygo-latest.zip",
274+
"tinygo.linux-amd64.tar.gz").CombinedOutput()
275+
if err != nil {
276+
return err
277+
}
278+
279+
// move file
280+
err = os.Rename("tinygo.linux-amd64.tar.gz", "tools/docker/versions/"+sha+".tar.gz")
281+
if err != nil {
282+
return err
283+
}
284+
285+
err = os.Remove("tinygo-latest.zip")
286+
if err != nil {
287+
return err
288+
}
289+
}
290+
return nil
291+
}
292+
293+
// fileExists checks if a file exists and is not a directory before we
294+
// try using it to prevent further errors.
295+
func fileExists(filename string) bool {
296+
info, err := os.Stat(filename)
297+
if os.IsNotExist(err) {
298+
return false
299+
}
300+
return !info.IsDir()
301+
}
302+
252303
func performCheckRun(cr *github.CheckRun, runID int64, buildsCh chan *Build) {
253304
// do the retest here
254305
url, err := getTinygoBinaryURLFromGH(runID)

0 commit comments

Comments
 (0)