Skip to content

Commit

Permalink
fix(cleanup): issue with incorrect exclusion of ancestors for retaine…
Browse files Browse the repository at this point in the history
…d images (#5956)

Issue occurred when using images built with werf using the buildah backend as base images in a project using werf with the Docker backend.

Fixed getting image parent ID logic.

Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
  • Loading branch information
alexey-igrychev committed Feb 1, 2024
1 parent 26123b6 commit 00ee0e1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/buildah/native_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (b *NativeBuildah) Commit(ctx context.Context, container string, opts Commi
}
}

builder.SetLabel("werf.io/base-image-id", fmt.Sprintf("sha256:%s", builder.FromImageID))
builder.SetLabel(image.WerfBaseImageIDLabel, fmt.Sprintf("sha256:%s", builder.FromImageID))

sysCtx, err := b.getSystemContext(opts.TargetPlatform)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/container_backend/buildah_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,11 @@ func (backend *BuildahBackend) GetImageInfo(ctx context.Context, ref string, opt
return nil, nil
}

var parentID string
if id, ok := inspect.Docker.Config.Labels["werf.io/base-image-id"]; ok {
parentID = id
} else {
parentID = string(inspect.Docker.Parent)
parentID := string(inspect.Docker.Parent)
if parentID == "" {
if id, ok := inspect.Docker.Config.Labels[image.WerfBaseImageIDLabel]; ok { // built with werf and buildah backend
parentID = id
}
}

var repository, tag, repoDigest string
Expand Down
11 changes: 5 additions & 6 deletions pkg/docker/image_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ func NewInfoFromInspect(ref string, inspect *types.ImageInspect) *image.Info {
repoDigest = image.ExtractRepoDigest(inspect.RepoDigests, repository)
}

var parentID string
if id, ok := inspect.Config.Labels["werf.io/base-image-id"]; ok {
parentID = id
} else {
// TODO(1.3): Legacy compatibility mode
parentID = inspect.Config.Image
parentID := inspect.Config.Image
if parentID == "" {
if id, ok := inspect.Config.Labels[image.WerfBaseImageIDLabel]; ok { // built with werf and buildah backend
parentID = id
}
}

return &image.Info{
Expand Down
11 changes: 5 additions & 6 deletions pkg/docker_registry/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,11 @@ func (api *api) getRepoImageByDesc(ctx context.Context, originalTag string, desc
}
repoImage.Size = totalSize

var parentID string
if baseImageID, ok := configFile.Config.Labels["werf.io/base-image-id"]; ok {
parentID = baseImageID
} else {
// TODO(1.3): Legacy compatibility mode
parentID = configFile.Config.Image
parentID := configFile.Config.Image
if parentID == "" {
if id, ok := configFile.Config.Labels[image.WerfBaseImageIDLabel]; ok { // built with werf and buildah backend
parentID = id
}
}
repoImage.ParentID = parentID
}
Expand Down
1 change: 1 addition & 0 deletions pkg/image/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
WerfStageContentDigestLabel = "werf-stage-content-digest"
WerfProjectRepoCommitLabel = "werf-project-repo-commit"
WerfImportChecksumLabelPrefix = "werf-import-checksum-"
WerfBaseImageIDLabel = "werf.io/base-image-id"

WerfImportMetadataChecksumLabel = "checksum"
WerfImportMetadataSourceImageIDLabel = "source-image-id"
Expand Down

0 comments on commit 00ee0e1

Please sign in to comment.