forked from toolshed/abra
feat: Retrieves auth token from image
This allows using a private registry for an image. To use it, you have to run docker login on your local machine before running abra deploy.
This commit is contained in:
@ -17,6 +17,7 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/log"
|
"coopcloud.tech/abra/pkg/log"
|
||||||
"coopcloud.tech/abra/pkg/ui"
|
"coopcloud.tech/abra/pkg/ui"
|
||||||
"coopcloud.tech/abra/pkg/upstream/convert"
|
"coopcloud.tech/abra/pkg/upstream/convert"
|
||||||
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/command/stack/formatter"
|
"github.com/docker/cli/cli/command/stack/formatter"
|
||||||
composetypes "github.com/docker/cli/cli/compose/types"
|
composetypes "github.com/docker/cli/cli/compose/types"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
@ -426,7 +427,8 @@ func deployServices(
|
|||||||
services map[string]swarm.ServiceSpec,
|
services map[string]swarm.ServiceSpec,
|
||||||
namespace convert.Namespace,
|
namespace convert.Namespace,
|
||||||
sendAuth bool,
|
sendAuth bool,
|
||||||
resolveImage string) ([]ui.ServiceMeta, error) {
|
resolveImage string,
|
||||||
|
) ([]ui.ServiceMeta, error) {
|
||||||
var servicesMeta []ui.ServiceMeta
|
var servicesMeta []ui.ServiceMeta
|
||||||
|
|
||||||
existingServices, err := GetStackServices(ctx, cl, namespace.Name())
|
existingServices, err := GetStackServices(ctx, cl, namespace.Name())
|
||||||
@ -446,6 +448,21 @@ func deployServices(
|
|||||||
encodedAuth string
|
encodedAuth string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// When sendAuth is set, use the docker cli to retrieve the auth token
|
||||||
|
// for the image we are deploying.
|
||||||
|
// This enables using a private registry by running docker login on the
|
||||||
|
// machine, that abra is executed.
|
||||||
|
if sendAuth {
|
||||||
|
dockerCLI, err := command.NewDockerCli()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("retrieving docker auth token: failed create docker cli: %s", err)
|
||||||
|
}
|
||||||
|
encodedAuth, err = command.RetrieveAuthTokenFromImage(dockerCLI.ConfigFile(), image)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("failed to retrieve registry auth for image %s: %s", image, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if service, exists := existingServiceMap[name]; exists {
|
if service, exists := existingServiceMap[name]; exists {
|
||||||
log.Debugf("updating %s", name)
|
log.Debugf("updating %s", name)
|
||||||
|
|
||||||
@ -587,7 +604,7 @@ func WaitOnServices(ctx context.Context, cl *dockerClient.Client, opts WaitOpts)
|
|||||||
fmt.Sprintf("%s_%s", opts.AppName, timestamp()),
|
fmt.Sprintf("%s_%s", opts.AppName, timestamp()),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Join(config.LOGS_DIR, opts.ServerName), 0764); err != nil {
|
if err := os.MkdirAll(filepath.Join(config.LOGS_DIR, opts.ServerName), 0o764); err != nil {
|
||||||
return fmt.Errorf("waitOnServices: error creating log dir: %s", err)
|
return fmt.Errorf("waitOnServices: error creating log dir: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user