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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 28 deletions

View File

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

View File

@ -2,6 +2,7 @@ package main
import (
"os"
"runtime"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
@ -327,3 +328,11 @@ func run(c *cli.Context) error {
return plugin.Exec()
}
func GetExecCmd() string {
if runtime.GOOS == "windows" {
return "C:/bin/drone-docker.exe"
}
return "drone-docker"
}

View File

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

View File

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

View File

@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
)
@ -416,3 +417,11 @@ func commandRmi(tag string) *exec.Cmd {
func trace(cmd *exec.Cmd) {
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"
}

View File

@ -20,7 +20,7 @@ echo $env:VERSION
echo $env:REGISTRY
# 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}
# build and publish the docker image

View File

@ -30,7 +30,7 @@ echo $env:GOARCH
echo $env:VERSION
# 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}
# authenticate with the docker registry