mirror of
https://github.com/containers/podman.git
synced 2026-02-05 15:45:08 +01:00
Replace podman pause image with rootfs.
This commit removes the code to build a local pause image from the Containerfile. It is replaced with code to find the catatonit binary and include it in the Rootfs. This removes the need to build a local pause container image. The same logic is also applied to createServiceContainer which is originally also based on the pause image. Fixes: #23292 Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
@@ -301,9 +301,13 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
||||
|
||||
// TODO: We don't understand why specgen does not take of this, but
|
||||
// integration tests clearly pointed out that it was required.
|
||||
imageData, err := opts.Image.Inspect(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var imageData *libimage.ImageData
|
||||
if opts.Image != nil {
|
||||
var err error
|
||||
imageData, err = opts.Image.Inspect(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
s.WorkDir = "/"
|
||||
// Entrypoint/Command handling is based off of
|
||||
|
||||
@@ -4,18 +4,15 @@ package generate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
buildahDefine "github.com/containers/buildah/define"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v5/libpod"
|
||||
"github.com/containers/podman/v5/libpod/define"
|
||||
)
|
||||
|
||||
// PullOrBuildInfraImage pulls down the specified image or the one set in
|
||||
// containers.conf. If none is set, it builds a local pause image.
|
||||
func PullOrBuildInfraImage(rt *libpod.Runtime, imageName string) (string, error) {
|
||||
// PullInfraImage pulls down the specified image or the one set in
|
||||
// containers.conf. If none is set, it returns an empty string. In this
|
||||
// case, the rootfs-based pause image is used by libpod.
|
||||
func PullInfraImage(rt *libpod.Runtime, imageName string) (string, error) {
|
||||
rtConfig, err := rt.GetConfigNoCopy()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -33,64 +30,5 @@ func PullOrBuildInfraImage(rt *libpod.Runtime, imageName string) (string, error)
|
||||
return imageName, nil
|
||||
}
|
||||
|
||||
name, err := buildPauseImage(rt, rtConfig)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("building local pause image: %w", err)
|
||||
}
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func buildPauseImage(rt *libpod.Runtime, rtConfig *config.Config) (string, error) {
|
||||
version, err := define.GetVersion()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
imageName := fmt.Sprintf("localhost/podman-pause:%s-%d", version.Version, version.Built)
|
||||
|
||||
// First check if the image has already been built.
|
||||
if _, _, err := rt.LibimageRuntime().LookupImage(imageName, nil); err == nil {
|
||||
return imageName, nil
|
||||
}
|
||||
|
||||
// Also look into the path as some distributions install catatonit in
|
||||
// /usr/bin.
|
||||
catatonitPath, err := rtConfig.FindInitBinary()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("finding pause binary: %w", err)
|
||||
}
|
||||
|
||||
buildContent := fmt.Sprintf(`FROM scratch
|
||||
COPY %s /catatonit
|
||||
ENTRYPOINT ["/catatonit", "-P"]`, catatonitPath)
|
||||
|
||||
tmpF, err := os.CreateTemp("", "pause.containerfile")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err := tmpF.WriteString(buildContent); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := tmpF.Close(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer os.Remove(tmpF.Name())
|
||||
|
||||
buildOptions := buildahDefine.BuildOptions{
|
||||
CommonBuildOpts: &buildahDefine.CommonBuildOptions{},
|
||||
Output: imageName,
|
||||
Quiet: true,
|
||||
IgnoreFile: "/dev/null", // makes sure to not read a local .ignorefile (see #13529)
|
||||
IIDFile: "/dev/null", // prevents Buildah from writing the ID on stdout
|
||||
IDMappingOptions: &buildahDefine.IDMappingOptions{
|
||||
// Use the host UID/GID mappings for the build to avoid issues when
|
||||
// running with a custom mapping (BZ #2083997).
|
||||
HostUIDMapping: true,
|
||||
HostGIDMapping: true,
|
||||
},
|
||||
}
|
||||
if _, _, err := rt.Build(context.Background(), buildOptions, tmpF.Name()); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return imageName, nil
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -38,12 +38,14 @@ func MakePod(p *entities.PodSpec, rt *libpod.Runtime) (_ *libpod.Pod, finalErr e
|
||||
}
|
||||
|
||||
if !p.PodSpecGen.NoInfra {
|
||||
imageName, err := PullOrBuildInfraImage(rt, p.PodSpecGen.InfraImage)
|
||||
imageName, err := PullInfraImage(rt, p.PodSpecGen.InfraImage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p.PodSpecGen.InfraImage = imageName
|
||||
p.PodSpecGen.InfraContainerSpec.RawImageName = imageName
|
||||
if len(imageName) > 0 {
|
||||
p.PodSpecGen.InfraImage = imageName
|
||||
p.PodSpecGen.InfraContainerSpec.RawImageName = imageName
|
||||
}
|
||||
}
|
||||
|
||||
spec, err := MapSpec(&p.PodSpecGen)
|
||||
|
||||
Reference in New Issue
Block a user