Skip to content

Commit

Permalink
fix(stapel-to-buildah): fix cleanup parent-id issue for images built …
Browse files Browse the repository at this point in the history
…with buildah

Save base image id into dedicated label `werf.io/base-image-id`.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed May 16, 2022
1 parent aacf4b1 commit 56e90e2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions pkg/buildah/native_linux.go
Expand Up @@ -327,6 +327,8 @@ func (b *NativeBuildah) Commit(ctx context.Context, container string, opts Commi
}
}

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

imgID, _, _, err := builder.Commit(ctx, imageRef, buildah.CommitOptions{
PreferredManifestType: buildah.Dockerv2ImageManifest,
SignaturePolicyPath: b.SignaturePolicyPath,
Expand Down
17 changes: 12 additions & 5 deletions pkg/container_backend/buildah_backend.go
Expand Up @@ -491,17 +491,24 @@ func (runtime *BuildahBackend) GetImageInfo(ctx context.Context, ref string, opt

repository, tag := image.ParseRepositoryAndTag(ref)

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

return &image.Info{
Name: ref,
Repository: repository,
Tag: tag,
Labels: inspect.Docker.Config.Labels,
CreatedAtUnixNano: inspect.Docker.Created.UnixNano(),
// RepoDigest: repoDigest, // FIXME
OnBuild: inspect.Docker.Config.OnBuild,
ID: inspect.Docker.ID,
ParentID: inspect.Docker.Config.Image,
Size: inspect.Docker.Size,
RepoDigest: inspect.FromImageDigest,
OnBuild: inspect.Docker.Config.OnBuild,
ID: inspect.FromImageID,
ParentID: parentID,
Size: inspect.Docker.Size,
}, nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/docker_registry/api.go
Expand Up @@ -143,13 +143,21 @@ func (api *api) GetRepoImage(_ context.Context, reference string) (*image.Info,
return nil, fmt.Errorf("unable to parse reference %q: %w", reference, err)
}

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
}

repoImage := &image.Info{
Name: reference,
Repository: strings.Join([]string{referenceParts.registry, referenceParts.repository}, "/"),
ID: manifest.Config.Digest.String(),
Tag: referenceParts.tag,
RepoDigest: digest.String(),
ParentID: configFile.Config.Image,
ParentID: parentID,
Labels: configFile.Config.Labels,
Size: totalSize,
}
Expand Down
10 changes: 9 additions & 1 deletion pkg/image/info.go
Expand Up @@ -45,6 +45,14 @@ func NewInfoFromInspect(ref string, inspect *types.ImageInspect) *Info {
repoDigest = inspect.RepoDigests[0]
}

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
}

return &Info{
Name: ref,
Repository: repository,
Expand All @@ -54,7 +62,7 @@ func NewInfoFromInspect(ref string, inspect *types.ImageInspect) *Info {
CreatedAtUnixNano: MustParseTimestampString(inspect.Created).UnixNano(),
RepoDigest: repoDigest,
ID: inspect.ID,
ParentID: inspect.Config.Image,
ParentID: parentID,
Size: inspect.Size,
}
}
Expand Down

0 comments on commit 56e90e2

Please sign in to comment.