Skip to content

Commit

Permalink
Updated image providers to consider amd64 images.
Browse files Browse the repository at this point in the history
  • Loading branch information
brett19 committed Dec 1, 2023
1 parent 94025a2 commit e2f42ed
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 18 deletions.
14 changes: 5 additions & 9 deletions deployment/dockerdeploy/dockerhubimageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"go.uber.org/zap"
Expand Down Expand Up @@ -34,14 +33,11 @@ func (p *DockerHubImageProvider) GetImage(ctx context.Context, def *ImageDef) (*
}

dhImagePath := fmt.Sprintf("couchbase:%s", serverVersion)
p.Logger.Debug("identified docker image to pull", zap.String("image", dhImagePath))
p.Logger.Debug("identified dockerhub image to pull", zap.String("image", dhImagePath))

err := dockerPullAndPipe(ctx, p.Logger, p.DockerCli, dhImagePath, types.ImagePullOptions{})
if err != nil {
return nil, errors.Wrap(err, "failed to pull from dockerhub registry")
}

return &ImageRef{
return MultiArchImagePuller{
Logger: p.Logger,
DockerCli: p.DockerCli,
ImagePath: dhImagePath,
}, nil
}.Pull(ctx)
}
16 changes: 7 additions & 9 deletions deployment/dockerdeploy/ghcrimageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ func (p *GhcrImageProvider) GetImage(ctx context.Context, def *ImageDef) (*Image
p.Logger.Debug("pulling image from ghcr")

ghcrImagePath := fmt.Sprintf("ghcr.io/cb-vanilla/server:%s", serverVersion)
err := dockerPullAndPipe(ctx, p.Logger, p.DockerCli, ghcrImagePath, types.ImagePullOptions{
RegistryAuth: p.genGhcrAuthStr(),
})
if err != nil {
return nil, errors.Wrap(err, "failed to pull from ghcr registry")
}
p.Logger.Debug("identified ghcr image to pull", zap.String("image", ghcrImagePath))

return &ImageRef{
ImagePath: ghcrImagePath,
}, nil
return MultiArchImagePuller{
Logger: p.Logger,
DockerCli: p.DockerCli,
RegistryAuth: p.genGhcrAuthStr(),
ImagePath: ghcrImagePath,
}.Pull(ctx)
}
80 changes: 80 additions & 0 deletions deployment/dockerdeploy/multiarchimagepuller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package dockerdeploy

import (
"context"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"go.uber.org/zap"
)

type MultiArchImagePuller struct {
Logger *zap.Logger
DockerCli *client.Client
RegistryAuth string
ImagePath string
}

func (p MultiArchImagePuller) Pull(ctx context.Context) (*ImageRef, error) {
images, err := p.DockerCli.ImageList(ctx, types.ImageListOptions{
Filters: filters.NewArgs(filters.Arg("reference", p.ImagePath)),
})
if err != nil {
return nil, errors.Wrap(err, "failed to list images")
}

if len(images) > 0 {
imageId := images[0].ID
p.Logger.Debug("identified image", zap.String("imageId", imageId))
return &ImageRef{ImagePath: imageId}, nil
}

p.Logger.Debug("image is not available locally, attempting to pull")

err = dockerPullAndPipe(ctx, p.Logger, p.DockerCli, p.ImagePath, types.ImagePullOptions{
RegistryAuth: p.RegistryAuth,
})
if err != nil {
return nil, errors.Wrap(err, "failed to pull from dockerhub registry")
}

images, err = p.DockerCli.ImageList(ctx, types.ImageListOptions{
Filters: filters.NewArgs(filters.Arg("reference", p.ImagePath)),
})
if err != nil {
return nil, errors.Wrap(err, "failed to list images after pull")
}

if len(images) > 0 {
imageId := images[0].ID
p.Logger.Debug("identified image", zap.String("imageId", imageId))
return &ImageRef{ImagePath: imageId}, nil
}

p.Logger.Debug("image is still not available locally, attempting to pull amd64 image")

err = dockerPullAndPipe(ctx, p.Logger, p.DockerCli, p.ImagePath, types.ImagePullOptions{
Platform: "linux/amd64",
RegistryAuth: p.RegistryAuth,
})
if err != nil {
return nil, errors.Wrap(err, "failed to pull from dockerhub registry")
}

images, err = p.DockerCli.ImageList(ctx, types.ImageListOptions{
Filters: filters.NewArgs(filters.Arg("reference", p.ImagePath)),
})
if err != nil {
return nil, errors.Wrap(err, "failed to list images after amd64 pull")
}

if len(images) > 0 {
imageId := images[0].ID
p.Logger.Debug("identified image", zap.String("imageId", imageId))
return &ImageRef{ImagePath: imageId}, nil
}

return nil, errors.New("could not find referenced image")
}

0 comments on commit e2f42ed

Please sign in to comment.