Skip to content

Commit 319901e

Browse files
authored
Merge pull request #447 from kool-dev/compose-v2
Compose v2
2 parents 699e39c + bb687e9 commit 319901e

23 files changed

+83
-359
lines changed

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
FROM docker/compose:alpine-1.29.2 AS docker-compose
21
FROM golang:1.19 AS build
32

43
ARG BUILD_VERSION=0.0.0-auto
@@ -12,14 +11,13 @@ RUN go build -a \
1211
-ldflags '-X kool-dev/kool/commands.version='$BUILD_VERSION' -extldflags "-static"' \
1312
-o kool
1413

15-
FROM alpine:3.15.4
14+
FROM docker:20.10.21-cli
1615

1716
ENV DOCKER_HOST=tcp://docker:2375
1817

19-
COPY --from=docker-compose /usr/local/bin/docker /usr/local/bin/docker
20-
COPY --from=docker-compose /usr/local/bin/docker-compose /usr/local/bin/docker-compose
2118
COPY --from=build /app/kool /usr/local/bin/kool
2219

23-
RUN apk add --no-cache git bash
20+
RUN apk add --no-cache git bash \
21+
&& rm -rf /var/cache/apk/* /tmp/*
2422

2523
CMD [ "kool" ]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## About `kool`
1515

16-
**Kool** is a CLI tool that brings the complexities of modern software development environments down to earth - making these environments lightweight, fast and reproducible. It reduces the complexity and learning curve of _Docker_ and _Docker Compose_ for local environments, and offers a simplified interface for using _Kubernetes_ to deploy staging and production environments to the cloud.
16+
**Kool** is a CLI tool that brings the complexities of modern software development environments down to earth - making these environments lightweight, fast and reproducible. It reduces the complexity and learning curve of _Docker_ containers for local environments, and offers a simplified interface for using _Kubernetes_ to deploy staging and production environments to the cloud.
1717

1818
**Kool** gets your local development environment up and running easily and quickly, so you have more time to build a great application. When the time is right, you can then use Kool Cloud to deploy and share your work with the world!
1919

@@ -25,6 +25,8 @@
2525

2626
Requirements: Kool is powered by [Docker](https://docs.docker.com/get-docker/). If you haven't done so already, you first need to [install Docker and the kool CLI](https://kool.dev/docs/getting-started/installation).
2727

28+
**Important**: make sure you are running the latest version of Docker and that you do have Composer V2 available (`docker compose`). You can read more about [Compose V2 release via its documentation](https://docs.docker.com/compose/reference/).
29+
2830
### For Linux and macOS
2931

3032
Install **kool** by running the following script. It will download the latest **kool** binary from [https://github.com/kool-dev/kool/releases](https://github.com/kool-dev/kool/releases), and save it in your `/usr/local/bin` folder.

commands/exec.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io"
77
"kool-dev/kool/core/builder"
88
"kool-dev/kool/core/environment"
9-
"kool-dev/kool/services/compose"
109
"os"
1110
"strings"
1211

@@ -44,7 +43,7 @@ func NewKoolExec() *KoolExec {
4443
*newDefaultKoolService(),
4544
&KoolExecFlags{false, []string{}, false},
4645
environment.NewEnvStorage(),
47-
compose.NewDockerCompose("exec"),
46+
builder.NewCommand("docker", "compose", "exec"),
4847
}
4948
}
5049

@@ -54,11 +53,6 @@ func (e *KoolExec) detectTTY() {
5453
if !isTerminal {
5554
e.composeExec.AppendArgs("-T")
5655
}
57-
58-
if aware, ok := e.composeExec.(compose.TtyAware); ok {
59-
// let DockerCompose know about whether we are under TTY or not
60-
aware.SetIsTTY(isTerminal)
61-
}
6256
}
6357

6458
func (e *KoolExec) checkUser(service string) {
@@ -88,9 +82,11 @@ func (e *KoolExec) checkUser(service string) {
8882
// so we avoid getting cross-fire on in/out redirections
8983
actualOut := e.Shell().OutStream()
9084
defer e.Shell().SetOutStream(actualOut)
91-
9285
e.Shell().SetOutStream(os.Stderr)
93-
e.Shell().Warning(fmt.Sprintf("failed to check running container for kool user; did you forget kool start? (err: %s)", err.Error()))
86+
87+
if e.env.IsTrue("KOOL_VERBOSE") {
88+
e.Shell().Warning(fmt.Sprintf("failed to check running container for kool user; did you forget kool start? (err: %s)", err.Error()))
89+
}
9490
} else if strings.Contains(passwd, fmt.Sprintf("kool:x:%s", asuser)) {
9591
// since user (kool:x:UID) exists within the container, we set it
9692
e.composeExec.AppendArgs("--user", asuser)

commands/exec_test.go

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"kool-dev/kool/core/builder"
77
"kool-dev/kool/core/environment"
88
"kool-dev/kool/core/shell"
9-
"kool-dev/kool/services/compose"
10-
"strings"
119
"testing"
1210
)
1311

@@ -51,10 +49,6 @@ func TestNewKoolExec(t *testing.T) {
5149
t.Errorf("bad default value for Detach flag on default KoolExec instance")
5250
}
5351
}
54-
55-
if _, ok := k.composeExec.(*compose.DockerCompose); !ok {
56-
t.Errorf("unexpected compose.DockerCompose on default KoolExec instance")
57-
}
5852
}
5953

6054
func TestNewExecCommand(t *testing.T) {
@@ -191,31 +185,20 @@ func TestFailingNewExecCommand(t *testing.T) {
191185

192186
func TestDockerComposeTerminalAwarness(t *testing.T) {
193187
f := newFakeKoolExec()
194-
f.composeExec = compose.NewDockerCompose("cmd")
195-
f.composeExec.(*compose.DockerCompose).SetShell(&shell.FakeShell{})
196-
f.composeExec.(*compose.DockerCompose).SetLocalDockerCompose(&builder.FakeCommand{
197-
MockLookPathError: errors.New("some error"),
198-
})
199-
200-
cmd := NewExecCommand(f)
201-
cmd.SetArgs([]string{"service", "command"})
188+
f.composeExec = &builder.FakeCommand{MockCmd: "docker", ArgsAppend: []string{"compose", "exec"}}
202189

203190
f.shell.(*shell.FakeShell).MockIsTerminal = false
204-
if err := cmd.Execute(); err != nil {
205-
t.Errorf("unexpected error executing exec command; error: %v", err)
206-
}
207-
208-
if strings.Contains(f.composeExec.String(), " -t ") {
209-
t.Errorf("unexpected -t flag when NOT under TTY; %s", f.composeExec.String())
191+
f.detectTTY()
192+
var l = len(f.composeExec.Args())
193+
if f.composeExec.Args()[l-1] != "-T" {
194+
t.Errorf("missing -T flag when NOT under TTY; %s", f.composeExec.String())
210195
}
211196

197+
f.composeExec = &builder.FakeCommand{MockCmd: "docker", ArgsAppend: []string{"compose", "exec"}}
212198
f.shell.(*shell.FakeShell).MockIsTerminal = true
213-
if err := cmd.Execute(); err != nil {
214-
t.Errorf("unexpected error executing exec command; error: %v", err)
215-
}
216-
217-
if !strings.Contains(f.composeExec.String(), " -t ") {
218-
t.Error("missing -t flag when under TTY")
199+
l = len(f.composeExec.Args())
200+
if f.composeExec.Args()[l-1] == "-T" {
201+
t.Error("unexpected -t flag when under TTY")
219202
}
220203
}
221204

commands/info.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package commands
22

33
import (
4+
"fmt"
45
"kool-dev/kool/core/builder"
56
"kool-dev/kool/core/environment"
67
"os"
@@ -37,7 +38,7 @@ func NewKoolInfo() *KoolInfo {
3738
*newDefaultKoolService(),
3839
environment.NewEnvStorage(),
3940
builder.NewCommand("docker", "-v"),
40-
builder.NewCommand("docker-compose", "-v"),
41+
builder.NewCommand("docker", "compose", "version"),
4142
}
4243
}
4344

@@ -79,16 +80,14 @@ func (i *KoolInfo) Execute(args []string) (err error) {
7980

8081
i.Shell().Println("")
8182

82-
// docker-compose CLI info
83+
// docker compose v2 info
8384
if output, err = i.Shell().Exec(i.cmdDockerCompose); err != nil {
84-
// just alert missing docker-compose, but don't elevate error
85+
// just alert missing docker compose, but don't elevate error
8586
i.Shell().Warning("Docker Compose:", err.Error())
86-
i.Shell().Warning("It's okay not having docker-compose installed, as kool will fallback to using a container for it when necessary.")
87-
err = nil
87+
i.Shell().Error(fmt.Errorf("You need to have Docker Compose V2 available. Make sure to update your Docker installation."))
88+
return
8889
} else {
8990
i.Shell().Println(output)
90-
output, _ = exec.LookPath("docker-compose")
91-
i.Shell().Println("Docker Compose Bin Path:", output)
9291
}
9392

9493
i.Shell().Println("")
@@ -106,5 +105,8 @@ func (i *KoolInfo) Execute(args []string) (err error) {
106105
}
107106
}
108107

108+
i.Shell().Println("")
109+
i.Shell().Println("kool installation seems to be working as expected.")
110+
109111
return
110112
}

commands/logs.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commands
22

33
import (
44
"kool-dev/kool/core/builder"
5-
"kool-dev/kool/services/compose"
65
"strconv"
76
"strings"
87

@@ -38,8 +37,8 @@ func NewKoolLogs() *KoolLogs {
3837
return &KoolLogs{
3938
*newDefaultKoolService(),
4039
&KoolLogsFlags{25, false},
41-
compose.NewDockerCompose("ps", "-aq"),
42-
compose.NewDockerCompose("logs"),
40+
builder.NewCommand("docker", "compose", "ps", "-aq"),
41+
builder.NewCommand("docker", "compose", "logs"),
4342
}
4443
}
4544

commands/logs_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"kool-dev/kool/core/builder"
77
"kool-dev/kool/core/shell"
8-
"kool-dev/kool/services/compose"
98
"testing"
109
)
1110

@@ -46,12 +45,12 @@ func TestNewKoolLogs(t *testing.T) {
4645
}
4746
}
4847

49-
if _, ok := k.logs.(*compose.DockerCompose); !ok {
48+
if _, ok := k.logs.(*builder.DefaultCommand); !ok {
5049
t.Error("unexpected builder.Command on default KoolLogs instance")
5150
}
5251

53-
if k.logs.(*compose.DockerCompose).Command.String() != "logs" {
54-
t.Error("unexpected compose.DockerCompose.Command.String() on default KoolLogs instance logs")
52+
if k.logs.String() != "docker compose logs" {
53+
t.Error("unexpected logs .String() on default KoolLogs instance logs")
5554
}
5655
}
5756

@@ -177,7 +176,7 @@ func TestNoContainersNewLogsCommand(t *testing.T) {
177176
}
178177

179178
if val, ok := f.shell.(*shell.FakeShell).CalledInteractive["logs"]; val && ok {
180-
t.Error("should not call docker-compose logs if there are no containers")
179+
t.Error("should not call docker compose logs if there are no containers")
181180
}
182181
}
183182

commands/self-update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (s *KoolSelfUpdate) Execute(args []string) (err error) {
5757
}
5858

5959
s.Shell().Success("Successfully updated to version ", latestVersion.String())
60+
s.Shell().Println("Please run 'kool info' now to validate your local environment.")
6061
return
6162
}
6263

commands/start.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"kool-dev/kool/core/environment"
66
"kool-dev/kool/core/network"
77
"kool-dev/kool/services/checker"
8-
"kool-dev/kool/services/compose"
98
"kool-dev/kool/services/updater"
109

1110
"github.com/spf13/cobra"
@@ -68,11 +67,11 @@ func NewKoolStart() *KoolStart {
6867
checker.NewChecker(defaultKoolService.shell),
6968
network.NewHandler(defaultKoolService.shell),
7069
environment.NewEnvStorage(),
71-
compose.NewDockerCompose("up", "--force-recreate"),
70+
builder.NewCommand("docker", "compose", "up", "--force-recreate"),
7271
&KoolRebuild{
7372
*newDefaultKoolService(),
74-
compose.NewDockerCompose("pull"),
75-
compose.NewDockerCompose("build", "--pull"),
73+
builder.NewCommand("docker", "compose", "pull"),
74+
builder.NewCommand("docker", "compose", "build", "--pull"),
7675
},
7776
}
7877
}
@@ -100,10 +99,7 @@ func (s *KoolStart) Execute(args []string) (err error) {
10099
}
101100

102101
if len(s.Flags.Profile) > 0 {
103-
if aware, ok := s.start.(compose.LocalDockerComposeAware); ok {
104-
// let DockerCompose know about whether we are under TTY or not
105-
aware.LocalDockerCompose().AppendArgs("--profile", s.Flags.Profile)
106-
}
102+
s.start.AppendArgs("--profile", s.Flags.Profile)
107103
}
108104

109105
if !s.Flags.Foreground {

commands/status.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"kool-dev/kool/core/network"
77
"kool-dev/kool/core/shell"
88
"kool-dev/kool/services/checker"
9-
"kool-dev/kool/services/compose"
109
"strings"
1110
"sync"
1211

@@ -51,8 +50,8 @@ func NewKoolStatus() *KoolStatus {
5150
checker.NewChecker(defaultKoolService.shell),
5251
network.NewHandler(defaultKoolService.shell),
5352
environment.NewEnvStorage(),
54-
compose.NewDockerCompose("ps", "--services"),
55-
compose.NewDockerCompose("ps", "-q"),
53+
builder.NewCommand("docker", "compose", "ps", "--services"),
54+
builder.NewCommand("docker", "compose", "ps", "-q"),
5655
builder.NewCommand("docker", "ps", "-a", "--format", "{{.Status}}|{{.Ports}}"),
5756
shell.NewTableWriter(),
5857
}

0 commit comments

Comments
 (0)