Skip to content

Commit b28f8c0

Browse files
authored
Merge pull request #23060 from karalabe/travis-docker
travis, build: own docker builder and hub pusher
2 parents a675c89 + 90ffcfd commit b28f8c0

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,37 @@ jobs:
2424
script:
2525
- go run build/ci.go lint
2626

27+
# This builder does the Docker Hub build and upload for amd64
28+
- stage: build
29+
if: type = push
30+
os: linux
31+
dist: bionic
32+
go: 1.16.x
33+
env:
34+
- docker
35+
services:
36+
- docker
37+
git:
38+
submodules: false # avoid cloning ethereum/tests
39+
script:
40+
- go run build/ci.go docker -upload karalabe/geth-docker-test
41+
42+
# This builder does the Docker Hub build and upload for arm64
43+
- stage: build
44+
if: type = push
45+
os: linux
46+
arch: arm64
47+
dist: bionic
48+
go: 1.16.x
49+
env:
50+
- docker
51+
services:
52+
- docker
53+
git:
54+
submodules: false # avoid cloning ethereum/tests
55+
script:
56+
- go run build/ci.go docker -upload karalabe/geth-docker-test
57+
2758
# This builder does the Ubuntu PPA upload
2859
- stage: build
2960
if: type = push

build/ci.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ func main() {
182182
doLint(os.Args[2:])
183183
case "archive":
184184
doArchive(os.Args[2:])
185+
case "docker":
186+
doDockerImage(os.Args[2:])
185187
case "debsrc":
186188
doDebianSource(os.Args[2:])
187189
case "nsis":
@@ -452,6 +454,56 @@ func maybeSkipArchive(env build.Environment) {
452454
}
453455
}
454456

457+
// Builds the docker images and optionally uploads them to Docker Hub.
458+
func doDockerImage(cmdline []string) {
459+
var (
460+
upload = flag.String("upload", "", `Where to upload the docker image (usually "ethereum/client-go")`)
461+
)
462+
flag.CommandLine.Parse(cmdline)
463+
464+
// Skip building and pushing docker images for PR builds
465+
env := build.Env()
466+
maybeSkipArchive(env)
467+
468+
// Retrieve the version infos to build and push to the following paths:
469+
// - ethereum/client-go:latest - Pushes to the master branch, Geth only
470+
// - ethereum/client-go:stable - Version tag publish on GitHub, Geth only
471+
// - ethereum/client-go:alltools-latest - Pushes to the master branch, Geth & tools
472+
// - ethereum/client-go:alltools-stable - Version tag publish on GitHub, Geth & tools
473+
// - ethereum/client-go:release-<major>.<minor> - Version tag publish on GitHub, Geth only
474+
// - ethereum/client-go:alltools-release-<major>.<minor> - Version tag publish on GitHub, Geth & tools
475+
// - ethereum/client-go:v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth only
476+
// - ethereum/client-go:alltools-v<major>.<minor>.<patch> - Version tag publish on GitHub, Geth & tools
477+
var tags []string
478+
479+
switch {
480+
case env.Branch == "master":
481+
tags = []string{"latest"}
482+
case strings.HasPrefix(env.Tag, "v1."):
483+
tags = []string{"stable", fmt.Sprintf("release-1.%d", params.VersionMinor), params.Version}
484+
}
485+
// Build the docker images via CLI (don't pull in the `moby` dep to call 3 commands)
486+
build.MustRunCommand("docker", "build", "--tag", fmt.Sprintf("%s:TAG", *upload), ".")
487+
build.MustRunCommand("docker", "build", "--tag", fmt.Sprintf("%s:alltools-TAG", *upload), "-f", "Dockerfile.alltools", ".")
488+
489+
// Retrieve the upload credentials and authenticate
490+
user := getenvBase64("DOCKER_HUB_USERNAME")
491+
pass := getenvBase64("DOCKER_HUB_PASSWORD")
492+
493+
if len(user) > 0 && len(pass) > 0 {
494+
auther := exec.Command("docker", "login", "-u", string(user), "--password-stdin")
495+
auther.Stdin = bytes.NewReader(pass)
496+
build.MustRun(auther)
497+
}
498+
// Tag and upload the images to Docker Hub
499+
for _, tag := range tags {
500+
build.MustRunCommand("docker", "image", "tag", fmt.Sprintf("%s:TAG", *upload), fmt.Sprintf("%s:%s", *upload, tag))
501+
build.MustRunCommand("docker", "image", "tag", fmt.Sprintf("%s:alltools-TAG", *upload), fmt.Sprintf("%s:alltools-%s", *upload, tag))
502+
build.MustRunCommand("docker", "push", fmt.Sprintf("%s:%s", *upload, tag))
503+
build.MustRunCommand("docker", "push", fmt.Sprintf("%s:alltools-%s", *upload, tag))
504+
}
505+
}
506+
455507
// Debian Packaging
456508
func doDebianSource(cmdline []string) {
457509
var (

0 commit comments

Comments
 (0)