Skip to content

Commit

Permalink
feat: add docker-compose (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
fentas committed Apr 3, 2024
1 parent 6a9d2e0 commit 7e9cfee
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
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 @@ import (

"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 @@ func main() {
root := cli.NewCmdBinary(&cli.CmdBinaryOptions{
Binaries: []*binary.Binary{
argsh.Binary(o),
compose.Binary(o),
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 @@ type BinaryOptions struct {
Tracker *progress.Tracker
Envs map[string]string
}

func Arch(arch string) string {
if arch == "amd64" {
return "x86_64"
}
return arch
}
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(),
}
}
// 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
},
VersionF: binary.GithubLatest,
VersionLocalF: func(b *binary.Binary) (string, error) {
v, err := b.Exec("version")
if err != nil {
return "", err
}
s := strings.Split(v, " ")
return s[len(s)-1], nil
},
}
}
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 @@ func Binary(options *binaries.BinaryOptions) *binary.Binary {
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),
), nil
},
Name: "tilt",
Expand Down

0 comments on commit 7e9cfee

Please sign in to comment.