Skip to content

Commit

Permalink
feat: allow user configurable docker compose version env variable
Browse files Browse the repository at this point in the history
Signed-off-by: Shubharanshu Mahapatra <[email protected]>
  • Loading branch information
Shubhranshu153 committed Oct 8, 2024
1 parent 33d519b commit b206698
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/finch/devcontainer_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"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 +111,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 := os.Getenv("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("")
}
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

0 comments on commit b206698

Please sign in to comment.