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: allow user configurable docker compose version env variable #1133

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
15 changes: 15 additions & 0 deletions cmd/finch/devcontainer_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
"github.com/docker/go-connections/nat"
"github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/runfinch/finch/pkg/command"
)
Expand Down Expand Up @@ -108,3 +110,16 @@ func inspectContainerOutputHandler(cmd command.Command) error {
prettyPrintJSON(stdoutBuf.String())
return err
}

func handleDockerCompatComposeVersion(cmdName string, nc nerdctlCommand, runArgs []string) error {
if cmdName == "compose" && nc.fc.DockerCompat && slices.Contains(runArgs, "version") {
ver := nc.systemDeps.Env("DOCKER_COMPOSE_VERSION")
if ver != "" {
logrus.Warn("Displaying docker compose version set as environment variable DOCKER_COMPOSE_VERSION...")
fmt.Println(ver)
return nil
}
return errors.New("DOCKER_COMPOSE_VERSION environment variable is not set")
}
return errors.New("")
}
1 change: 1 addition & 0 deletions cmd/finch/nerdctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type NerdctlCommandSystemDeps interface {
system.FilePathJoiner
system.AbsFilePath
system.FilePathToSlash
system.EnvGetter
}

type nerdctlCommandCreator struct {
Expand Down
4 changes: 4 additions & 0 deletions cmd/finch/nerdctl_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (nc *nerdctlCommand) run(cmdName string, args []string) error {
return inspectContainerOutputHandler(cmd)
}

if err := handleDockerCompatComposeVersion(cmdName, *nc, cmdArgs); err == nil {
return nil
}

return nc.ncc.Create(cmdArgs...).Run()

}
Expand Down
4 changes: 4 additions & 0 deletions cmd/finch/nerdctl_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ func (nc *nerdctlCommand) run(cmdName string, args []string) error {
return inspectContainerOutputHandler(cmd)
}

if err := handleDockerCompatComposeVersion(cmdName, *nc, cmdArgs); err == nil {
return nil
}

return nc.ncc.Create(runArgs...).Run()
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/mocks/nerdctl_cmd_system_deps.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading