mirror of
https://github.com/thegeeklab/wp-docker-buildx.git
synced 2024-11-21 13:50:39 +00:00
chore: revert multi-registry support (#311)
This commit is contained in:
parent
0cc14f4114
commit
08408124c6
@ -95,29 +95,6 @@ steps:
|
||||
tags: latest
|
||||
```
|
||||
|
||||
#### Push to multiple registries
|
||||
|
||||
```yaml
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: docker
|
||||
image: thegeeklab/drone-docker-buildx:23
|
||||
privileged: true
|
||||
settings:
|
||||
repo:
|
||||
- octocat/example
|
||||
- ghcr.io/octocat/example
|
||||
tags: latest
|
||||
registries:
|
||||
- username: octocat
|
||||
password: docker-password
|
||||
- registry: ghcr.io
|
||||
username: octocat
|
||||
password: ghrc-password
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Build the binary with the following command:
|
||||
|
@ -208,7 +208,7 @@ properties:
|
||||
description: |
|
||||
Repository name for the image. If the image is to be pushed to registries other than the default DockerHub,
|
||||
it is necessary to set `repo` as fully-qualified name.
|
||||
type: list
|
||||
type: string
|
||||
required: false
|
||||
|
||||
- name: registry
|
||||
@ -293,8 +293,3 @@ properties:
|
||||
This should be used with caution and avoided whenever possible.
|
||||
type: list
|
||||
required: false
|
||||
|
||||
- name: registries
|
||||
description: List of registry credentials. Check out the Examples for more information.
|
||||
type: list
|
||||
required: false
|
||||
|
@ -235,7 +235,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
||||
Destination: &settings.Build.Compress,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "repo",
|
||||
EnvVars: []string{"PLUGIN_REPO"},
|
||||
Usage: "repository name for the image",
|
||||
@ -246,7 +246,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
||||
Name: "docker.registry",
|
||||
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
|
||||
Usage: "docker registry to authenticate with",
|
||||
Value: plugin.DefaultRegistry,
|
||||
Value: "https://index.docker.io/v1/",
|
||||
Destination: &settings.Login.Registry,
|
||||
Category: category,
|
||||
},
|
||||
@ -328,13 +328,5 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
||||
Value: &drone.StringSliceFlag{},
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "docker.registries",
|
||||
EnvVars: []string{"PLUGIN_REGISTRIES"},
|
||||
Usage: "credentials for registries",
|
||||
Value: "[]",
|
||||
Destination: &settings.Login.RegistriesRaw,
|
||||
Category: category,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
7
go.mod
7
go.mod
@ -6,20 +6,13 @@ require (
|
||||
github.com/coreos/go-semver v0.3.1
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4
|
||||
github.com/urfave/cli/v2 v2.25.5
|
||||
golang.org/x/sys v0.11.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
1
go.sum
1
go.sum
@ -25,7 +25,6 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// helper function to create the docker login command.
|
||||
func commandLogin(login RegistryData) *execabs.Cmd {
|
||||
func commandLogin(login Login) *execabs.Cmd {
|
||||
if login.Email != "" {
|
||||
return commandLoginEmail(login)
|
||||
}
|
||||
@ -28,7 +28,7 @@ func commandLogin(login RegistryData) *execabs.Cmd {
|
||||
)
|
||||
}
|
||||
|
||||
func commandLoginEmail(login RegistryData) *execabs.Cmd {
|
||||
func commandLoginEmail(login Login) *execabs.Cmd {
|
||||
args := []string{
|
||||
"login",
|
||||
"-u", login.Username,
|
||||
@ -140,10 +140,8 @@ func commandBuild(build Build, dryrun bool) *execabs.Cmd {
|
||||
args = append(args, "--platform", strings.Join(build.Platforms.Value(), ","))
|
||||
}
|
||||
|
||||
for _, repo := range build.Repo.Value() {
|
||||
for _, arg := range build.Tags.Value() {
|
||||
args = append(args, "-t", fmt.Sprintf("%s:%s", repo, arg))
|
||||
}
|
||||
for _, arg := range build.Tags.Value() {
|
||||
args = append(args, "-t", fmt.Sprintf("%s:%s", build.Repo, arg))
|
||||
}
|
||||
|
||||
for _, arg := range build.ExtraTags.Value() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -32,17 +31,11 @@ type Daemon struct {
|
||||
|
||||
// Login defines Docker login parameters.
|
||||
type Login struct {
|
||||
RegistryData
|
||||
Config string
|
||||
Registries []RegistryData
|
||||
RegistriesRaw string
|
||||
}
|
||||
|
||||
type RegistryData struct {
|
||||
Registry string // Docker registry address
|
||||
Username string // Docker registry username
|
||||
Password string // Docker registry password
|
||||
Email string // Docker registry email
|
||||
Config string // Docker Auth Config
|
||||
}
|
||||
|
||||
// Build defines Docker build parameters.
|
||||
@ -63,7 +56,7 @@ type Build struct {
|
||||
CacheFrom []string // Docker build cache-from
|
||||
CacheTo string // Docker build cache-to
|
||||
Compress bool // Docker build compress
|
||||
Repo cli.StringSlice // Docker build repositories
|
||||
Repo string // Docker build repository
|
||||
NoCache bool // Docker build no-cache
|
||||
AddHost cli.StringSlice // Docker build add-host
|
||||
Quiet bool // Docker build quiet
|
||||
@ -83,10 +76,7 @@ type Settings struct {
|
||||
Dryrun bool
|
||||
}
|
||||
|
||||
const (
|
||||
strictFilePerm = 0o600
|
||||
DefaultRegistry = "https://index.docker.io/v1/"
|
||||
)
|
||||
const strictFilePerm = 0o600
|
||||
|
||||
// Validate handles the settings validation of the plugin.
|
||||
func (p *Plugin) Validate() error {
|
||||
@ -118,16 +108,6 @@ func (p *Plugin) Validate() error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(p.settings.Login.RegistriesRaw), &p.settings.Login.Registries); err != nil {
|
||||
return fmt.Errorf("error unmarshal registries: %w", err)
|
||||
}
|
||||
|
||||
for i, registryData := range p.settings.Login.Registries {
|
||||
if registryData.Registry == "" {
|
||||
p.settings.Login.Registries[i].Registry = DefaultRegistry
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -187,16 +167,7 @@ func (p *Plugin) Execute() error {
|
||||
|
||||
// login to the Docker registry
|
||||
if p.settings.Login.Password != "" {
|
||||
cmd := commandLogin(p.settings.Login.RegistryData)
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error authenticating: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, registryData := range p.settings.Login.Registries {
|
||||
cmd := commandLogin(registryData)
|
||||
cmd := commandLogin(p.settings.Login)
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
@ -214,8 +185,6 @@ func (p *Plugin) Execute() error {
|
||||
switch {
|
||||
case p.settings.Login.Password != "":
|
||||
logrus.Info("Detected registry credentials")
|
||||
case len(p.settings.Login.Registries) > 0:
|
||||
logrus.Info("Detected multiple registry credentials")
|
||||
case p.settings.Login.Config != "":
|
||||
logrus.Info("Detected registry credentials file")
|
||||
default:
|
||||
|
@ -1,23 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRegistries(t *testing.T) {
|
||||
p := &Plugin{}
|
||||
p.settings.Login.RegistriesRaw = `[{"username": "docker_user", "password": "docker_password"}]`
|
||||
|
||||
assert.NoError(t, p.Validate())
|
||||
|
||||
fmt.Println(p.settings.Login.Registries[0].Password)
|
||||
|
||||
if assert.Len(t, p.settings.Login.Registries, 1) {
|
||||
assert.EqualValues(t, "docker_user", p.settings.Login.Registries[0].Username)
|
||||
assert.EqualValues(t, "docker_password", p.settings.Login.Registries[0].Password)
|
||||
assert.EqualValues(t, DefaultRegistry, p.settings.Login.Registries[0].Registry)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user