Skip to content

Commit

Permalink
Rename compose.native variants to compose.all-in for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesir87 committed Dec 5, 2024
1 parent 8438588 commit a5c562e
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 17 deletions.
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ During development, containers provide the following services:

![Dev environment architecture](./dev-environment-architecture.png)


## Trying it out

This project is configured to run with the app running either natively (using Node installed on the machine) or in a container.
Expand All @@ -37,34 +36,32 @@ This project is configured to run with the app running either natively (using No

2. Start all of the application dependencies

```console
docker compose up
```
```console
docker compose up
```

3. Install the app dependencies and start the main app with the following command:

```console
yarn install
yarn dev
```
```console
yarn install
yarn dev
```

#### Debugging the application

Once the app is running, you can start a debug session by using the **Debug** task in the "Run and Debug" panel.

Once the app is running, you can start a debug session by using the **Debug** task in the "Run and Debug" panel.

### Running completely in containers

The `compose.native.yaml` file defines an additional `app` service that will run the application in the container.
The `compose.all-in.yaml` file defines an additional `app` service that will run the application in the container.

The code is currently mounted into the app container, theoretically allowing for hot reloading. However, there is a limitation for WSL environments where the filesystem event isn't propagated, preventing nodemon from seeing the file change event.

1. Start the app using Compose, but specifying the native file

```console
docker compose -f compose.native.yaml
```
1. Start the app using Compose, but specifying the "all-in" file

```console
docker compose -f compose.all-in.yaml
```

### Running tests

Expand All @@ -76,7 +73,7 @@ This project contains a few sample tests to demonstrate Testcontainer integratio

3. Press play for the test you'd like to run.

The *.integration.spec.js tests will use Testcontainers to launch Kafka, Postgres, and LocalStack.
The \*.integration.spec.js tests will use Testcontainers to launch Kafka, Postgres, and LocalStack.

#### Running tests via the command line

Expand Down
103 changes: 103 additions & 0 deletions compose.all-in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
services:
############## THE APP ITSELF ##############
app:
build:
context: .
target: dev
volumes:
- .:/usr/local/app
ports:
- 3000:3000
environment:
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_REGION: us-east-1
AWS_ENDPOINT_URL: http://aws:4566
KAFKA_BOOTSTRAP_SERVERS: kafka:9093
INVENTORY_SERVICE_BASE_URL: http://mock-inventory:8080
PGHOST: postgres

############## DATABASE AND VISUALIZER ##############
postgres:
image: postgres:17.1
# ports:
# - "5432:5432"
volumes:
- ./dev/db:/docker-entrypoint-initdb.d
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: catalog

pgadmin:
image: dpage/pgadmin4:8.13.0
ports:
- "5050:80"
volumes:
- ./dev/pgadmin/servers.json:/pgadmin4/servers.json
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: secret
PGADMIN_CONFIG_SERVER_MODE: 'False'
depends_on:
- postgres

############## LOCAL AWS ##############
aws:
image: localstack/localstack:3.8.1
ports:
- "4566:4566"

bucket-creator:
image: localstack/localstack:3.8.1
entrypoint: []
command: awslocal --endpoint-url http://aws:4566 s3api create-bucket --bucket product-images
depends_on:
aws:
condition: service_healthy

############## MOCK INVENTORY SERVICE ##############
mock-inventory:
image: wiremock/wiremock:3.9.2
# ports:
# - 8090:8080
volumes:
- ./dev/inventory-mocks:/home/wiremock

############## KAFKA AND VISUALIZATION ##############
kafka:
image: apache/kafka-native:3.9.0
environment:
# Configure listeners for both docker and host communication
KAFKA_LISTENERS: CONTROLLER://localhost:9091,HOST://0.0.0.0:9092,DOCKER://0.0.0.0:9093
KAFKA_ADVERTISED_LISTENERS: HOST://localhost:9092,DOCKER://kafka:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,DOCKER:PLAINTEXT,HOST:PLAINTEXT

# Settings required for KRaft mode
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9091

# Listener to use for broker-to-broker communication
KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER

# Required for a single node cluster
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

kafka-topic-creator:
image: apache/kafka:3.9.0
command: /opt/kafka/bin/kafka-topics.sh --create --topic products --partitions 1 --replication-factor 1 --bootstrap-server kafka:9093
depends_on:
- kafka

kafka-ui:
image: ghcr.io/kafbat/kafka-ui:01aa8ab36387c5f1d66d098e71488bfb0eb5f39c
ports:
- 8080:8080
environment:
DYNAMIC_CONFIG_ENABLED: 'true'
KAFKA_CLUSTERS_0_NAME: local
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9093
depends_on:
- kafka
114 changes: 114 additions & 0 deletions compose.traefik-all-in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
services:
proxy:
image: traefik:v3.1
command: --providers.docker --api.insecure
ports:
- "80:80"
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"

############## THE APP ITSELF ##############
app:
build:
context: .
target: dev
volumes:
- .:/usr/local/app
ports:
- 3000:3000
environment:
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
AWS_REGION: us-east-1
AWS_ENDPOINT_URL: http://aws:4566
KAFKA_BOOTSTRAP_SERVERS: kafka:9093
INVENTORY_SERVICE_BASE_URL: http://mock-inventory:8080
PGHOST: postgres

############## DATABASE AND VISUALIZER ##############
postgres:
image: postgres:17.1
volumes:
- ./dev/db:/docker-entrypoint-initdb.d
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: catalog

pgadmin:
image: dpage/pgadmin4:8.13.0
volumes:
- ./dev/pgadmin/servers.json:/pgadmin4/servers.json
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: secret
PGADMIN_CONFIG_SERVER_MODE: 'False'
depends_on:
- postgres
labels:
traefik.http.routers.pgadmin.rule: Host(`pgadmin.localhost`)
traefik.http.services.pgadmin.loadbalancer.server.port: 80

############## LOCAL AWS ##############
aws:
image: localstack/localstack:3.8.1
labels:
traefik.http.routers.aws.rule: Host(`aws.localhost`)
traefik.http.services.aws.loadbalancer.server.port: 4566

bucket-creator:
image: localstack/localstack:3.8.1
entrypoint: []
command: awslocal --endpoint-url http://aws:4566 s3api create-bucket --bucket product-images
depends_on:
aws:
condition: service_healthy

############## MOCK INVENTORY SERVICE ##############
mock-inventory:
image: wiremock/wiremock:3.9.2
volumes:
- ./dev/inventory-mocks:/home/wiremock
labels:
traefik.http.routers.mock-inventory.rule: Host(`inventory.localhost`)
traefik.http.services.mock-inventory.loadbalancer.server.port: 8080

############## KAFKA AND VISUALIZATION ##############
kafka:
image: apache/kafka-native:3.9.0
environment:
# Configure listeners for both docker and host communication
KAFKA_LISTENERS: CONTROLLER://localhost:9091,HOST://0.0.0.0:9092,DOCKER://0.0.0.0:9093
KAFKA_ADVERTISED_LISTENERS: HOST://localhost:9092,DOCKER://kafka:9093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,DOCKER:PLAINTEXT,HOST:PLAINTEXT

# Settings required for KRaft mode
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9091

# Listener to use for broker-to-broker communication
KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER

# Required for a single node cluster
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

kafka-topic-creator:
image: apache/kafka:3.9.0
command: /opt/kafka/bin/kafka-topics.sh --create --topic products --partitions 1 --replication-factor 1 --bootstrap-server kafka:9093
depends_on:
- kafka

kafka-ui:
image: ghcr.io/kafbat/kafka-ui:01aa8ab36387c5f1d66d098e71488bfb0eb5f39c
environment:
DYNAMIC_CONFIG_ENABLED: 'true'
KAFKA_CLUSTERS_0_NAME: local
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9093
depends_on:
- kafka
labels:
traefik.http.routers.kafka-ui.rule: Host(`kafka.localhost`)
traefik.http.services.kafka-ui.loadbalancer.server.port: 8080

0 comments on commit a5c562e

Please sign in to comment.