Skip to content

Release merge #18

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

Merged
merged 6 commits into from
May 15, 2025
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
38 changes: 36 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,49 @@ jobs:
asset-name: ccmanager-${{ matrix.goos }}-${{ matrix.goarch }}
file: ccmanager

# Separate mac amd64 build to support fsevents dependency
buildmacamd64:
runs-on: macos-13
strategy:
matrix:
goos:
- darwin
goarch:
- amd64

env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}

steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.21"

- name: Build
run: go build -o ccmanager cmd/ccmanager.go

- name: Release file
uses: djnicholson/release-action@v2.10
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-name: ${{ github.event.release.name }}
tag-name: ${{ github.event.release.tag_name }}
asset-name: ccmanager-${{ matrix.goos }}-${{ matrix.goarch }}
file: ccmanager


# Separate mac build to support fsevents dependency
buildmac:
buildmacarm64:
runs-on: macos-14 # beta arm runner
strategy:
matrix:
goos:
- darwin
goarch:
- amd64
- arm64

env:
Expand Down
28 changes: 6 additions & 22 deletions cmd/ccmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,24 @@ import (
"ccmanager/internal/adapters"
"ccmanager/internal/models"
"fmt"
"github.com/akamensky/argparse"
"github.com/alexflint/go-arg"
"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"log"
"os"
"strings"
)

func main() {
parser := argparse.NewParser("ccmanager", "CloudControl instance manager")
basePath := parser.StringList("b", "basepath", &argparse.Options{
Help: "Paths where to find CloudControl docker compose folders. Can be set using a comma separated list in CCMANAGER_BASEPATH",
Required: false,
})

if err := parser.Parse(os.Args); err != nil {
log.Fatal(parser.Usage(err))
}

if len(*basePath) == 0 {
if e, found := os.LookupEnv("CCMANAGER_BASEPATH"); found {
*basePath = strings.Split(e, ",")
}
}

if len(*basePath) == 0 {
log.Fatal(parser.Usage("No basepath given. Please use CCMANAGER_BASEPATH or the --basepath argument"))
var args struct {
BasePath []string `arg:"required,env:CCMANAGER_BASEPATH,separate" help:"Paths where to find CloudControl docker compose folders"`
ContainerSeparator string `default:"-" arg:"env:CCMANAGER_SEP" help:"Separator used in docker compose container names"`
}
arg.MustParse(&args)

var items []list.Item

d := adapters.DockerAdapter{}

program := tea.NewProgram(models.NewMainModel(&d, *basePath, items))
program := tea.NewProgram(models.NewMainModel(&d, args.BasePath, items))
if _, err := program.Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/alexflint/go-arg v1.5.1 // indirect
github.com/alexflint/go-scalar v1.2.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.6 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.16 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alexflint/go-arg v1.5.1 h1:nBuWUCpuRy0snAG+uIJ6N0UvYxpxA0/ghA/AaHxlT8Y=
github.com/alexflint/go-arg v1.5.1/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8=
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1rlcoLz8y5B2r4tTLMiVTrMtpfY0O8EScKJxaSaEc=
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down
67 changes: 37 additions & 30 deletions internal/adapters/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type DockerAdapter struct {
}

func (d *DockerAdapter) GetContainerStatus(basePath string, name string) (CloudControlStatus, error) {
containerName := fmt.Sprintf("%s_cli_1", name)
containerName := fmt.Sprintf("%s%scli%s1", name, api.Separator, api.Separator)
c := d.getClient()
notFound := regexp.MustCompile("No such container")
if i, err := c.ContainerInspect(context.Background(), containerName); err != nil {
Expand Down Expand Up @@ -86,7 +86,7 @@ func (d *DockerAdapter) GetContainerStatus(basePath string, name string) (CloudC
}

func (d *DockerAdapter) RunCloudControl(_ string, name string, consoleWidth uint, consoleHeight uint) (*ContainerExec, error) {
containerName := fmt.Sprintf("%s_cli_1", name)
containerName := fmt.Sprintf("%s%scli%s1", name, api.Separator, api.Separator)
consoleSize := [2]uint{consoleHeight, consoleWidth}
return &ContainerExec{
exec: func(stdin io.Reader, stdout io.Writer) error {
Expand Down Expand Up @@ -135,65 +135,74 @@ func (d *DockerAdapter) RunCloudControl(_ string, name string, consoleWidth uint
}

go func(c net.Conn) {
active := true
s := bufio.NewReader(c)
for {
select {
case <-quitWriter:
return
default:
if b, err := s.ReadByte(); err != nil {
logrus.Errorf("error reading from Docker: %s", err)
return
} else {
if _, err := stdout.Write([]byte{b}); err != nil {
logrus.Errorf("error writing to stdout: %s", err)
if active {
if b, err := s.ReadByte(); err != nil {
logrus.Errorf("error reading from Docker: %s", err)
active = false
} else {
if _, err := stdout.Write([]byte{b}); err != nil {
logrus.Errorf("error writing to stdout: %s", err)
}
}
}
}
}
}(execResponse.Conn)

go func(c net.Conn) {
active := true
s := bufio.NewReader(stdin)
for {
select {
case <-quitReader:
return
default:
if b, err := s.ReadByte(); err != nil {
logrus.Errorf("error reading from Docker: %s", err)
return
} else {
if _, err := c.Write([]byte{b}); err != nil {
logrus.Errorf("error writing to Docker: %s", err)
return
if active {
if b, err := s.ReadByte(); err != nil {
logrus.Errorf("error reading from Docker: %s", err)
active = false
} else {
if _, err := c.Write([]byte{b}); err != nil {
logrus.Errorf("error writing to Docker: %s", err)
active = false
}
}
}
}
}
}(execResponse.Conn)

go func() {
active := true
width := consoleWidth
height := consoleHeight
for {
select {
case <-quitTermResize:
return
default:
if w, err := term.GetWinsize(fd); err != nil {
logrus.Errorf("error getting terminal size: %s", err)
return
} else {
if w.Width != uint16(width) || w.Height != uint16(height) {
width = uint(w.Width)
height = uint(w.Height)
if err := dockerCli.ContainerExecResize(context.Background(), executeID, types.ResizeOptions{
Width: width,
Height: height,
}); err != nil {
logrus.Errorf("error resizing container terminal: %s", err)
return
if active {
if w, err := term.GetWinsize(fd); err != nil {
logrus.Errorf("error getting terminal size: %s", err)
active = false
} else {
if w.Width != uint16(width) || w.Height != uint16(height) {
width = uint(w.Width)
height = uint(w.Height)
if err := dockerCli.ContainerExecResize(context.Background(), executeID, types.ResizeOptions{
Width: width,
Height: height,
}); err != nil {
logrus.Errorf("error resizing container terminal: %s", err)
active = false
}
}
}
}
Expand Down Expand Up @@ -270,8 +279,6 @@ func (d *DockerAdapter) getClient() client.Client {
func (d *DockerAdapter) getComposeBackend() api.Service {
if d.composeBackend == nil {
cl := d.getClient()
// ensure old docker-compose compatibility
api.Separator = "_"
if c, err := command.NewDockerCli(command.WithAPIClient(&cl), command.WithDefaultContextStoreConfig()); err != nil {
panic(fmt.Sprintf("Can not connect to Docker API: %s", err.Error()))
} else {
Expand Down
Loading