-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc7254d
commit d503032
Showing
4 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
kind: pipeline | ||
name: testing | ||
type: vm | ||
|
||
pool: | ||
use: ubuntu | ||
|
||
platform: | ||
os: linux | ||
arch: amd64 | ||
|
||
steps: | ||
- name: vet | ||
image: golang:1.17 | ||
commands: | ||
- go vet ./... | ||
environment: | ||
|
||
volumes: | ||
- name: gopath | ||
path: /go | ||
|
||
volumes: | ||
- name: gopath | ||
temp: {} | ||
|
||
trigger: | ||
ref: | ||
- refs/heads/main | ||
- "refs/tags/**" | ||
- "refs/pull/**" | ||
|
||
--- | ||
|
||
kind: pipeline | ||
name: release-binaries | ||
type: vm | ||
|
||
pool: | ||
use: ubuntu | ||
|
||
steps: | ||
- name: build | ||
pull: always | ||
image: golang:1.19 | ||
commands: | ||
- GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-gcr-linux-amd64 ./cmd/drone-buildx-gcr | ||
- GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-gcr-linux-arm64 ./cmd/drone-buildx-gcr | ||
- GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-gcr-darwin-amd64 ./cmd/drone-buildx-gcr | ||
- GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-gcr-darwin-arm64 ./cmd/drone-buildx-gcr | ||
- GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -a -tags netgo -o release/drone-buildx-gcr-windows-amd64.exe ./cmd/drone-buildx-gcr | ||
|
||
environment: | ||
CGO_ENABLED: 0 | ||
GO111MODULE: on | ||
|
||
- name: zstd-compress | ||
commands: | ||
- sudo apt-get update -y | ||
- sudo apt-get install -y zstd | ||
- zstd release/drone-buildx-gcr-linux-amd64 | ||
- zstd release/drone-buildx-gcr-linux-arm64 | ||
- zstd release/drone-buildx-gcr-darwin-arm64 | ||
- zstd release/drone-buildx-gcr-darwin-amd64 | ||
- zstd release/drone-buildx-gcr-windows-amd64.exe | ||
|
||
- name: release | ||
image: plugins/github-release | ||
settings: | ||
files: | ||
- release/drone-buildx-gcr-linux-amd64.zst | ||
- release/drone-buildx-gcr-linux-arm64.zst | ||
- release/drone-buildx-gcr-darwin-arm64.zst | ||
- release/drone-buildx-gcr-darwin-amd64.zst | ||
- release/drone-buildx-gcr-windows-amd64.exe.zst | ||
api_key: | ||
from_secret: github_token | ||
when: | ||
event: | ||
- tag | ||
depends_on: | ||
- testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"os" | ||
"path" | ||
"strings" | ||
|
||
docker "github.com/drone-plugins/drone-buildx" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
// gcr default username | ||
const username = "_json_key" | ||
|
||
func main() { | ||
// Load env-file if it exists first | ||
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" { | ||
godotenv.Load(env) | ||
} | ||
|
||
var ( | ||
repo = getenv("PLUGIN_REPO") | ||
registry = getenv("PLUGIN_REGISTRY") | ||
password = getenv( | ||
"PLUGIN_JSON_KEY", | ||
"GCR_JSON_KEY", | ||
"GOOGLE_CREDENTIALS", | ||
"TOKEN", | ||
) | ||
) | ||
|
||
// decode the token if base64 encoded | ||
decoded, err := base64.StdEncoding.DecodeString(password) | ||
if err == nil { | ||
password = string(decoded) | ||
} | ||
|
||
// default registry value | ||
if registry == "" { | ||
registry = "gcr.io" | ||
} | ||
|
||
// must use the fully qualified repo name. If the | ||
// repo name does not have the registry prefix we | ||
// should prepend. | ||
if !strings.HasPrefix(repo, registry) { | ||
repo = path.Join(registry, repo) | ||
} | ||
|
||
os.Setenv("PLUGIN_REPO", repo) | ||
os.Setenv("PLUGIN_REGISTRY", registry) | ||
os.Setenv("DOCKER_USERNAME", username) | ||
os.Setenv("DOCKER_PASSWORD", password) | ||
os.Setenv("PLUGIN_REGISTRY_TYPE", "GCR") | ||
|
||
// invoke the base docker plugin binary | ||
docker.Run() | ||
} | ||
|
||
func getenv(key ...string) (s string) { | ||
for _, k := range key { | ||
s = os.Getenv(k) | ||
if s != "" { | ||
return | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module github.com/drone-plugins/drone-buildx-gcr | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/joho/godotenv v1.5.1 | ||
) | ||
|
||
require ( | ||
github.com/coreos/go-semver v0.3.0 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect | ||
github.com/drone-plugins/drone-buildx v1.0.2-0.20230512061850-99d0da95877e // indirect | ||
github.com/drone-plugins/drone-plugin-lib v0.4.1 // indirect | ||
github.com/drone/drone-go v1.7.1 // indirect | ||
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/sirupsen/logrus v1.9.0 // indirect | ||
github.com/urfave/cli v1.22.2 // indirect | ||
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY= | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= | ||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/dchest/uniuri v1.2.0 h1:koIcOUdrTIivZgSLhHQvKgqdWZq5d7KdMEWF1Ud6+5g= | ||
github.com/drone-plugins/drone-buildx v1.0.2-0.20230512061850-99d0da95877e h1:UVfB6v/wptaDtyfhEwxnUXViMfEiN97LudyfSeLw2hA= | ||
github.com/drone-plugins/drone-buildx v1.0.2-0.20230512061850-99d0da95877e/go.mod h1:2CEwXGujWoB9bBQqknU214yd/FJzUNDDHGlg9qb3M4c= | ||
github.com/drone-plugins/drone-docker v0.0.0-20230516214326-025dfb0adcad h1:0/CtKuTi5zR9GZiVTHyjdnFLwp9EPYskOg4x9HpUEdw= | ||
github.com/drone-plugins/drone-docker v0.0.0-20230516214326-025dfb0adcad/go.mod h1:x+jHIgW3nIN9/h6053fExzCFKKjCrH22Cnsm7nQJcrs= | ||
github.com/drone-plugins/drone-plugin-lib v0.4.1 h1:47rZlmcMpr1hSp+6Gl+1Z4t+efi/gMQU3lxukC1Yg64= | ||
github.com/drone-plugins/drone-plugin-lib v0.4.1/go.mod h1:KwCu92jFjHV3xv2hu5Qg/8zBNvGwbhoJDQw/EwnTvoM= | ||
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw= | ||
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg= | ||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= | ||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= | ||
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743 h1:X3Xxno5Ji8idrNiUoFc7QyXpqhSYlDRYQmc7mlpMBzU= | ||
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743/go.mod h1:KrtyD5PFj++GKkFS/7/RRrfnRhAMGQwy75GLCHWrCNs= | ||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= | ||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= | ||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= | ||
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80= | ||
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |