Skip to content

Commit fd20e9a

Browse files
Docker buildx support
1 parent 3aa3a43 commit fd20e9a

File tree

5 files changed

+202
-0
lines changed

5 files changed

+202
-0
lines changed

.drone.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
kind: pipeline
3+
name: testing
4+
type: vm
5+
6+
pool:
7+
use: ubuntu
8+
9+
platform:
10+
os: linux
11+
arch: amd64
12+
13+
steps:
14+
- name: vet
15+
image: golang:1.17
16+
commands:
17+
- go vet ./...
18+
environment:
19+
20+
volumes:
21+
- name: gopath
22+
path: /go
23+
24+
volumes:
25+
- name: gopath
26+
temp: {}
27+
28+
trigger:
29+
ref:
30+
- refs/heads/main
31+
- "refs/tags/**"
32+
- "refs/pull/**"
33+
34+
---
35+
36+
kind: pipeline
37+
name: release-binaries
38+
type: vm
39+
40+
pool:
41+
use: ubuntu
42+
43+
steps:
44+
- name: build
45+
pull: always
46+
image: golang:1.19
47+
commands:
48+
- GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-acr-linux-amd64 ./cmd/drone-buildx-acr
49+
- GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-acr-linux-arm64 ./cmd/drone-buildx-acr
50+
- GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-acr-darwin-amd64 ./cmd/drone-buildx-acr
51+
- GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-acr-darwin-arm64 ./cmd/drone-buildx-acr
52+
- GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-acr-windows-amd64.exe ./cmd/drone-buildx-acr
53+
54+
environment:
55+
CGO_ENABLED: 0
56+
GO111MODULE: on
57+
58+
- name: zstd-compress
59+
commands:
60+
- sudo apt-get update -y
61+
- sudo apt-get install -y zstd
62+
- zstd release/drone-buildx-acr-linux-amd64
63+
- zstd release/drone-buildx-acr-linux-arm64
64+
- zstd release/drone-buildx-acr-darwin-arm64
65+
- zstd release/drone-buildx-acr-darwin-amd64
66+
- zstd release/drone-buildx-acr-windows-amd64.exe
67+
68+
- name: release
69+
image: plugins/github-release
70+
settings:
71+
files:
72+
- release/drone-buildx-acr-linux-amd64.zst
73+
- release/drone-buildx-acr-linux-arm64.zst
74+
- release/drone-buildx-acr-darwin-arm64.zst
75+
- release/drone-buildx-acr-darwin-amd64.zst
76+
- release/drone-buildx-acr-windows-amd64.exe.zst
77+
api_key:
78+
from_secret: github_token
79+
when:
80+
event:
81+
- tag
82+
depends_on:
83+
- testing

cmd/drone-buildx-acr/main.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"github.com/joho/godotenv"
9+
10+
docker "github.com/drone-plugins/drone-buildx"
11+
)
12+
13+
func main() {
14+
// Load env-file if it exists first
15+
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
16+
godotenv.Load(env)
17+
}
18+
19+
var (
20+
repo = getenv("PLUGIN_REPO")
21+
registry = getenv("PLUGIN_REGISTRY")
22+
username = getenv("SERVICE_PRINCIPAL_CLIENT_ID")
23+
password = getenv("SERVICE_PRINCIPAL_CLIENT_SECRET")
24+
)
25+
26+
// default registry value
27+
if registry == "" {
28+
registry = "azurecr.io"
29+
}
30+
31+
// must use the fully qualified repo name. If the
32+
// repo name does not have the registry prefix we
33+
// should prepend.
34+
if !strings.HasPrefix(repo, registry) {
35+
repo = fmt.Sprintf("%s/%s", registry, repo)
36+
}
37+
38+
os.Setenv("PLUGIN_REPO", repo)
39+
os.Setenv("PLUGIN_REGISTRY", registry)
40+
os.Setenv("DOCKER_USERNAME", username)
41+
os.Setenv("DOCKER_PASSWORD", password)
42+
os.Setenv("PLUGIN_REGISTRY_TYPE", "ACR")
43+
44+
// invoke the base docker plugin binary
45+
docker.Run()
46+
}
47+
48+
func getenv(key ...string) (s string) {
49+
for _, k := range key {
50+
s = os.Getenv(k)
51+
if s != "" {
52+
return
53+
}
54+
}
55+
return
56+
}

go.mod

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module github.com/drone-plugins/drone-buildx-acr
2+
3+
go 1.19
4+
5+
require (
6+
github.com/drone-plugins/drone-buildx v1.0.2-0.20230512061850-99d0da95877e
7+
github.com/joho/godotenv v1.5.1
8+
)
9+
10+
require (
11+
github.com/coreos/go-semver v0.3.0 // indirect
12+
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
13+
github.com/drone/drone-go v1.7.1 // indirect
14+
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743 // indirect
15+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
16+
github.com/sirupsen/logrus v1.9.3 // indirect
17+
github.com/urfave/cli v1.22.2 // indirect
18+
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
19+
)

go.sum

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
4+
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
5+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
6+
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
7+
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
8+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
10+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11+
github.com/drone-plugins/drone-buildx v1.0.2-0.20230512061850-99d0da95877e h1:UVfB6v/wptaDtyfhEwxnUXViMfEiN97LudyfSeLw2hA=
12+
github.com/drone-plugins/drone-buildx v1.0.2-0.20230512061850-99d0da95877e/go.mod h1:2CEwXGujWoB9bBQqknU214yd/FJzUNDDHGlg9qb3M4c=
13+
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw=
14+
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg=
15+
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
16+
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
17+
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743 h1:X3Xxno5Ji8idrNiUoFc7QyXpqhSYlDRYQmc7mlpMBzU=
18+
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743/go.mod h1:KrtyD5PFj++GKkFS/7/RRrfnRhAMGQwy75GLCHWrCNs=
19+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
20+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
21+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
22+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
23+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
24+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
25+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
26+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
27+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
28+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
29+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
30+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
31+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
32+
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
33+
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
34+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
35+
golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80=
36+
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
37+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
38+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
39+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
40+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
41+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

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-acr/releases/download/{{ release }}/drone-buildx-acr-{{ os }}-{{ arch }}.zst

0 commit comments

Comments
 (0)