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"
@ -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