Fix ECR & GCR docker publish on windows (#352)

This commit is contained in:
Shubham Agrawal 2022-01-12 22:32:57 +05:30 committed by GitHub
parent 0ffe085ddc
commit 47dc8555ad
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 28 deletions

@ -7,6 +7,9 @@ import (
"strings" "strings"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/sirupsen/logrus"
docker "github.com/drone-plugins/drone-docker"
) )
func main() { func main() {
@ -40,12 +43,12 @@ func main() {
os.Setenv("DOCKER_PASSWORD", password) os.Setenv("DOCKER_PASSWORD", password)
// invoke the base docker plugin binary // invoke the base docker plugin binary
cmd := exec.Command("drone-docker") cmd := exec.Command(docker.GetDroneDockerExecCmd())
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
os.Exit(1) logrus.Fatal(err)
} }
} }

@ -2,6 +2,7 @@ package main
import ( import (
"os" "os"
"runtime"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -267,26 +268,26 @@ func run(c *cli.Context) error {
Config: c.String("docker.config"), Config: c.String("docker.config"),
}, },
Build: docker.Build{ Build: docker.Build{
Remote: c.String("remote.url"), Remote: c.String("remote.url"),
Name: c.String("commit.sha"), Name: c.String("commit.sha"),
Dockerfile: c.String("dockerfile"), Dockerfile: c.String("dockerfile"),
Context: c.String("context"), Context: c.String("context"),
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"), Args: c.StringSlice("args"),
ArgsEnv: c.StringSlice("args-from-env"), ArgsEnv: c.StringSlice("args-from-env"),
Target: c.String("target"), Target: c.String("target"),
Squash: c.Bool("squash"), Squash: c.Bool("squash"),
Pull: c.BoolT("pull-image"), Pull: c.BoolT("pull-image"),
CacheFrom: c.StringSlice("cache-from"), CacheFrom: c.StringSlice("cache-from"),
Compress: c.Bool("compress"), Compress: c.Bool("compress"),
Repo: c.String("repo"), Repo: c.String("repo"),
Labels: c.StringSlice("custom-labels"), Labels: c.StringSlice("custom-labels"),
LabelSchema: c.StringSlice("label-schema"), LabelSchema: c.StringSlice("label-schema"),
AutoLabel: c.BoolT("auto-label"), AutoLabel: c.BoolT("auto-label"),
Link: c.String("link"), Link: c.String("link"),
NoCache: c.Bool("no-cache"), NoCache: c.Bool("no-cache"),
AddHost: c.StringSlice("add-host"), AddHost: c.StringSlice("add-host"),
Quiet: c.Bool("quiet"), Quiet: c.Bool("quiet"),
}, },
Daemon: docker.Daemon{ Daemon: docker.Daemon{
Registry: c.String("docker.registry"), Registry: c.String("docker.registry"),
@ -327,3 +328,11 @@ func run(c *cli.Context) error {
return plugin.Exec() return plugin.Exec()
} }
func GetExecCmd() string {
if runtime.GOOS == "windows" {
return "C:/bin/drone-docker.exe"
}
return "drone-docker"
}

@ -11,12 +11,15 @@ import (
"strings" "strings"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" "github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ecr" "github.com/aws/aws-sdk-go/service/ecr"
docker "github.com/drone-plugins/drone-docker"
) )
const defaultRegion = "us-east-1" const defaultRegion = "us-east-1"
@ -110,11 +113,11 @@ func main() {
os.Setenv("DOCKER_PASSWORD", password) os.Setenv("DOCKER_PASSWORD", password)
// invoke the base docker plugin binary // invoke the base docker plugin binary
cmd := exec.Command("drone-docker") cmd := exec.Command(docker.GetDroneDockerExecCmd())
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
if err = cmd.Run(); err != nil { if err = cmd.Run(); err != nil {
os.Exit(1) logrus.Fatal(err)
} }
} }

@ -8,6 +8,9 @@ import (
"strings" "strings"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/sirupsen/logrus"
docker "github.com/drone-plugins/drone-docker"
) )
// gcr default username // gcr default username
@ -54,12 +57,12 @@ func main() {
os.Setenv("DOCKER_PASSWORD", password) os.Setenv("DOCKER_PASSWORD", password)
// invoke the base docker plugin binary // invoke the base docker plugin binary
cmd := exec.Command("drone-docker") cmd := exec.Command(docker.GetDroneDockerExecCmd())
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
os.Exit(1) logrus.Fatal(err)
} }
} }

@ -6,6 +6,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"time" "time"
) )
@ -416,3 +417,11 @@ func commandRmi(tag string) *exec.Cmd {
func trace(cmd *exec.Cmd) { func trace(cmd *exec.Cmd) {
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " ")) fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
} }
func GetDroneDockerExecCmd() string {
if runtime.GOOS == "windows" {
return "C:/bin/drone-docker.exe"
}
return "drone-docker"
}

@ -20,7 +20,7 @@ echo $env:VERSION
echo $env:REGISTRY echo $env:REGISTRY
# build the binary # build the binary
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe"; Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}";
go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY} go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}
# build and publish the docker image # build and publish the docker image

@ -30,7 +30,7 @@ echo $env:GOARCH
echo $env:VERSION echo $env:VERSION
# build the binary # build the binary
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe" Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}"
go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY} go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}
# authenticate with the docker registry # authenticate with the docker registry