Skip to content

Commit

Permalink
fix(linux): DOCKER_CONFIG path (#1102)
Browse files Browse the repository at this point in the history
* fix(linux): DOCKER_CONFIG path

Signed-off-by: Justin Alvarez <[email protected]>

* rename DockerConfigPath to DockerConfigDir and update comment

Signed-off-by: Justin Alvarez <[email protected]>

---------

Signed-off-by: Justin Alvarez <[email protected]>
  • Loading branch information
pendo324 authored Sep 23, 2024
1 parent bdeb3c7 commit 5b45b75
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/finch/main_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var newApp = func(
logger,
fp.NerdctlConfigFilePath(),
fp.BuildkitSocketPath(),
fp.DockerConfigDir(),
fp.FinchDependencyBinDir(),
system.NewStdLib(),
)
Expand Down
5 changes: 5 additions & 0 deletions pkg/command/nerdctl_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
EnvKeyNerdctlTOML = "NERDCTL_TOML"
EnvKeyBuildkitHost = "BUILDKIT_HOST"
EnvKeyDockerConfig = "DOCKER_CONFIG"
)

type nerdctlCmdCreator struct {
Expand All @@ -28,6 +29,7 @@ type nerdctlCmdCreator struct {
systemDeps NerdctlCmdCreatorSystemDeps
nerdctlConfigPath string
buildkitSocketPath string
dockerConfigPath string
binPath string
}

Expand All @@ -39,6 +41,7 @@ func NewNerdctlCmdCreator(
logger flog.Logger,
nerdctlConfigPath string,
buildkitSocketPath string,
dockerConfigPath string,
binPath string,
systemDeps NerdctlCmdCreatorSystemDeps,
) NerdctlCmdCreator {
Expand All @@ -47,6 +50,7 @@ func NewNerdctlCmdCreator(
logger: logger,
nerdctlConfigPath: nerdctlConfigPath,
buildkitSocketPath: buildkitSocketPath,
dockerConfigPath: dockerConfigPath,
binPath: binPath,
systemDeps: systemDeps,
}
Expand All @@ -65,6 +69,7 @@ func (ncc *nerdctlCmdCreator) create(stdin io.Reader, stdout, stderr io.Writer,
newPathEnv = append(
newPathEnv,
fmt.Sprintf("%s=%s", EnvKeyNerdctlTOML, ncc.nerdctlConfigPath),
fmt.Sprintf("%s=%s", EnvKeyDockerConfig, ncc.dockerConfigPath),
fmt.Sprintf("%s=unix://%s", EnvKeyBuildkitHost, ncc.buildkitSocketPath),
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/command/nerdctl_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
const (
mockNerdctlConfigPath = "/etc/finch/nerdctl.toml"
mockBuildkitSocketPath = "/etc/finch/buildkit"
mockDockerConfigPath = "/etc/finch/docker"
mockFinchBinPath = "/usr/lib/usrexec/finch"
mockSystemPath = "/usr/bin"
finalPath = mockFinchBinPath + command.EnvKeyPathJoiner + mockSystemPath
Expand Down Expand Up @@ -47,6 +48,7 @@ func TestLimaCmdCreator_Create(t *testing.T) {
cmd.EXPECT().SetEnv([]string{
fmt.Sprintf("%s=%s", command.EnvKeyPath, finalPath),
fmt.Sprintf("%s=%s", command.EnvKeyNerdctlTOML, mockNerdctlConfigPath),
fmt.Sprintf("%s=%s", command.EnvKeyDockerConfig, mockDockerConfigPath),
fmt.Sprintf("%s=unix://%s", command.EnvKeyBuildkitHost, mockBuildkitSocketPath),
})
cmd.EXPECT().SetStdin(nil)
Expand All @@ -72,6 +74,7 @@ func TestLimaCmdCreator_Create(t *testing.T) {
logger,
mockNerdctlConfigPath,
mockBuildkitSocketPath,
mockDockerConfigPath,
mockFinchBinPath,
lcd,
).Create(mockArgs...)
Expand Down
6 changes: 6 additions & 0 deletions pkg/path/finch_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func (fp Finch) BuildkitSocketPath() string {
return filepath.Join(fp.FinchRuntimeDataDir(), "buildkit", "buildkitd.sock")
}

// DockerConfigDir returns the path to the docker config file.
// nerdctl uses ${DOCKER_CONFIG}/config.json for authentication with image registries.
func (fp Finch) DockerConfigDir() string {
return filepath.Join(string(fp), "docker")
}

// FinchDependencyBinDir returns the path to Finch's local helper or dependency binaries.
// Currently used for vended version of BuildKit.
func (Finch) FinchDependencyBinDir() string {
Expand Down

0 comments on commit 5b45b75

Please sign in to comment.