Skip to content

Commit 67c4103

Browse files
SDKQE-3648: Enable pulling Enterprise Analytics images from ghcr (#124)
1 parent 02423cb commit 67c4103

1 file changed

Lines changed: 40 additions & 20 deletions

File tree

deployment/dockerdeploy/ghcrimageprovider.go

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,25 @@ func (p *GhcrImageProvider) GetImage(ctx context.Context, def *ImageDef) (*Image
7474
return nil, errors.New("cannot pull community edition of columnar")
7575
}
7676

77-
ghcrImagePath := fmt.Sprintf("ghcr.io/cb-vanilla/columnar:%s", serverVersion)
78-
image, err := MultiArchImagePuller{
79-
Logger: p.Logger,
80-
DockerCli: p.DockerCli,
81-
RegistryAuth: p.genGhcrAuthStr(),
82-
ImagePath: ghcrImagePath,
83-
}.Pull(ctx)
84-
if err != nil {
85-
p.Logger.Debug("ghcr provider failed to provide image from columnar repo", zap.Error(err))
77+
var imagePaths []string
78+
if len(serverVersion) > 0 && (serverVersion[0] == '0' || serverVersion[0] == '1') {
79+
// For versions starting with 0 or 1, try the legacy columnar paths
80+
imagePaths = []string{
81+
fmt.Sprintf("ghcr.io/cb-vanilla/columnar:%s", serverVersion),
82+
fmt.Sprintf("ghcr.io/cb-vanilla/couchbase-columnar:%s", serverVersion),
83+
}
8684

87-
ghcrImagePath := fmt.Sprintf("ghcr.io/cb-vanilla/couchbase-columnar:%s", serverVersion)
88-
image, err := MultiArchImagePuller{
85+
return p.tryImagePaths(ctx, imagePaths)
86+
} else {
87+
// For newer versions, use enterprise-analytics
88+
ghcrImagePath := fmt.Sprintf("ghcr.io/cb-vanilla/enterprise-analytics:%s", serverVersion)
89+
return MultiArchImagePuller{
8990
Logger: p.Logger,
9091
DockerCli: p.DockerCli,
9192
RegistryAuth: p.genGhcrAuthStr(),
9293
ImagePath: ghcrImagePath,
9394
}.Pull(ctx)
94-
if err != nil {
95-
p.Logger.Debug("ghcr provider failed to provide image from couchbase-columnar repo", zap.Error(err))
96-
97-
return nil, errors.New("failed to pull image from both columnar and couchbase-columnar repos")
98-
}
99-
100-
return image, nil
10195
}
102-
103-
return image, nil
10496
}
10597
}
10698

@@ -197,3 +189,31 @@ func (p *GhcrImageProvider) SearchImages(ctx context.Context, version string) ([
197189

198190
return images, nil
199191
}
192+
193+
// tryImagePaths attempts to pull from multiple image paths in sequence
194+
// Returns the first successful image or an error if all attempts fail
195+
func (p *GhcrImageProvider) tryImagePaths(ctx context.Context, imagePaths []string) (*ImageRef, error) {
196+
var lastErr error
197+
198+
for i, imagePath := range imagePaths {
199+
p.Logger.Debug("attempting to pull image", zap.String("imagePath", imagePath), zap.Int("attempt", i+1))
200+
201+
image, err := MultiArchImagePuller{
202+
Logger: p.Logger,
203+
DockerCli: p.DockerCli,
204+
RegistryAuth: p.genGhcrAuthStr(),
205+
ImagePath: imagePath,
206+
}.Pull(ctx)
207+
208+
if err != nil {
209+
p.Logger.Debug("failed to pull image", zap.String("imagePath", imagePath), zap.Error(err))
210+
lastErr = err
211+
continue
212+
}
213+
214+
p.Logger.Debug("successfully pulled image", zap.String("imagePath", imagePath))
215+
return image, nil
216+
}
217+
218+
return nil, fmt.Errorf("failed to pull image from all %d paths, last error: %w", len(imagePaths), lastErr)
219+
}

0 commit comments

Comments
 (0)