libcompose icon indicating copy to clipboard operation
libcompose copied to clipboard

Documentation for AuthConfigs/RegistryConfigs

Open ekristen opened this issue 9 years ago • 10 comments

Is there documentation on on how to pass in Auth/RegistryConfig information for libcompose to pull from private repository locations?

ekristen avatar Apr 01 '16 05:04 ekristen

This would be handy for me as well.

technolo-g avatar Jan 24 '17 00:01 technolo-g

This says it was in a closed milestone but I'm not sure where the documentation is and the issue is still open. :(

vito-c avatar Feb 22 '17 23:02 vito-c

To give you an idea of how troublesome this has been.

package command

import (
	"context"
	"fmt"

	"github.com/urfave/cli"

	"github.com/docker/libcompose/docker/auth"
	"github.com/docker/libcompose/docker"
	"github.com/docker/libcompose/docker/ctx"
	"github.com/docker/libcompose/project"
	"github.com/docker/libcompose/project/options"
)

// UpCmd the command responsible for starting services
func UpCmd(c *cli.Context) {

	dctx := &ctx.Context{
		Context: project.Context{
			ComposeFiles: []string{"docker-compose.yml"},
			ProjectName:  "test",
		},
	}
	dctx.AuthLookup = auth.NewConfigLookup(dctx.ConfigFile)

	project, err := docker.NewProject(
		dctx,
	nil)

	dump, err := project.Config()
	fmt.Println(dump)
	fmt.Println("HAS AUTH: ", dctx.ConfigFile.ContainsAuth())
	fmt.Println("DUMP AUTH: ", dctx.ConfigFile.AuthConfigs)

	if err != nil {
		panic(err)
	}

	err = project.Up(context.Background(), options.Up{})

	if err != nil {
		panic(err)
	}
}
HAS AUTH:  true
DUMP AUTH:  map[myreg.com:{me **supersecret**   myreg.com  }]
INFO[0000] [0/6] [some.service]: Starting
Pulling some.service (myreg.com/some/service:latest)...
ERRO[0001] Failed to pull image myreg.com/some/service:latest: Error response from daemon: Get https://myreg.com/v2/some/service/manifests/latest: unknown: Authentication is required

goroutine 1 [running]:
github.com/AudaxHealthInc/maestro/command.UpCmd(0xc4203e12c0)
	/Users/vitocutten/code/go/src/github.com/AudaxHealthInc/maestro/command/up.go:60 +0x2e3
github.com/urfave/cli.HandleAction(0x14b6540, 0x15a4cb8, 0xc4203e12c0, 0xc42031b800, 0x0)
	/Users/vitocutten/code/go/src/github.com/urfave/cli/app.go:487 +0x7c
github.com/urfave/cli.Command.Run(0x1582e7f, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1598bd6, 0x32, 0x0, ...)
	/Users/vitocutten/code/go/src/github.com/urfave/cli/command.go:207 +0xb72
github.com/urfave/cli.(*App).Run(0xc4200b4820, 0xc42000c380, 0x2, 0x2, 0x0, 0x0)
	/Users/vitocutten/code/go/src/github.com/urfave/cli/app.go:250 +0x7d0
main.main()
	/Users/vitocutten/code/go/src/github.com/AudaxHealthInc/maestro/maestro.go:23 +0x1ac

vito-c avatar Feb 23 '17 00:02 vito-c

In case anyone else runs into this issue here is the way I solved it.

package command

import (
	"context"

	"github.com/urfave/cli"

	"github.com/docker/libcompose/docker"
	"github.com/docker/libcompose/docker/auth"
	"github.com/docker/libcompose/docker/ctx"
	"github.com/docker/libcompose/project"
)

// PullCmd the command responsible for pulling services
func PullCmd(c *cli.Context) {

	dctx := &ctx.Context{
		Context: project.Context{
			ComposeFiles: []string{"docker-compose.yml"},
			ProjectName:  "maestro",
		},
	}
	dctx.LookupConfig()
	dctx.AuthLookup = auth.NewConfigLookup(dctx.ConfigFile)
	project, err := docker.NewProject(
		dctx,
		nil)

	if err != nil {
		panic(err)
	}

	err = project.Pull(context.Background())

	if err != nil {
		panic(err)
	}
}

vito-c avatar Feb 23 '17 17:02 vito-c

Thanks @vito-c!

technolo-g avatar Feb 23 '17 17:02 technolo-g

@vito-c, would you like me to PR this into the docs?

technolo-g avatar Feb 28 '17 00:02 technolo-g

@vdemeester would you like me to put this in the example dir?

vito-c avatar Feb 28 '17 04:02 vito-c

@vito-c definitely 👼 🙏 😸

vdemeester avatar Feb 28 '17 07:02 vdemeester

@vdemeester I've been trying to test this with the new docker that cam out and have been failing pretty hard when the ~/.docker/config.json file is of the format:

{
	"auths": {
		"foobar.com": {},
		"something.org": {}
	},
	"credsStore": "osxkeychain"
}

It works fine when the format is:

{
	"auths": {
		"foobar.com": {"auth":"*****"},
		"something.org": {"auth":"*****"}
	}
}

vito-c avatar Mar 18 '17 14:03 vito-c

As far as I can tell the current vendor version of docker you are using for libcompose doesn't support credentials via osxkeychain because it doesn't have /Users/vitocutten/code/go/src/github.com/docker/docker/cli/config/credentials/default_store_darwin.go

vito-c avatar Mar 19 '17 05:03 vito-c