Skip to content

Conversation

mmonaco
Copy link
Contributor

@mmonaco mmonaco commented Jul 20, 2024

Make it easier to pull creds from a docker config.json outside of the standard location, without needing environmental variables. For example, a mounted K8s Secret of type kubernetes.io/dockerconfigjson.

Describe the change

new feature

This is a small nice-to-have, exposing existing functionality to regclient library users.

How to verify it

Connect to a registry using creds in a non-standard config file.

Changelog text

  • Add a WithDockerCredsFile() regclient.Opt

Please verify and check that the pull request fulfills the following requirements

  • Tests have been added or not applicable
  • N/A - regclient doesn't have much coverage for opts, config.Docker tests reads
  • Documentation has been added, updated, or not applicable
  • will be picked up in godoc
  • Changes have been rebased to main
  • Multiple commits to the same code have been squashed

Make it easier to pull creds from a docker config.json outside of the
standard location, without needing environmental variables. For example,
a mounted K8s Secret of type `kubernetes.io/dockerconfigjson`.

Signed-off-by: Matthew Monaco <matt@monaco.cx>
Copy link
Contributor

@sudo-bmitch sudo-bmitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@sudo-bmitch sudo-bmitch merged commit d888dff into regclient:main Jul 20, 2024
5 checks passed
@lia39
Copy link

lia39 commented Jul 24, 2024

how do I implement this within a deployment?
until now I mounted the secret to the config.json path manually

@mmonaco
Copy link
Contributor Author

mmonaco commented Jul 24, 2024

how do I implement this within a deployment? until now I mounted the secret to the config.json path manually

This is what I am doing (I almost always wind up wrapping clients with a local one).

type Client struct {
        rc   *regclient.RegClient
        ...
}

// NewClient builds a new Client.
func NewClient(conffile) *Client {
        opt := func() regclient.Opt {
                if conffile != "" {
                        return regclient.WithDockerCredsFile(conffile)
                }
                return regclient.WithDockerCreds()
        }()
        return &Client{
                rc: regclient.New(opt),
                ...
        }
}

and conffile is being set from a flag. So in my Deployment config (I use jsonnet, but yaml, json, etc work too), I add a volume+volumemount mount to /run/.../<mysecretname> and add a container arg for --conf-file=/run/.../<mysecretname>/.dockerconfigjson. When I'm running locally, the --conf-file default is empty, so it uses my local docker config as normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants