format via gofumpt (#123)
format code ;) Reviewed-on: https://codeberg.org/woodpecker-plugins/docker-buildx/pulls/123 Reviewed-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
55cc3b1d21
commit
fef922e92a
11
.ecrc
Normal file
11
.ecrc
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"Exclude": [
|
||||||
|
".git",
|
||||||
|
"go.mod", "go.sum",
|
||||||
|
"vendor",
|
||||||
|
"LICENSE",
|
||||||
|
"node_modules",
|
||||||
|
"_test.go",
|
||||||
|
"Makefile"
|
||||||
|
]
|
||||||
|
}
|
19
.editorconfig
Normal file
19
.editorconfig
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
tab_width = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.go]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
|
@ -34,10 +34,24 @@ steps:
|
||||||
|
|
||||||
test:
|
test:
|
||||||
image: *golang
|
image: *golang
|
||||||
|
depends_on: vendor
|
||||||
commands: go test -cover ./...
|
commands: go test -cover ./...
|
||||||
|
|
||||||
|
lint-editorconfig:
|
||||||
|
image: docker.io/mstruebing/editorconfig-checker:2.7.2
|
||||||
|
when:
|
||||||
|
event: pull_request
|
||||||
|
|
||||||
|
lint-format:
|
||||||
|
image: *golang
|
||||||
|
depends_on: vendor
|
||||||
|
commands: make formatcheck
|
||||||
|
when:
|
||||||
|
event: pull_request
|
||||||
|
|
||||||
publish-dryrun:
|
publish-dryrun:
|
||||||
image: *build_plugin
|
image: *build_plugin
|
||||||
|
depends_on: test
|
||||||
pull: true
|
pull: true
|
||||||
settings:
|
settings:
|
||||||
<<: *base_buildx_settings
|
<<: *base_buildx_settings
|
||||||
|
@ -51,6 +65,7 @@ steps:
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
image: *build_plugin
|
image: *build_plugin
|
||||||
|
depends_on: test
|
||||||
settings:
|
settings:
|
||||||
<<: *base_buildx_settings
|
<<: *base_buildx_settings
|
||||||
logins: *login_setting
|
logins: *login_setting
|
||||||
|
@ -60,6 +75,7 @@ steps:
|
||||||
|
|
||||||
publish_pr_image:
|
publish_pr_image:
|
||||||
image: *build_plugin
|
image: *build_plugin
|
||||||
|
depends_on: test
|
||||||
settings:
|
settings:
|
||||||
<<: *base_buildx_settings
|
<<: *base_buildx_settings
|
||||||
tag: pull_${CI_COMMIT_PULL_REQUEST}
|
tag: pull_${CI_COMMIT_PULL_REQUEST}
|
||||||
|
@ -71,6 +87,7 @@ steps:
|
||||||
# TODO: replace by plugin-ready-release-go once it supports gitea
|
# TODO: replace by plugin-ready-release-go once it supports gitea
|
||||||
gitea-release:
|
gitea-release:
|
||||||
image: "woodpeckerci/plugin-gitea-release:0.3.1"
|
image: "woodpeckerci/plugin-gitea-release:0.3.1"
|
||||||
|
depends_on: test
|
||||||
settings:
|
settings:
|
||||||
base_url: https://codeberg.org
|
base_url: https://codeberg.org
|
||||||
title: ${CI_COMMIT_TAG}
|
title: ${CI_COMMIT_TAG}
|
||||||
|
|
12
Makefile
12
Makefile
|
@ -2,5 +2,17 @@ TARGETOS ?= linux
|
||||||
TARGETARCH ?= amd64
|
TARGETARCH ?= amd64
|
||||||
LDFLAGS := -s -w -extldflags "-static"
|
LDFLAGS := -s -w -extldflags "-static"
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -v -a -tags netgo -o plugin-docker-buildx ./cmd/docker-buildx
|
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags '${LDFLAGS}' -v -a -tags netgo -o plugin-docker-buildx ./cmd/docker-buildx
|
||||||
|
|
||||||
|
format: install-tools
|
||||||
|
gofumpt -extra -w .
|
||||||
|
|
||||||
|
formatcheck: install-tools
|
||||||
|
@([ -z "$(shell gofumpt -d . | head)" ]) || (echo "Source is unformatted"; exit 1)
|
||||||
|
|
||||||
|
install-tools: ## Install development tools
|
||||||
|
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
||||||
|
go install mvdan.cc/gofumpt@latest; \
|
||||||
|
fi
|
||||||
|
|
|
@ -19,7 +19,7 @@ func main() {
|
||||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||||
godotenv.Overload("/run/drone/env")
|
godotenv.Overload("/run/drone/env")
|
||||||
}
|
}
|
||||||
|
|
||||||
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
|
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
|
||||||
godotenv.Overload(envFile)
|
godotenv.Overload(envFile)
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -8,6 +8,7 @@ require (
|
||||||
github.com/aws/aws-sdk-go v1.49.17
|
github.com/aws/aws-sdk-go v1.49.17
|
||||||
github.com/drone-plugins/drone-plugin-lib v0.4.2
|
github.com/drone-plugins/drone-plugin-lib v0.4.2
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
|
github.com/pelletier/go-toml/v2 v2.1.1
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.3
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/urfave/cli/v2 v2.27.1
|
github.com/urfave/cli/v2 v2.27.1
|
||||||
|
@ -20,7 +21,6 @@ require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -4,10 +4,6 @@ github.com/6543/go-version v1.3.1 h1:HvOp+Telns7HWJ2Xo/05YXQSB2bE0WmVgbHqwMPZT4U
|
||||||
github.com/6543/go-version v1.3.1/go.mod h1:oqFAHCwtLVUTLdhQmVZWYvaHXTdsbB4SY85at64SQEo=
|
github.com/6543/go-version v1.3.1/go.mod h1:oqFAHCwtLVUTLdhQmVZWYvaHXTdsbB4SY85at64SQEo=
|
||||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
||||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/aws/aws-sdk-go v1.47.4 h1:IyhNbmPt+5ldi5HNzv7ZnXiqSglDMaJiZlzj4Yq3qnk=
|
|
||||||
github.com/aws/aws-sdk-go v1.47.4/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
|
||||||
github.com/aws/aws-sdk-go v1.49.16 h1:KAQwhLg296hfffRdh+itA9p7Nx/3cXS/qOa3uF9ssig=
|
|
||||||
github.com/aws/aws-sdk-go v1.49.16/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
|
||||||
github.com/aws/aws-sdk-go v1.49.17 h1:Cc+7LgPjKeJkF2SdNo1IkpQ5Dfl9HCZEVw9OP3CPuEI=
|
github.com/aws/aws-sdk-go v1.49.17 h1:Cc+7LgPjKeJkF2SdNo1IkpQ5Dfl9HCZEVw9OP3CPuEI=
|
||||||
github.com/aws/aws-sdk-go v1.49.17/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
github.com/aws/aws-sdk-go v1.49.17/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||||
|
@ -39,10 +35,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI=
|
|
||||||
github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
|
||||||
github.com/urfave/cli/v2 v2.27.0 h1:uNs1K8JwTFL84X68j5Fjny6hfANh9nTlJ6dRtZAFAHY=
|
|
||||||
github.com/urfave/cli/v2 v2.27.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
|
||||||
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
|
||||||
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||||
|
|
|
@ -10,14 +10,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommandBuilder(t *testing.T) {
|
func TestCommandBuilder(t *testing.T) {
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Name string
|
Name string
|
||||||
Daemon Daemon
|
Daemon Daemon
|
||||||
Input string
|
Input string
|
||||||
WantedLen int
|
WantedLen int
|
||||||
Skip bool
|
Skip bool
|
||||||
Excuse string
|
Excuse string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "Single driver-opt value",
|
Name: "Single driver-opt value",
|
||||||
|
@ -29,15 +28,14 @@ func TestCommandBuilder(t *testing.T) {
|
||||||
Name: "Single driver-opt value with comma",
|
Name: "Single driver-opt value with comma",
|
||||||
Input: "no_proxy=.mydomain,.sub.domain.com",
|
Input: "no_proxy=.mydomain,.sub.domain.com",
|
||||||
WantedLen: 1,
|
WantedLen: 1,
|
||||||
Skip: true,
|
Skip: true,
|
||||||
Excuse: "Can be enabled whenever #94 is fixed.",
|
Excuse: "Can be enabled whenever #94 is fixed.",
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.Name, func(t *testing.T) {
|
t.Run(test.Name, func(t *testing.T) {
|
||||||
if (test.Skip) {
|
if test.Skip {
|
||||||
t.Skip(fmt.Printf("%v skipped. %v", test.Name, test.Excuse))
|
t.Skip(fmt.Printf("%v skipped. %v", test.Name, test.Excuse))
|
||||||
}
|
}
|
||||||
// prepare test values to mock plugin call with settings
|
// prepare test values to mock plugin call with settings
|
||||||
|
@ -68,5 +66,4 @@ func TestCommandBuilder(t *testing.T) {
|
||||||
assert.Len(t, test.Daemon.BuildkitDriverOpt.Value(), test.WantedLen)
|
assert.Len(t, test.Daemon.BuildkitDriverOpt.Value(), test.WantedLen)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,15 @@ import (
|
||||||
|
|
||||||
const DefaultRegion = "us-east-1"
|
const DefaultRegion = "us-east-1"
|
||||||
|
|
||||||
var repo string
|
var (
|
||||||
var assumeRole string
|
repo string
|
||||||
var externalID string
|
assumeRole string
|
||||||
var ecr_login Login
|
externalID string
|
||||||
var aws_region string
|
ecr_login Login
|
||||||
|
aws_region string
|
||||||
|
)
|
||||||
|
|
||||||
func (p *Plugin) EcrInit() {
|
func (p *Plugin) EcrInit() {
|
||||||
|
|
||||||
// create a standalone Login object to account for single repo and multi-repo case
|
// create a standalone Login object to account for single repo and multi-repo case
|
||||||
if len(p.settings.Logins) >= 1 {
|
if len(p.settings.Logins) >= 1 {
|
||||||
for _, login := range p.settings.Logins {
|
for _, login := range p.settings.Logins {
|
||||||
|
@ -81,7 +82,6 @@ func (p *Plugin) EcrInit() {
|
||||||
|
|
||||||
svc := getECRClient(sess, assumeRole, externalID)
|
svc := getECRClient(sess, assumeRole, externalID)
|
||||||
username, password, registry, err := getAuthInfo(svc)
|
username, password, registry, err := getAuthInfo(svc)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error getting ECR auth: %v", err)
|
log.Fatalf("error getting ECR auth: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,6 @@ func (p *Plugin) EcrInit() {
|
||||||
p.settings.DefaultLogin.Password = password
|
p.settings.DefaultLogin.Password = password
|
||||||
p.settings.DefaultLogin.Registry = registry
|
p.settings.DefaultLogin.Registry = registry
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimHostname(repo, registry string) string {
|
func trimHostname(repo, registry string) string {
|
||||||
|
@ -168,7 +167,7 @@ func updateImageScannningConfig(svc *ecr.ECR, name string, scanOnPush bool) (err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy string, name string) (err error) {
|
func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy, name string) (err error) {
|
||||||
input := &ecr.PutLifecyclePolicyInput{}
|
input := &ecr.PutLifecyclePolicyInput{}
|
||||||
input.SetLifecyclePolicyText(lifecyclePolicy)
|
input.SetLifecyclePolicyText(lifecyclePolicy)
|
||||||
input.SetRepositoryName(name)
|
input.SetRepositoryName(name)
|
||||||
|
@ -177,7 +176,7 @@ func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy string, name string) (e
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadRepositoryPolicy(svc *ecr.ECR, repositoryPolicy string, name string) (err error) {
|
func uploadRepositoryPolicy(svc *ecr.ECR, repositoryPolicy, name string) (err error) {
|
||||||
input := &ecr.SetRepositoryPolicyInput{}
|
input := &ecr.SetRepositoryPolicyInput{}
|
||||||
input.SetPolicyText(repositoryPolicy)
|
input.SetPolicyText(repositoryPolicy)
|
||||||
input.SetRepositoryName(name)
|
input.SetRepositoryName(name)
|
||||||
|
@ -209,7 +208,7 @@ func getAuthInfo(svc *ecr.ECR) (username, password, registry string, err error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getECRClient(sess *session.Session, role string, externalId string) *ecr.ECR {
|
func getECRClient(sess *session.Session, role, externalId string) *ecr.ECR {
|
||||||
if role == "" {
|
if role == "" {
|
||||||
return ecr.New(sess)
|
return ecr.New(sess)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue