Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use podman for building custom images if executable is found #1101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

REGISTRY_URL={{ .RegistryURL }}
REGISTRY_NAMESPACE={{ .RegistryNamespace }}
CONTAINER_RUNTIME=docker
CONTAINER_RUNTIME={{ .ContainerRuntime }}
if [ "$#" -gt 1 ]; then
REGISTRY_URL=$1
REGISTRY_NAMESPACE=$2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ "$(basename "$PWD")" != 'scripts' ]] ; then
echo 'please run this script from the "scripts" directory'
exit 1
fi
CONTAINER_RUNTIME=docker
CONTAINER_RUNTIME={{ .ContainerRuntime }}
if [ "$#" -eq 1 ]; then
CONTAINER_RUNTIME=$1
fi
Expand Down
10 changes: 10 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"math/rand"
"net/url"
"os"
"os/exec"
"path/filepath"
"reflect"
"regexp"
Expand Down Expand Up @@ -1565,3 +1566,12 @@ func IsHTTPURL(str string) bool {

return regex.MatchString(str)
}

// GetDefaultContainerRuntime returns the preferred container runtime of the host
func GetDefaultContainerRuntime() string {
_, err := exec.LookPath("podman")
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we log a message at level info here that "Podman executable found in the directories named by the PATH environment variable. Using Podman as the container runtime.

return "podman"
}
return "docker"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also log a message at level info here that "Couldn't find Podman executable in the directories named by the PATH environment variable. Using Docker as the container runtime.

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type DockerfileImagePushScriptConfig struct {

// ImagePushTemplateConfig represents template config used by ImagePush script
type ImagePushTemplateConfig struct {
ContainerRuntime string
RegistryURL string
RegistryNamespace string
Images []string
Expand Down Expand Up @@ -79,7 +80,9 @@ func (t *ContainerImagesPushScript) DirectoryDetect(dir string) (services map[st
// Transform transforms the artifacts
func (t *ContainerImagesPushScript) Transform(newArtifacts []transformertypes.Artifact, alreadySeenArtifacts []transformertypes.Artifact) ([]transformertypes.PathMapping, []transformertypes.Artifact, error) {
pathMappings := []transformertypes.PathMapping{}
ipt := ImagePushTemplateConfig{}
ipt := ImagePushTemplateConfig{
ContainerRuntime: common.GetDefaultContainerRuntime(),
}
for _, a := range newArtifacts {
if a.Type != artifacts.NewImagesArtifactType {
continue
Expand Down
2 changes: 2 additions & 0 deletions transformer/dockerfile/dockerfilebuildscripttransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type DockerfileImageBuildScriptConfig struct {

// DockerfileImageBuildScriptTemplateConfig represents the data used to fill the build script generator template
type DockerfileImageBuildScriptTemplateConfig struct {
ContainerRuntime string
RelParentOfSourceDir string
DockerfilesConfig []DockerfileImageBuildConfig
RegistryURL string
Expand Down Expand Up @@ -177,6 +178,7 @@ func (t *DockerfileImageBuildScript) Transform(newArtifacts []transformertypes.A
RegistryURL: commonqa.ImageRegistry(),
RegistryNamespace: commonqa.ImageRegistryNamespace(),
DockerfilesConfig: dockerfilesImageBuildConfig,
ContainerRuntime: common.GetDefaultContainerRuntime(),
}
pathMappings = append(pathMappings, transformertypes.PathMapping{
Type: transformertypes.TemplatePathMappingType,
Expand Down
Loading