Skip to content

Commit

Permalink
Fix ECR & GCR docker publish on windows (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham149 authored Jan 12, 2022
1 parent 0ffe085 commit 47dc855
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 28 deletions.
7 changes: 5 additions & 2 deletions cmd/drone-acr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"strings"

"github.com/joho/godotenv"
"github.com/sirupsen/logrus"

docker "github.com/drone-plugins/drone-docker"
)

func main() {
Expand Down Expand Up @@ -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)
}
}

Expand Down
49 changes: 29 additions & 20 deletions cmd/drone-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"os"
"runtime"

"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -267,26 +268,26 @@ func run(c *cli.Context) error {
Config: c.String("docker.config"),
},
Build: docker.Build{
Remote: c.String("remote.url"),
Name: c.String("commit.sha"),
Dockerfile: c.String("dockerfile"),
Context: c.String("context"),
Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"),
ArgsEnv: c.StringSlice("args-from-env"),
Target: c.String("target"),
Squash: c.Bool("squash"),
Pull: c.BoolT("pull-image"),
CacheFrom: c.StringSlice("cache-from"),
Compress: c.Bool("compress"),
Repo: c.String("repo"),
Labels: c.StringSlice("custom-labels"),
LabelSchema: c.StringSlice("label-schema"),
AutoLabel: c.BoolT("auto-label"),
Link: c.String("link"),
NoCache: c.Bool("no-cache"),
AddHost: c.StringSlice("add-host"),
Quiet: c.Bool("quiet"),
Remote: c.String("remote.url"),
Name: c.String("commit.sha"),
Dockerfile: c.String("dockerfile"),
Context: c.String("context"),
Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"),
ArgsEnv: c.StringSlice("args-from-env"),
Target: c.String("target"),
Squash: c.Bool("squash"),
Pull: c.BoolT("pull-image"),
CacheFrom: c.StringSlice("cache-from"),
Compress: c.Bool("compress"),
Repo: c.String("repo"),
Labels: c.StringSlice("custom-labels"),
LabelSchema: c.StringSlice("label-schema"),
AutoLabel: c.BoolT("auto-label"),
Link: c.String("link"),
NoCache: c.Bool("no-cache"),
AddHost: c.StringSlice("add-host"),
Quiet: c.Bool("quiet"),
},
Daemon: docker.Daemon{
Registry: c.String("docker.registry"),
Expand Down Expand Up @@ -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"
}
7 changes: 5 additions & 2 deletions cmd/drone-ecr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/drone-gcr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"strings"

"github.com/joho/godotenv"
"github.com/sirupsen/logrus"

docker "github.com/drone-plugins/drone-docker"
)

// gcr default username
Expand Down Expand Up @@ -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)
}
}

Expand Down
9 changes: 9 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
)
Expand Down Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion scripts/windows/latest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/windows/tag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47dc855

Please sign in to comment.