-
|
I have this Go code in my project. The issue is that, it doesn't use the cached layers the second time unlike when using the command line where it prints func buildImage(c context.Context) error {
version := config.GetVersion()
targetTag := fmt.Sprintf("lsw-v1:%s", version.ShortCommit)
noCache := false
remove := false
layers := true
dockerfilePath, err := getDockerfile()
if err != nil {
return err
}
contextDir := filepath.Dir(dockerfilePath)
dockerfileName := filepath.Base(dockerfilePath)
buildOptions := types.BuildOptions{
ContainerFiles: []string{dockerfileName},
BuildOptions: buildahDefine.BuildOptions{
NoCache: noCache,
RemoveIntermediateCtrs: remove,
Output: targetTag,
ContextDirectory: contextDir,
Layers: layers,
},
}
// Notice we pass []string{dockerfileName} instead of dockerfilePath
_, err = images.Build(c, []string{dockerfileName}, buildOptions)
if err != nil {
return err
}
return nil
} |
Beta Was this translation helpful? Give feedback.
Answered by
A2va
Mar 15, 2026
Replies: 1 comment
-
|
It was resolved when setting buildOptions := types.BuildOptions{
ContainerFiles: []string{dockerfileName},
BuildOptions: buildahDefine.BuildOptions{
NoCache: noCache,
RemoveIntermediateCtrs: remove,
Output: targetTag,
ContextDirectory: contextDir,
Layers: layers,
+ OutputFormat: buildahDefine.OCIv1ImageManifest, // or buildahDefine.Dockerv2ImageManifest
},
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
A2va
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It was resolved when setting
OutputFormatin the build optionbuildOptions := types.BuildOptions{ ContainerFiles: []string{dockerfileName}, BuildOptions: buildahDefine.BuildOptions{ NoCache: noCache, RemoveIntermediateCtrs: remove, Output: targetTag, ContextDirectory: contextDir, Layers: layers, + OutputFormat: buildahDefine.OCIv1ImageManifest, // or buildahDefine.Dockerv2ImageManifest }, }