From 3e321f1904170de413d27011bb8dc0fcd282caf7 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 27 Aug 2017 12:27:28 -0700 Subject: [PATCH] enable gcr and heroku plugins --- .drone.sh | 22 +++++++++++++ .drone.yml | 33 +++++++++++++------ .gitignore | 29 ++--------------- Dockerfile | 4 --- Dockerfile.armhf | 4 --- MAINTAINERS | 46 -------------------------- cmd/drone-docker-ecr/main.go | 5 +++ cmd/drone-docker-gcr/main.go | 50 +++++++++++++++++++++++++++++ cmd/drone-docker-heroku/main.go | 45 ++++++++++++++++++++++++++ main.go => cmd/drone-docker/main.go | 12 ++++--- plugin.go => docker.go | 7 +--- docker/Dockerfile | 6 ++++ docker/Dockerfile.arm | 1 + docker/Dockerfile.arm64 | 1 + docker/ecr/Dockerfile | 1 + docker/ecr/Dockerfile.arm | 1 + docker/ecr/Dockerfile.arm64 | 1 + docker/gcr/Dockerfile | 6 ++++ docker/gcr/Dockerfile.arm | 4 +++ docker/gcr/Dockerfile.arm64 | 4 +++ docker/heroku/Dockerfile | 6 ++++ docker/heroku/Dockerfile.arm | 4 +++ docker/heroku/Dockerfile.arm64 | 4 +++ 23 files changed, 195 insertions(+), 101 deletions(-) create mode 100644 .drone.sh delete mode 100644 Dockerfile delete mode 100644 Dockerfile.armhf delete mode 100644 MAINTAINERS create mode 100644 cmd/drone-docker-ecr/main.go create mode 100644 cmd/drone-docker-gcr/main.go create mode 100644 cmd/drone-docker-heroku/main.go rename main.go => cmd/drone-docker/main.go (96%) rename plugin.go => docker.go (98%) create mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.arm create mode 100644 docker/Dockerfile.arm64 create mode 100644 docker/ecr/Dockerfile create mode 100644 docker/ecr/Dockerfile.arm create mode 100644 docker/ecr/Dockerfile.arm64 create mode 100644 docker/gcr/Dockerfile create mode 100644 docker/gcr/Dockerfile.arm create mode 100644 docker/gcr/Dockerfile.arm64 create mode 100644 docker/heroku/Dockerfile create mode 100644 docker/heroku/Dockerfile.arm create mode 100644 docker/heroku/Dockerfile.arm64 diff --git a/.drone.sh b/.drone.sh new file mode 100644 index 0000000..b6af27a --- /dev/null +++ b/.drone.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e +set -x + +# compile the main binary +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/amd64/drone-docker github.com/drone-plugins/drone-docker/cmd/drone-docker +GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm64/drone-docker github.com/drone-plugins/drone-docker/cmd/drone-docker +GOOS=linux GOARCH=arm CGO_ENABLED=0 GOARM=7 go build -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm/drone-docker github.com/drone-plugins/drone-docker/cmd/drone-docker + +# build the heroku binary +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-docker-heroku github.com/drone-plugins/drone-docker/cmd/drone-docker-heroku +GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/arm64/drone-docker-heroku github.com/drone-plugins/drone-docker/cmd/drone-docker-heroku +GOOS=linux GOARCH=arm CGO_ENABLED=0 GOARM=7 go build -a -tags netgo -o release/linux/arm/drone-docker-heroku github.com/drone-plugins/drone-docker/cmd/drone-docker-heroku + +# build the gcr binary +GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/amd64/drone-docker-gcr github.com/drone-plugins/drone-docker/cmd/drone-docker-gcr +GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -a -tags netgo -o release/linux/arm64/drone-docker-gcr github.com/drone-plugins/drone-docker/cmd/drone-docker-gcr +GOOS=linux GOARCH=arm CGO_ENABLED=0 GOARM=7 go build -a -tags netgo -o release/linux/arm/drone-docker-gcr github.com/drone-plugins/drone-docker/cmd/drone-docker-gcr + +# build the ecr binary +# todo diff --git a/.drone.yml b/.drone.yml index 8cf7e40..34c0006 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,21 +3,36 @@ workspace: path: src/github.com/drone-plugins/drone-docker pipeline: - test: - image: golang:1.6 - environment: - - CGO_ENABLED=0 - commands: - # Disabled: main.go:99: cli.StringSlice composite literal uses unkeyed fields - # - go vet - - go test -cover -coverprofile=coverage.out - - go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a -tags netgo + build: + image: golang:1.9 + commands: sh .drone.sh publish: image: plugins/docker repo: plugins/docker tags: [ "latest", "17", "17.05" ] secrets: [ docker_username, docker_password ] + dockerfile: docker/Dockerfile + when: + branch: master + event: push + + publish_heroku: + image: plugins/docker + repo: plugins/heroku + tags: [ "latest", "17", "17.05" ] + secrets: [ docker_username, docker_password ] + dockerfile: docker/heroku/Dockerfile + when: + branch: master + event: push + + publish_gcr: + image: plugins/docker + repo: plugins/gcr + tags: [ "latest", "17", "17.05" ] + secrets: [ docker_username, docker_password ] + dockerfile: docker/gcr/Dockerfile when: branch: master event: push diff --git a/.gitignore b/.gitignore index fa8a04b..439dab8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,3 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof -.env - +release coverage.out -drone-docker +tmp diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index d50790c..0000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM docker:17.05.0-ce-dind - -ADD drone-docker /bin/ -ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"] diff --git a/Dockerfile.armhf b/Dockerfile.armhf deleted file mode 100644 index 5d94df2..0000000 --- a/Dockerfile.armhf +++ /dev/null @@ -1,4 +0,0 @@ -FROM ??? - -ADD drone-docker /bin/ -ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"] diff --git a/MAINTAINERS b/MAINTAINERS deleted file mode 100644 index 0ecaf19..0000000 --- a/MAINTAINERS +++ /dev/null @@ -1,46 +0,0 @@ -[people] - [people.bradrydzewski] - name = "Brad Rydzewski" - email = "brad@drone.io" - login = "bradrydzewski" - [people.Bugagazavr] - name = "Kirill" - email = "" - login = "Bugagazavr" - [people.donny-dont] - name = "Don Olmstead" - email = "donny-dont@gmail.com" - login = "donny-dont" - [people.jackspirou] - name = "Jack Spirou" - email = "" - login = "jackspirou" - [people.msteinert] - name = "Mike Steinert" - email = "" - login = "msteinert" - [people.nlf] - name = "Nathan LaFreniere" - email = "" - login = "nlf" - [people.tboerger] - name = "Thomas Boerger" - email = "thomas@webhippie.de" - login = "tboerger" - [people.athieriot] - name = "Aurélien Thieriot" - email = "a.thieriot@gmail.com" - login = "athieriot" - -[org] - [org.core] - people = [ - "bradrydzewski", - "Bugagazavr", - "donny-dont", - "jackspirou", - "msteinert", - "nlf", - "tboerger", - "athieriot" - ] diff --git a/cmd/drone-docker-ecr/main.go b/cmd/drone-docker-ecr/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/cmd/drone-docker-ecr/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/cmd/drone-docker-gcr/main.go b/cmd/drone-docker-gcr/main.go new file mode 100644 index 0000000..7342de3 --- /dev/null +++ b/cmd/drone-docker-gcr/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "encoding/base64" + "os" + "os/exec" + "path" + "strings" +) + +func main() { + var ( + username = "_json_key" + password = os.Getenv("GCR_TOKEN") + registry = os.Getenv("PLUGIN_REGISTRY") + repo = os.Getenv("PLUGIN_REPO") + ) + + // decode the token if base64 encoded + decoded, err := base64.StdEncoding.DecodeString(password) + if err == nil { + password = string(decoded) + } + + // default registry value + if registry == "" { + registry = "gcr.io" + } + + // must use the fully qualified repo name. If the + // repo name does not have the registry prefix we + // should prepend. + if !strings.HasPrefix(repo, registry) { + repo = path.Join(registry, repo) + os.Setenv("PLUGIN_REPO", repo) + } + + os.Setenv("PLUGIN_REGISTRY", registry) + os.Setenv("DOCKER_USERNAME", username) + os.Setenv("DOCKER_PASSWORD", password) + + // invoke the base docker plugin binary + cmd := exec.Command("drone-docker") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err = cmd.Run() + if err != nil { + os.Exit(1) + } +} diff --git a/cmd/drone-docker-heroku/main.go b/cmd/drone-docker-heroku/main.go new file mode 100644 index 0000000..5d8a616 --- /dev/null +++ b/cmd/drone-docker-heroku/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "os" + "os/exec" + "path" +) + +func main() { + var ( + registry = "registry.heroku.com" + process = os.Getenv("PLUGIN_PROCESS_TYPE") + app = os.Getenv("PLUGIN_APP") + email = os.Getenv("PLUGIN_EMAIL") + key = os.Getenv("PLUGIN_API_KEY") + ) + + // if the heroku email is provided as a named secret + // then we should use it. + if os.Getenv("HEROKU_EMAIL") != "" { + email = os.Getenv("HEROKU_EMAIL") + } + + // if the heroku api key is provided as a named secret + // then we should use it. + if os.Getenv("HEROKU_API_KEY") != "" { + key = os.Getenv("HEROKU_API_KEY") + } + + os.Setenv("PLUGIN_REGISTRY", registry) + os.Setenv("PLUGIN_REPO", path.Join(registry, app, process)) + + os.Setenv("DOCKER_PASSWORD", key) + os.Setenv("DOCKER_USERNAME", email) + os.Setenv("DOCKER_EMAIL", email) + + // invoke the base docker plugin binary + cmd := exec.Command("drone-docker") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + os.Exit(1) + } +} diff --git a/main.go b/cmd/drone-docker/main.go similarity index 96% rename from main.go rename to cmd/drone-docker/main.go index 231ff68..8d4483e 100644 --- a/main.go +++ b/cmd/drone-docker/main.go @@ -7,6 +7,8 @@ import ( "github.com/Sirupsen/logrus" "github.com/joho/godotenv" "github.com/urfave/cli" + + "github.com/drone-plugins/drone-docker" ) var build = "0" // build number set at compile-time @@ -152,7 +154,7 @@ func main() { cli.StringFlag{ Name: "docker.registry", Usage: "docker registry", - Value: defaultRegistry, + Value: "https://index.docker.io/v1/", EnvVar: "PLUGIN_REGISTRY,DOCKER_REGISTRY", }, cli.StringFlag{ @@ -178,15 +180,15 @@ func main() { } func run(c *cli.Context) error { - plugin := Plugin{ + plugin := docker.Plugin{ Dryrun: c.Bool("dry-run"), - Login: Login{ + Login: docker.Login{ Registry: c.String("docker.registry"), Username: c.String("docker.username"), Password: c.String("docker.password"), Email: c.String("docker.email"), }, - Build: Build{ + Build: docker.Build{ Remote: c.String("remote.url"), Name: c.String("commit.sha"), Dockerfile: c.String("dockerfile"), @@ -199,7 +201,7 @@ func run(c *cli.Context) error { Repo: c.String("repo"), LabelSchema: c.StringSlice("label-schema"), }, - Daemon: Daemon{ + Daemon: docker.Daemon{ Registry: c.String("docker.registry"), Mirror: c.String("daemon.mirror"), StorageDriver: c.String("daemon.storage-driver"), diff --git a/plugin.go b/docker.go similarity index 98% rename from plugin.go rename to docker.go index 377394c..6f62654 100644 --- a/plugin.go +++ b/docker.go @@ -1,4 +1,4 @@ -package main +package docker import ( "fmt" @@ -9,11 +9,6 @@ import ( "time" ) -const ( - // default docker registry - defaultRegistry = "https://index.docker.io/v1/" -) - type ( // Daemon defines Docker daemon parameters. Daemon struct { diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..4b61ebb --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,6 @@ +# docker build --rm -f docker/Dockerfile -t plugins/docker . + +FROM docker:17.05.0-ce-dind + +ADD release/linux/amd64/drone-docker /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"] diff --git a/docker/Dockerfile.arm b/docker/Dockerfile.arm new file mode 100644 index 0000000..b8e4bb0 --- /dev/null +++ b/docker/Dockerfile.arm @@ -0,0 +1 @@ +# see https://github.com/docker-library/docker/issues/67 diff --git a/docker/Dockerfile.arm64 b/docker/Dockerfile.arm64 new file mode 100644 index 0000000..b8e4bb0 --- /dev/null +++ b/docker/Dockerfile.arm64 @@ -0,0 +1 @@ +# see https://github.com/docker-library/docker/issues/67 diff --git a/docker/ecr/Dockerfile b/docker/ecr/Dockerfile new file mode 100644 index 0000000..5afe248 --- /dev/null +++ b/docker/ecr/Dockerfile @@ -0,0 +1 @@ +FROM plugins/docker:latest diff --git a/docker/ecr/Dockerfile.arm b/docker/ecr/Dockerfile.arm new file mode 100644 index 0000000..49b98df --- /dev/null +++ b/docker/ecr/Dockerfile.arm @@ -0,0 +1 @@ +FROM plugins/docker:linux-arm diff --git a/docker/ecr/Dockerfile.arm64 b/docker/ecr/Dockerfile.arm64 new file mode 100644 index 0000000..181c846 --- /dev/null +++ b/docker/ecr/Dockerfile.arm64 @@ -0,0 +1 @@ +FROM plugins/docker:linux-arm64 diff --git a/docker/gcr/Dockerfile b/docker/gcr/Dockerfile new file mode 100644 index 0000000..92d562d --- /dev/null +++ b/docker/gcr/Dockerfile @@ -0,0 +1,6 @@ +# docker build --rm -f docker/gcr/Dockerfile -t plugins/gcr . + +FROM plugins/docker:latest + +ADD release/linux/amd64/drone-docker-gcr /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker-gcr"] diff --git a/docker/gcr/Dockerfile.arm b/docker/gcr/Dockerfile.arm new file mode 100644 index 0000000..5d45caf --- /dev/null +++ b/docker/gcr/Dockerfile.arm @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-arm + +ADD release/linux/arm64/drone-docker-gcr /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker-gcr"] diff --git a/docker/gcr/Dockerfile.arm64 b/docker/gcr/Dockerfile.arm64 new file mode 100644 index 0000000..49c049b --- /dev/null +++ b/docker/gcr/Dockerfile.arm64 @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-arm64 + +ADD release/linux/arm64/drone-docker-gcr /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker-gcr"] diff --git a/docker/heroku/Dockerfile b/docker/heroku/Dockerfile new file mode 100644 index 0000000..6f53c65 --- /dev/null +++ b/docker/heroku/Dockerfile @@ -0,0 +1,6 @@ +# docker build --rm -f docker/heroku/Dockerfile -t plugins/heroku . + +FROM plugins/docker:latest + +ADD release/linux/amd64/drone-docker-heroku /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker-heroku"] diff --git a/docker/heroku/Dockerfile.arm b/docker/heroku/Dockerfile.arm new file mode 100644 index 0000000..e521b02 --- /dev/null +++ b/docker/heroku/Dockerfile.arm @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-arm + +ADD release/linux/arm/drone-docker-heroku /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker-heroku"] diff --git a/docker/heroku/Dockerfile.arm64 b/docker/heroku/Dockerfile.arm64 new file mode 100644 index 0000000..c9e9fe8 --- /dev/null +++ b/docker/heroku/Dockerfile.arm64 @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-arm64 + +ADD release/linux/arm64/drone-docker-heroku /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker-heroku"]