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

testutil: update docker-compose command to docker compose #3249

Merged
merged 3 commits into from
Sep 4, 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
2 changes: 1 addition & 1 deletion p2p/bootnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func resolveRelay(ctx context.Context, rawURL, lockHashHex string, callback func
// queryRelayAddrs returns the relay multiaddrs via a http GET query to the url.
//
// This supports resolving relay addrs from known http URLs which is handy
// when relays are deployed in docker-compose or kubernetes
// when relays are deployed in docker compose or kubernetes
//
// It retries until the context is cancelled.
func queryRelayAddrs(ctx context.Context, relayURL string, backoff func(), lockHashHex string) ([]ma.Multiaddr, error) {
Expand Down
4 changes: 2 additions & 2 deletions testutil/compose/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Charon Compose

> Run, test, and debug a developer-focussed insecure local charon cluster using docker-compose
> Run, test, and debug a developer-focussed insecure local charon cluster using docker compose

Compose is a tool that generates `docker-compose.yml` files such that different charon clusters can be created and run.

Expand All @@ -16,7 +16,7 @@ The `compose` command also includes some convenience functions.
- `compose clean`: Cleans the compose directory of existing files.
- `compose auto`: Runs `compose define && compose lock && compose run`.

Note that compose automatically runs `docker-compose up` at the end of each command. This can be disabled via `--up=false`.
Note that compose automatically runs `docker compose up` at the end of each command. This can be disabled via `--up=false`.

The `compose new` step configures the target cluster and key generation process. See `compose new --help` for supported flags.

Expand Down
2 changes: 1 addition & 1 deletion testutil/compose/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func startAlertCollector(ctx context.Context, dir string) chan string {
// Time required to wait for prometheus container to start.
time.Sleep(time.Second * 10)
for ; ctx.Err() == nil; time.Sleep(iterSleep) { // Sleep for iterSleep before next iteration.
cmd := exec.CommandContext(ctx, "docker-compose", "exec", "-T", "curl", "curl", "-s", "http://prometheus:9090/api/v1/rules?type=alert")
cmd := exec.CommandContext(ctx, "docker", "compose", "exec", "-T", "curl", "curl", "-s", "http://prometheus:9090/api/v1/rules?type=alert")
cmd.Dir = dir
out, err := cmd.CombinedOutput()
if ctx.Err() != nil {
Expand Down
8 changes: 4 additions & 4 deletions testutil/compose/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type AutoConfig struct {
RunTmplFunc func(*TmplData)
// DefineTmplFunc allows arbitrary overrides if the define step template.
DefineTmplFunc func(*TmplData)
// LogFile enables writing (appending) docker-compose output to this file path instead of stdout.
// LogFile enables writing (appending) docker compose output to this file path instead of stdout.
LogFile string
}

Expand Down Expand Up @@ -106,7 +106,7 @@ func Auto(ctx context.Context, conf AutoConfig) error {

_, _ = w.Write([]byte("===== run step: docker compose up --no-start --build =====\n"))

// Build and create docker-compose services before executing docker compose up.
// Build and create docker compose services before executing docker compose up.
if err = execBuildAndCreate(ctx, conf.Dir); err != nil {
return err
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func execDown(ctx context.Context, dir string) error {
// execUp executes `docker compose up` and it writes docker compose logs to the given out io.Writer.
func execUp(ctx context.Context, dir string, out io.Writer) error {
// Build first so containers start at the same time below.
log.Info(ctx, "Executing docker-compose build")
log.Info(ctx, "Executing docker compose build")
cmd := exec.CommandContext(ctx, "docker", "compose", "build", "--parallel")
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil {
Expand All @@ -226,7 +226,7 @@ func execUp(ctx context.Context, dir string, out io.Writer) error {
err = ctx.Err()
}

return errors.Wrap(err, "exec docker-compose up")
return errors.Wrap(err, "exec docker compose up")
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions testutil/compose/compose/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © 2022-2024 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1

// Command compose provides a tool to run, test, debug local charon clusters
// using docker-compose.
// using docker compose.
//
// It consists of multiple steps:
// - compose new: Creates a new config.json that defines what will be composed.
Expand Down Expand Up @@ -34,7 +34,7 @@ func main() {
func newRootCmd() *cobra.Command {
root := &cobra.Command{
Use: "compose",
Short: "Charon Compose - Run, test, and debug a developer-focussed insecure local charon cluster using docker-compose",
Short: "Charon Compose - Run, test, and debug a developer-focussed insecure local charon cluster using docker compose",
}

root.AddCommand(newNewCmd())
Expand Down
4 changes: 2 additions & 2 deletions testutil/compose/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func Define(ctx context.Context, dir string, conf Config) (TmplData, error) {
Nodes: []TmplNode{n},
}
} else {
// Other keygens only need a noop docker-compose, since charon-compose.yml
// Other keygens only need a noop docker compose, since charon-compose.yml
// is used directly in their compose lock.

data = TmplData{
Expand All @@ -169,7 +169,7 @@ func Define(ctx context.Context, dir string, conf Config) (TmplData, error) {
}

log.Info(ctx, "Creating docker-compose.yml")
log.Info(ctx, "Create cluster definition: docker-compose up")
log.Info(ctx, "Create cluster definition: docker compose up")

if err := WriteDockerCompose(dir, data); err != nil {
return TmplData{}, err
Expand Down
4 changes: 1 addition & 3 deletions testutil/compose/docker-compose.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-node-base: &node-base
image: obolnetwork/charon:{{.CharonImageTag}}
{{if .CharonEntrypoint }}entrypoint: {{.CharonEntrypoint}}
Expand Down Expand Up @@ -70,7 +68,7 @@ services:

{{if .Alerting}}
curl:
# Can be used to curl services; e.g. docker-compose exec curl curl http://prometheus:9090/api/v1/rules\?type\=alert
# Can be used to curl services; e.g. docker compose exec curl curl http://prometheus:9090/api/v1/rules\?type\=alert
image: curlimages/curl:latest
command: sleep 1d
networks: [compose]
Expand Down
2 changes: 1 addition & 1 deletion testutil/compose/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func Lock(ctx context.Context, dir string, conf Config) (TmplData, error) {
}

log.Info(ctx, "Creating docker-compose.yml")
log.Info(ctx, "Create keys and cluster lock with: docker-compose up")
log.Info(ctx, "Create keys and cluster lock with: docker compose up")

conf.Step = stepLocked
if err := WriteConfig(dir, conf); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion testutil/compose/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func WriteDockerCompose(dir string, data TmplData) error {

err = os.WriteFile(path.Join(dir, "docker-compose.yml"), buf.Bytes(), 0o755) //nolint:gosec
if err != nil {
return errors.Wrap(err, "write docker-compose")
return errors.Wrap(err, "write docker-compose.yml")
}

return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-node-base: &node-base
image: obolnetwork/charon:latest
entrypoint: echo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-node-base: &node-base
image: obolnetwork/charon:latest
command: [create,dkg]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-node-base: &node-base
image: obolnetwork/charon:latest
command: [create,cluster]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-node-base: &node-base
image: obolnetwork/charon:latest
command: not used
Expand Down
4 changes: 1 addition & 3 deletions testutil/compose/testdata/TestDockerCompose_run_yml.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.8"

x-node-base: &node-base
image: obolnetwork/charon:latest
command: run
Expand Down Expand Up @@ -211,7 +209,7 @@ services:
- .:/compose

curl:
# Can be used to curl services; e.g. docker-compose exec curl curl http://prometheus:9090/api/v1/rules\?type\=alert
# Can be used to curl services; e.g. docker compose exec curl curl http://prometheus:9090/api/v1/rules\?type\=alert
image: curlimages/curl:latest
command: sleep 1d
networks: [compose]
Expand Down
Loading