Skip to content

Commit 47dc855

Browse files
authored
Fix ECR & GCR docker publish on windows (#352)
1 parent 0ffe085 commit 47dc855

File tree

7 files changed

+55
-28
lines changed

7 files changed

+55
-28
lines changed

cmd/drone-acr/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"strings"
88

99
"github.com/joho/godotenv"
10+
"github.com/sirupsen/logrus"
11+
12+
docker "github.com/drone-plugins/drone-docker"
1013
)
1114

1215
func main() {
@@ -40,12 +43,12 @@ func main() {
4043
os.Setenv("DOCKER_PASSWORD", password)
4144

4245
// invoke the base docker plugin binary
43-
cmd := exec.Command("drone-docker")
46+
cmd := exec.Command(docker.GetDroneDockerExecCmd())
4447
cmd.Stdout = os.Stdout
4548
cmd.Stderr = os.Stderr
4649
err := cmd.Run()
4750
if err != nil {
48-
os.Exit(1)
51+
logrus.Fatal(err)
4952
}
5053
}
5154

cmd/drone-docker/main.go

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"os"
5+
"runtime"
56

67
"github.com/joho/godotenv"
78
"github.com/sirupsen/logrus"
@@ -267,26 +268,26 @@ func run(c *cli.Context) error {
267268
Config: c.String("docker.config"),
268269
},
269270
Build: docker.Build{
270-
Remote: c.String("remote.url"),
271-
Name: c.String("commit.sha"),
272-
Dockerfile: c.String("dockerfile"),
273-
Context: c.String("context"),
274-
Tags: c.StringSlice("tags"),
275-
Args: c.StringSlice("args"),
276-
ArgsEnv: c.StringSlice("args-from-env"),
277-
Target: c.String("target"),
278-
Squash: c.Bool("squash"),
279-
Pull: c.BoolT("pull-image"),
280-
CacheFrom: c.StringSlice("cache-from"),
281-
Compress: c.Bool("compress"),
282-
Repo: c.String("repo"),
283-
Labels: c.StringSlice("custom-labels"),
284-
LabelSchema: c.StringSlice("label-schema"),
285-
AutoLabel: c.BoolT("auto-label"),
286-
Link: c.String("link"),
287-
NoCache: c.Bool("no-cache"),
288-
AddHost: c.StringSlice("add-host"),
289-
Quiet: c.Bool("quiet"),
271+
Remote: c.String("remote.url"),
272+
Name: c.String("commit.sha"),
273+
Dockerfile: c.String("dockerfile"),
274+
Context: c.String("context"),
275+
Tags: c.StringSlice("tags"),
276+
Args: c.StringSlice("args"),
277+
ArgsEnv: c.StringSlice("args-from-env"),
278+
Target: c.String("target"),
279+
Squash: c.Bool("squash"),
280+
Pull: c.BoolT("pull-image"),
281+
CacheFrom: c.StringSlice("cache-from"),
282+
Compress: c.Bool("compress"),
283+
Repo: c.String("repo"),
284+
Labels: c.StringSlice("custom-labels"),
285+
LabelSchema: c.StringSlice("label-schema"),
286+
AutoLabel: c.BoolT("auto-label"),
287+
Link: c.String("link"),
288+
NoCache: c.Bool("no-cache"),
289+
AddHost: c.StringSlice("add-host"),
290+
Quiet: c.Bool("quiet"),
290291
},
291292
Daemon: docker.Daemon{
292293
Registry: c.String("docker.registry"),
@@ -327,3 +328,11 @@ func run(c *cli.Context) error {
327328

328329
return plugin.Exec()
329330
}
331+
332+
func GetExecCmd() string {
333+
if runtime.GOOS == "windows" {
334+
return "C:/bin/drone-docker.exe"
335+
}
336+
337+
return "drone-docker"
338+
}

cmd/drone-ecr/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import (
1111
"strings"
1212

1313
"github.com/joho/godotenv"
14+
"github.com/sirupsen/logrus"
1415

1516
"github.com/aws/aws-sdk-go/aws"
1617
"github.com/aws/aws-sdk-go/aws/awserr"
1718
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
1819
"github.com/aws/aws-sdk-go/aws/session"
1920
"github.com/aws/aws-sdk-go/service/ecr"
21+
22+
docker "github.com/drone-plugins/drone-docker"
2023
)
2124

2225
const defaultRegion = "us-east-1"
@@ -110,11 +113,11 @@ func main() {
110113
os.Setenv("DOCKER_PASSWORD", password)
111114

112115
// invoke the base docker plugin binary
113-
cmd := exec.Command("drone-docker")
116+
cmd := exec.Command(docker.GetDroneDockerExecCmd())
114117
cmd.Stdout = os.Stdout
115118
cmd.Stderr = os.Stderr
116119
if err = cmd.Run(); err != nil {
117-
os.Exit(1)
120+
logrus.Fatal(err)
118121
}
119122
}
120123

cmd/drone-gcr/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
"strings"
99

1010
"github.com/joho/godotenv"
11+
"github.com/sirupsen/logrus"
12+
13+
docker "github.com/drone-plugins/drone-docker"
1114
)
1215

1316
// gcr default username
@@ -54,12 +57,12 @@ func main() {
5457
os.Setenv("DOCKER_PASSWORD", password)
5558

5659
// invoke the base docker plugin binary
57-
cmd := exec.Command("drone-docker")
60+
cmd := exec.Command(docker.GetDroneDockerExecCmd())
5861
cmd.Stdout = os.Stdout
5962
cmd.Stderr = os.Stderr
6063
err = cmd.Run()
6164
if err != nil {
62-
os.Exit(1)
65+
logrus.Fatal(err)
6366
}
6467
}
6568

docker.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011
"time"
1112
)
@@ -416,3 +417,11 @@ func commandRmi(tag string) *exec.Cmd {
416417
func trace(cmd *exec.Cmd) {
417418
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
418419
}
420+
421+
func GetDroneDockerExecCmd() string {
422+
if runtime.GOOS == "windows" {
423+
return "C:/bin/drone-docker.exe"
424+
}
425+
426+
return "drone-docker"
427+
}

scripts/windows/latest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo $env:VERSION
2020
echo $env:REGISTRY
2121

2222
# build the binary
23-
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe";
23+
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}";
2424
go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}
2525

2626
# build and publish the docker image

scripts/windows/tag.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ echo $env:GOARCH
3030
echo $env:VERSION
3131

3232
# build the binary
33-
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe"
33+
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}"
3434
go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}
3535

3636
# authenticate with the docker registry

0 commit comments

Comments
 (0)