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: add docker-compose #8

Merged
merged 1 commit into from
Apr 3, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Have a look into [pkg/binary](./pkg/binary/) for more details.
Have a look into [pkg/binaries](./pkg/binaries/) for prepackaged binaries.

- [argsh](https://github.com/arg-sh/argsh) - Utilities for Bash script quality
- [docker-compose](https://github.com/docker/compose) - Define and run multi-container Docker applications
- [gh](https://github.com/cli/cli) - GitHub CLI wrapper
- [hcloud](https://github.com/hetznercloud/cli) - Hetzner Cloud CLI wrapper
- [jq](https://github.com/jqlang/jq) - Command-line JSON processor
Expand Down
2 changes: 2 additions & 0 deletions cmd/b/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

"github.com/buyoio/b/pkg/binaries"
"github.com/buyoio/b/pkg/binaries/argsh"
compose "github.com/buyoio/b/pkg/binaries/docker-compose"
"github.com/buyoio/b/pkg/binaries/gh"
"github.com/buyoio/b/pkg/binaries/hcloud"
"github.com/buyoio/b/pkg/binaries/jq"
Expand Down Expand Up @@ -36,6 +37,7 @@
root := cli.NewCmdBinary(&cli.CmdBinaryOptions{
Binaries: []*binary.Binary{
argsh.Binary(o),
compose.Binary(o),

Check warning on line 40 in cmd/b/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/b/main.go#L40

Added line #L40 was not covered by tests
gh.Binary(o),
hcloud.Binary(o),
jq.Binary(o),
Expand Down
7 changes: 7 additions & 0 deletions pkg/binaries/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@
Tracker *progress.Tracker
Envs map[string]string
}

func Arch(arch string) string {
if arch == "amd64" {
return "x86_64"

Check warning on line 18 in pkg/binaries/binaries.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/binaries.go#L16-L18

Added lines #L16 - L18 were not covered by tests
}
return arch

Check warning on line 20 in pkg/binaries/binaries.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/binaries.go#L20

Added line #L20 was not covered by tests
}
43 changes: 43 additions & 0 deletions pkg/binaries/docker-compose/compose.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package compose

import (
"context"
"fmt"
"runtime"
"strings"

"github.com/buyoio/b/pkg/binaries"
"github.com/buyoio/b/pkg/binary"
)

func Binary(options *binaries.BinaryOptions) *binary.Binary {
if options == nil {
options = &binaries.BinaryOptions{
Context: context.Background(),

Check warning on line 16 in pkg/binaries/docker-compose/compose.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/docker-compose/compose.go#L13-L16

Added lines #L13 - L16 were not covered by tests
}
}
// https://github.com/docker/compose/releases/download/v2.26.1/docker-compose-linux-x86_64
return &binary.Binary{
Context: options.Context,
Envs: options.Envs,
Tracker: options.Tracker,
Version: options.Version,
Name: "docker-compose",
GitHubRepo: "docker/compose",
GitHubFileF: func(b *binary.Binary) (string, error) {
return fmt.Sprintf("docker-compose-%s-%s",
runtime.GOOS,
binaries.Arch(runtime.GOARCH),
), nil
},

Check warning on line 32 in pkg/binaries/docker-compose/compose.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/docker-compose/compose.go#L20-L32

Added lines #L20 - L32 were not covered by tests
VersionF: binary.GithubLatest,
VersionLocalF: func(b *binary.Binary) (string, error) {
v, err := b.Exec("version")
if err != nil {
return "", err

Check warning on line 37 in pkg/binaries/docker-compose/compose.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/docker-compose/compose.go#L34-L37

Added lines #L34 - L37 were not covered by tests
}
s := strings.Split(v, " ")
return s[len(s)-1], nil

Check warning on line 40 in pkg/binaries/docker-compose/compose.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/docker-compose/compose.go#L39-L40

Added lines #L39 - L40 were not covered by tests
},
}
}
8 changes: 1 addition & 7 deletions pkg/binaries/tilt/tilt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
Version: options.Version,
GitHubRepo: "windmilleng/tilt",
GitHubFileF: func(b *binary.Binary) (string, error) {
arch := func(arch string) string {
if arch == "amd64" {
return "x86_64"
}
return arch
}
return fmt.Sprintf("tilt.%s.%s.%s.tar.gz",
b.Version[1:],
runtime.GOOS,
arch(runtime.GOARCH),
binaries.Arch(runtime.GOARCH),

Check warning on line 29 in pkg/binaries/tilt/tilt.go

View check run for this annotation

Codecov / codecov/patch

pkg/binaries/tilt/tilt.go#L29

Added line #L29 was not covered by tests
), nil
},
Name: "tilt",
Expand Down