Skip to content

Commit 7206114

Browse files
Add plugin support for drone-buildx
1 parent 78fd2a5 commit 7206114

File tree

4 files changed

+88
-6
lines changed

4 files changed

+88
-6
lines changed

.drone.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,3 +992,56 @@ depends_on:
992992
- windows-ltsc2022
993993
- linux-amd64-acr
994994
- linux-arm64-acr
995+
---
996+
997+
kind: pipeline
998+
name: release-binaries
999+
type: vm
1000+
1001+
pool:
1002+
use: ubuntu
1003+
1004+
steps:
1005+
- name: build
1006+
pull: always
1007+
image: golang:1.19
1008+
commands:
1009+
- GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-linux-amd64 ./cmd/drone-docker
1010+
- GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-linux-arm64 ./cmd/drone-docker
1011+
- GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-darwin-amd64 ./cmd/drone-docker
1012+
- GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-darwin-arm64 ./cmd/drone-docker
1013+
- GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-windows-amd64.exe ./cmd/drone-docker
1014+
1015+
environment:
1016+
CGO_ENABLED: 0
1017+
GO111MODULE: on
1018+
1019+
- name: zstd-compress
1020+
commands:
1021+
- sudo apt-get update -y
1022+
- sudo apt-get install -y zstd
1023+
- zstd release/drone-buildx-linux-amd64
1024+
- zstd release/drone-buildx-linux-arm64
1025+
- zstd release/drone-buildx-darwin-arm64
1026+
- zstd release/drone-buildx-darwin-amd64
1027+
- zstd release/drone-buildx-windows-amd64.exe
1028+
1029+
- name: release
1030+
image: plugins/github-release
1031+
settings:
1032+
files:
1033+
- release/drone-buildx-linux-amd64.zst
1034+
- release/drone-buildx-linux-arm64.zst
1035+
- release/drone-buildx-darwin-arm64.zst
1036+
- release/drone-buildx-darwin-amd64.zst
1037+
- release/drone-buildx-windows-amd64.exe.zst
1038+
api_key:
1039+
from_secret: github_token
1040+
when:
1041+
event:
1042+
- tag
1043+
depends_on:
1044+
- windows-1809
1045+
- windows-ltsc2022
1046+
- linux-amd64-docker
1047+
- linux-arm64-docker

daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os"
99
)
1010

11-
const dockerExe = "/usr/bin/docker"
11+
const dockerExe = "docker"
1212
const dockerdExe = "/usr/bin/dockerd"
1313
const dockerHome = "/root/.docker/"
1414

docker_test.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"testing"
77
)
88

9-
func TestCommandBuild(t *testing.T) {
9+
func TestCommandBuildx(t *testing.T) {
1010
tcs := []struct {
11-
name string
12-
build Build
13-
want *exec.Cmd
11+
name string
12+
build Build
13+
builder Builder
14+
dryrun bool
15+
want *exec.Cmd
1416
}{
1517
{
1618
name: "secret from env var",
@@ -21,15 +23,19 @@ func TestCommandBuild(t *testing.T) {
2123
SecretEnvs: []string{
2224
"foo_secret=FOO_SECRET_ENV_VAR",
2325
},
26+
Repo: "plugins/drone-docker",
27+
Tags: []string{"latest"},
2428
},
2529
want: exec.Command(
2630
dockerExe,
31+
"buildx",
2732
"build",
2833
"--rm=true",
2934
"-f",
3035
"Dockerfile",
3136
"-t",
3237
"plugins/drone-docker:latest",
38+
"--push",
3339
".",
3440
"--secret id=foo_secret,env=FOO_SECRET_ENV_VAR",
3541
),
@@ -43,15 +49,19 @@ func TestCommandBuild(t *testing.T) {
4349
SecretFiles: []string{
4450
"foo_secret=/path/to/foo_secret",
4551
},
52+
Repo: "plugins/drone-docker",
53+
Tags: []string{"latest"},
4654
},
4755
want: exec.Command(
4856
dockerExe,
57+
"buildx",
4958
"build",
5059
"--rm=true",
5160
"-f",
5261
"Dockerfile",
5362
"-t",
5463
"plugins/drone-docker:latest",
64+
"--push",
5565
".",
5666
"--secret id=foo_secret,src=/path/to/foo_secret",
5767
),
@@ -70,15 +80,19 @@ func TestCommandBuild(t *testing.T) {
7080
"foo_secret=/path/to/foo_secret",
7181
"bar_secret=/path/to/bar_secret",
7282
},
83+
Repo: "plugins/drone-docker",
84+
Tags: []string{"latest"},
7385
},
7486
want: exec.Command(
7587
dockerExe,
88+
"buildx",
7689
"build",
7790
"--rm=true",
7891
"-f",
7992
"Dockerfile",
8093
"-t",
8194
"plugins/drone-docker:latest",
95+
"--push",
8296
".",
8397
"--secret id=foo_secret,env=FOO_SECRET_ENV_VAR",
8498
"--secret id=bar_secret,env=BAR_SECRET_ENV_VAR",
@@ -102,15 +116,19 @@ func TestCommandBuild(t *testing.T) {
102116
"=/path/to/bar_secret",
103117
"",
104118
},
119+
Repo: "plugins/drone-docker",
120+
Tags: []string{"latest"},
105121
},
106122
want: exec.Command(
107123
dockerExe,
124+
"buildx",
108125
"build",
109126
"--rm=true",
110127
"-f",
111128
"Dockerfile",
112129
"-t",
113130
"plugins/drone-docker:latest",
131+
"--push",
114132
".",
115133
),
116134
},
@@ -121,15 +139,19 @@ func TestCommandBuild(t *testing.T) {
121139
Dockerfile: "Dockerfile",
122140
Context: ".",
123141
Platform: "test/platform",
142+
Repo: "plugins/drone-docker",
143+
Tags: []string{"latest"},
124144
},
125145
want: exec.Command(
126146
dockerExe,
147+
"buildx",
127148
"build",
128149
"--rm=true",
129150
"-f",
130151
"Dockerfile",
131152
"-t",
132153
"plugins/drone-docker:latest",
154+
"--push",
133155
".",
134156
"--platform",
135157
"test/platform",
@@ -142,15 +164,19 @@ func TestCommandBuild(t *testing.T) {
142164
Dockerfile: "Dockerfile",
143165
Context: ".",
144166
SSHKeyPath: "id_rsa=/root/.ssh/id_rsa",
167+
Repo: "plugins/drone-docker",
168+
Tags: []string{"latest"},
145169
},
146170
want: exec.Command(
147171
dockerExe,
172+
"buildx",
148173
"build",
149174
"--rm=true",
150175
"-f",
151176
"Dockerfile",
152177
"-t",
153178
"plugins/drone-docker:latest",
179+
"--push",
154180
".",
155181
"--ssh id_rsa=/root/.ssh/id_rsa",
156182
),
@@ -161,7 +187,7 @@ func TestCommandBuild(t *testing.T) {
161187
tc := tc
162188

163189
t.Run(tc.name, func(t *testing.T) {
164-
cmd := commandBuild(tc.build)
190+
cmd := commandBuildx(tc.build, tc.builder, tc.dryrun)
165191

166192
if !reflect.DeepEqual(cmd.String(), tc.want.String()) {
167193
t.Errorf("Got cmd %v, want %v", cmd, tc.want)

plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
run:
2+
binary:
3+
source: https://github.com/drone-plugins/drone-buildx/releases/download/{{ release }}/drone-buildx-{{ os }}-{{ arch }}.zst

0 commit comments

Comments
 (0)