feat: Retrieves auth token from image
All checks were successful
continuous-integration/drone/push Build is passing

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:
2025-08-11 11:06:25 +02:00
committed by decentral1se
parent 3fae036db2
commit 157d131b37

View File

@ -17,6 +17,7 @@ import (
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/ui"
"coopcloud.tech/abra/pkg/upstream/convert"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/stack/formatter"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/docker/api/types"
@ -426,7 +427,8 @@ func deployServices(
services map[string]swarm.ServiceSpec,
namespace convert.Namespace,
sendAuth bool,
resolveImage string) ([]ui.ServiceMeta, error) {
resolveImage string,
) ([]ui.ServiceMeta, error) {
var servicesMeta []ui.ServiceMeta
existingServices, err := GetStackServices(ctx, cl, namespace.Name())
@ -446,6 +448,21 @@ func deployServices(
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 {
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()),
)
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)
}