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 8, 2024
1 parent 69e78c9 commit c09682e
Show file tree
Hide file tree
Showing 14 changed files with 1,143 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

Check warning on line 26 in cmd/world/cardinal/purge.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/purge.go#L26

Added line #L26 was not covered by tests
}

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
9 changes: 7 additions & 2 deletions cmd/world/cardinal/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"strings"

"github.com/google/uuid"
"github.com/rotisserie/eris"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"

"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 @@ -108,11 +109,15 @@ This will start the following Docker services and its dependencies:
fmt.Println("This may take a few minutes to rebuild the Docker images.")
fmt.Println("Use `world cardinal dev` to run Cardinal faster/easier in development mode.")

// Print CockroachDB password
cfg.DockerEnv["DB_PASSWORD"] = uuid.New().String()
printServiceAddress("DB Password", cfg.DockerEnv["DB_PASSWORD"])

group, ctx := errgroup.WithContext(cmd.Context())

// 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

Check warning on line 30 in cmd/world/cardinal/stop.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/cardinal/stop.go#L30

Added line #L30 was not covered by tests
}

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", "-v"})
err = rootCmd.Execute()
assert.NilError(t, err)

Expand Down
Loading

0 comments on commit c09682e

Please sign in to comment.