@@ -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
456508func doDebianSource (cmdline []string ) {
457509 var (
0 commit comments