Skip to content

Commit

Permalink
change docker compose using docker api sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
zulkhair committed Aug 7, 2024
1 parent 69e78c9 commit dbdc41d
Show file tree
Hide file tree
Showing 14 changed files with 996 additions and 38 deletions.
6 changes: 3 additions & 3 deletions cmd/world/cardinal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"pkg.world.dev/world-cli/common"
"pkg.world.dev/world-cli/common/config"
"pkg.world.dev/world-cli/common/docker"
"pkg.world.dev/world-cli/common/logger"
"pkg.world.dev/world-cli/common/teacmd"
"pkg.world.dev/world-cli/tea/style"
)

Expand Down Expand Up @@ -231,7 +231,7 @@ func startRedis(ctx context.Context, cfg *config.Config) error {
// Start Redis container
group.Go(func() error {
cfg.Detach = true
if err := teacmd.DockerStart(cfg, []teacmd.DockerService{teacmd.DockerServiceRedis}); err != nil {
if err := docker.Start(cfg, docker.Redis); err != nil {
return eris.Wrap(err, "Encountered an error with Redis")
}
return nil
Expand All @@ -243,7 +243,7 @@ func startRedis(ctx context.Context, cfg *config.Config) error {
// 2) The parent context is canceled for whatever reason.
group.Go(func() error {
<-ctx.Done()
if err := teacmd.DockerStop([]teacmd.DockerService{teacmd.DockerServiceRedis}); err != nil {
if err := docker.Stop(cfg, docker.Redis); err != nil {
return err
}
return nil
Expand Down
12 changes: 9 additions & 3 deletions cmd/world/cardinal/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (

"github.com/spf13/cobra"

"pkg.world.dev/world-cli/common/teacmd"
"pkg.world.dev/world-cli/common/config"
"pkg.world.dev/world-cli/common/docker"
)

/////////////////
Expand All @@ -19,8 +20,13 @@ var purgeCmd = &cobra.Command{
Short: "Stop and reset the state of your Cardinal game shard",
Long: `Stop and reset the state of your Cardinal game shard.
This command stop all Docker services and remove all Docker volumes.`,
RunE: func(_ *cobra.Command, _ []string) error {
err := teacmd.DockerPurge()
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
if err != nil {
return err
}

err = docker.Purge(cfg)
if err != nil {
return err
}
Expand Down
15 changes: 2 additions & 13 deletions cmd/world/cardinal/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"

"pkg.world.dev/world-cli/common/config"
"pkg.world.dev/world-cli/common/teacmd"
"pkg.world.dev/world-cli/common/docker"
)

// restartCmd restarts your Cardinal game shard stack
Expand All @@ -31,18 +31,7 @@ This will restart the following Docker services:
return err
}

if cfg.Debug {
err = teacmd.DockerRestart(cfg, []teacmd.DockerService{
teacmd.DockerServiceCardinalDebug,
teacmd.DockerServiceNakama,
})
} else {
err = teacmd.DockerRestart(cfg, []teacmd.DockerService{
teacmd.DockerServiceCardinal,
teacmd.DockerServiceNakama,
})
}

err = docker.Restart(cfg, docker.Cardinal, docker.Nakama)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/world/cardinal/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"pkg.world.dev/world-cli/common"
"pkg.world.dev/world-cli/common/config"
"pkg.world.dev/world-cli/common/teacmd"
"pkg.world.dev/world-cli/common/docker"
)

/////////////////
Expand Down Expand Up @@ -112,7 +112,7 @@ This will start the following Docker services and its dependencies:

// Start the World Engine stack
group.Go(func() error {
if err := teacmd.DockerStartAll(cfg); err != nil {
if err := docker.Start(cfg, docker.NakamaDB, docker.Redis, docker.Cardinal, docker.Nakama); err != nil {
return eris.Wrap(err, "Encountered an error with Docker")
}
return eris.Wrap(ErrGracefulExit, "Stack terminated")
Expand Down
12 changes: 9 additions & 3 deletions cmd/world/cardinal/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (

"github.com/spf13/cobra"

"pkg.world.dev/world-cli/common/teacmd"
"pkg.world.dev/world-cli/common/config"
"pkg.world.dev/world-cli/common/docker"
)

/////////////////
Expand All @@ -23,8 +24,13 @@ This will stop the following Docker services:
- Cardinal (Game shard)
- Nakama (Relay) + DB
- Redis (Cardinal dependency)`,
RunE: func(_ *cobra.Command, _ []string) error {
err := teacmd.DockerStopAll()
RunE: func(cmd *cobra.Command, _ []string) error {
cfg, err := config.GetConfig(cmd)
if err != nil {
return err
}

err = docker.Stop(cfg, docker.Nakama, docker.Cardinal, docker.NakamaDB, docker.Redis)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestCreateStartStopRestartPurge(t *testing.T) {
assert.NilError(t, err)

// Start cardinal
rootCmd.SetArgs([]string{"cardinal", "start", "--build", "--detach", "--editor=false"})
rootCmd.SetArgs([]string{"cardinal", "start", "--detach", "--editor=false"})
err = rootCmd.Execute()
assert.NilError(t, err)

Expand Down
Loading

0 comments on commit dbdc41d

Please sign in to comment.