Skip to content

Commit b6943fd

Browse files
committed
- Add a logic to read config file for Podman in `render` command to pull images from private registry. Signed-off-by: Chuan-Yen Chiang <[email protected]>
1 parent df56b2b commit b6943fd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cmd/crank/render/runtime_docker.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"net"
2424
"os"
25+
"path/filepath"
2526

2627
"github.com/distribution/reference"
2728
"github.com/docker/cli/cli/config"
@@ -162,8 +163,24 @@ func GetRuntimeDocker(fn pkgv1.Function, log logging.Logger) (*RuntimeDocker, er
162163
return nil, errors.Wrapf(err, "cannot get pull policy for Function %q", fn.GetName())
163164
}
164165

165-
// Initial ConfigFile
166-
configFile := config.LoadDefaultConfigFile(os.Stderr)
166+
// Initial ConfigFile, first check environment variable XDG_RUNTIME_DIR for Podman if it exists
167+
// Otherwise, use the default Docker config file
168+
var configFile *configfile.ConfigFile
169+
if _, err := os.Stat(filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "containers/auth.json")); err == nil {
170+
// Use the auth.json file if specified XDG_RUNTIME_DIR and file exists
171+
f, err := os.Open(filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "containers/auth.json"))
172+
if err != nil {
173+
return nil, errors.Wrapf(err, "cannot open file %s", filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "containers/auth.json"))
174+
}
175+
defer f.Close() //nolint:errcheck // Only open for reading.
176+
177+
configFile, err = config.LoadFromReader(f)
178+
if err != nil {
179+
return nil, errors.Wrapf(err, "cannot load config file from reader")
180+
}
181+
} else {
182+
configFile = config.LoadDefaultConfigFile(os.Stderr)
183+
}
167184

168185
r := &RuntimeDocker{
169186
Image: fn.Spec.Package,

0 commit comments

Comments
 (0)