Skip to content

Commit

Permalink
add docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
lerenn committed Apr 18, 2024
1 parent 651b2a9 commit dbecbc8
Show file tree
Hide file tree
Showing 33 changed files with 650 additions and 529 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ endif
ci: ## Run the CI
@${DAGGER_COMMAND} all

.PHONY: dev/up
dev/up: ## Start the development environment
@go run ./tools/generate-certs
@docker-compose up -d

.PHONY: dev/down
dev/down: ## Stop the development environment
@docker-compose down

.PHONY: lint
lint: ## Lint the code
@${DAGGER_COMMAND} linter
Expand Down
67 changes: 24 additions & 43 deletions build/ci/dagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"strings"
"sync"

"dagger.io/dagger"
Expand All @@ -21,11 +20,6 @@ var (
testFlag string

brokers map[string]*dagger.Service

generator func(context.Context) error
linter *dagger.Container
examples map[string]*dagger.Container
tests map[string]*dagger.Container
)

var rootCmd = &cobra.Command{
Expand All @@ -42,12 +36,6 @@ var rootCmd = &cobra.Command{
// Create services
brokers = ci.Brokers(client)

// Create containers
generator = ci.Generator(client)
linter = ci.Linter(client)
examples = ci.Examples(client, brokers)
tests = ci.Tests(client, brokers)

return nil
},
}
Expand All @@ -57,9 +45,10 @@ var allCmd = &cobra.Command{
Aliases: []string{"a"},
Short: "Execute all CI",
Run: func(cmd *cobra.Command, args []string) {
execute(context.Background(), generator)
executeContainers(context.Background(), []*dagger.Container{linter})
executeContainers(context.Background(), utils.MapToList(tests), utils.MapToList(examples))
execute(context.Background(), ci.Generator(client))
executeContainers(context.Background(), ci.Linter(client))
executeContainers(context.Background(), ci.Tests(client, brokers, "./..."))
executeContainers(context.Background(), ci.Tests(client, brokers, "./..."))
},
}

Expand All @@ -68,14 +57,16 @@ var examplesCmd = &cobra.Command{
Aliases: []string{"g"},
Short: "Execute examples step of the CI",
Run: func(cmd *cobra.Command, args []string) {
examples := ci.Examples(client, brokers)

if exampleFlag != "" {
_, exists := examples[exampleFlag]
if !exists {
panic(fmt.Errorf("example %q doesn't exist", exampleFlag))
}
executeContainers(context.Background(), []*dagger.Container{examples[exampleFlag]})
executeContainers(context.Background(), examples[exampleFlag])
} else {
executeContainers(context.Background(), utils.MapToList(examples))
executeContainers(context.Background(), utils.MapToList(examples)...)
}
},
}
Expand All @@ -85,7 +76,7 @@ var generatorCmd = &cobra.Command{
Aliases: []string{"g"},
Short: "Execute generator step of the CI",
Run: func(cmd *cobra.Command, args []string) {
execute(context.Background(), generator)
execute(context.Background(), ci.Generator(client))
},
}

Expand All @@ -94,7 +85,7 @@ var linterCmd = &cobra.Command{
Aliases: []string{"g"},
Short: "Execute linter step of the CI",
Run: func(cmd *cobra.Command, args []string) {
executeContainers(context.Background(), []*dagger.Container{linter})
executeContainers(context.Background(), ci.Linter(client))
},
}

Expand All @@ -112,19 +103,11 @@ var testCmd = &cobra.Command{
Aliases: []string{"g"},
Short: "Execute tests step of the CI",
Run: func(cmd *cobra.Command, args []string) {
if testFlag != "" {
if !strings.HasPrefix(testFlag, "./") {
testFlag = "./" + testFlag
}

_, exists := tests[testFlag]
if !exists {
panic(fmt.Errorf("test %q doesn't exist in %+v", testFlag, tests))
}
executeContainers(context.Background(), []*dagger.Container{tests[testFlag]})
} else {
executeContainers(context.Background(), utils.MapToList(tests))
if testFlag == "" {
testFlag = "./..."
}

executeContainers(context.Background(), ci.Tests(client, brokers, testFlag))
},
}

Expand All @@ -150,24 +133,22 @@ func main() {
}
}

func executeContainers(ctx context.Context, containers ...[]*dagger.Container) {
func executeContainers(ctx context.Context, containers ...*dagger.Container) {
// Regroup arg
funcs := make([]func(context.Context) error, 0)
for _, l1 := range containers {
for _, l2 := range l1 {
if l2 == nil {
continue
}
if l1 == nil {
continue
}

// Note: create a new local variable to store value of actual l2
callback := l2
// Note: create a new local variable to store value of actual l2
callback := l1

fn := func(ctx context.Context) error {
_, err := callback.Stderr(ctx)
return err
}
funcs = append(funcs, fn)
fn := func(ctx context.Context) error {
_, err := callback.Stderr(ctx)
return err
}
funcs = append(funcs, fn)
}

execute(ctx, funcs...)
Expand Down
122 changes: 122 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
services:
# NATS variants
nats:
image: nats:latest
ports:
- 4222:4222
nats-tls:
image: nats:latest
ports:
- "4223:4222"
command: [
"--tls",
"--tlscert", "/certs/server-cert.pem",
"--tlskey", "/certs/server-key.pem",
]
volumes:
- ./tmp/certs/nats:/certs
nats-tls-basic-auth:
image: nats:latest
ports:
- 4224:4222
command: [
"--tls",
"--tlscert", "/certs/server-cert.pem",
"--tlskey", "/certs/server-key.pem",
"--user", "user",
"--pass", "password",
]
volumes:
- ./tmp/certs/nats:/certs

# NATS Jetstream variants
nats-jetstream:
image: nats:latest
ports:
- 4225:4222
command: [
"-js",
]
nats-jetstream-tls:
image: nats:latest
ports:
- 4226:4222
command: [
"-js",
"--tls",
"--tlscert", "/certs/server-cert.pem",
"--tlskey", "/certs/server-key.pem",
]
volumes:
- ./tmp/certs/nats:/certs
nats-jetstream-tls-basic-auth:
image: nats:latest
ports:
- 4227:4222
command: [
"-js",
"--tls",
"--tlscert", "/certs/server-cert.pem",
"--tlskey", "/certs/server-key.pem",
"--user", "user",
"--pass", "password",
]
volumes:
- ./tmp/certs/nats:/certs

# Kafka variants
kafka:
image: bitnami/kafka:3.5.1
ports:
- 9092:9092
- 9093:9093
environment:
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_LISTENERS=INTERNAL://:9092,CONTROLLER://:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://localhost:9092
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@:9093
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
kafka-tls:
image: bitnami/kafka:3.5.1
ports:
- 9094:9094
- 9095:9095
environment:
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_LISTENERS=INTERNAL://:9094,CONTROLLER://:9095
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://localhost:9094
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,INTERNAL:SSL
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@:9095
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
- KAFKA_TLS_TYPE=PEM
- KAFKA_TLS_CLIENT_AUTH=none
volumes:
- ./tmp/certs/kafka:/bitnami/kafka/config/certs/
kafka-tls-basic-auth:
image: bitnami/kafka:3.5.1
ports:
- 9096:9096
- 9097:9097
environment:
- KAFKA_CFG_NODE_ID=0
- KAFKA_CFG_PROCESS_ROLES=controller,broker
- KAFKA_CFG_LISTENERS=INTERNAL://:9096,CONTROLLER://:9097
- KAFKA_CFG_ADVERTISED_LISTENERS=INTERNAL://localhost:9096
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,INTERNAL:SASL_SSL
- KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@:9097
- KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=INTERNAL
- KAFKA_CFG_SASL_MECHANISM_INTER_BROKER_PROTOCOL=SCRAM-SHA-512
- KAFKA_TLS_TYPE=PEM
- KAFKA_TLS_CLIENT_AUTH=none
- KAFKA_INTER_BROKER_USER=user
- KAFKA_INTER_BROKER_PASSWORD=password
volumes:
- ./tmp/certs/kafka:/bitnami/kafka/config/certs/


4 changes: 2 additions & 2 deletions pkg/asyncapi/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (suite *ParseSuite) TestCorrectVersions() {
suite.Require().Equal(len(correctVersions), len(SupportedVersions))

for _, v := range correctVersions {
b := []byte(fmt.Sprintf("{\"version\":\"%s\"}", v))
b := []byte(fmt.Sprintf("{\"asyncapi\":\"%s\"}", v))
_, err := FromJSON(b)
suite.Require().NoError(err)
}
Expand All @@ -37,7 +37,7 @@ func (suite *ParseSuite) TestIncorrectVersions() {
}

for _, v := range correctVersions {
b := []byte(fmt.Sprintf("{\"version\":\"%s\"}", v))
b := []byte(fmt.Sprintf("{\"asyncapi\":\"%s\"}", v))
_, err := FromJSON(b)
suite.Require().Error(err)
suite.Require().ErrorIs(err, ErrInvalidVersion)
Expand Down
Loading

0 comments on commit dbecbc8

Please sign in to comment.