Skip to content

Commit

Permalink
docker: add compose cheat-sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
l-lin committed Jun 26, 2024
1 parent 7024385 commit 0612bfa
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
50 changes: 50 additions & 0 deletions docker/compose/kafka/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
services:
# ZOOKEEPER ------------------------------------------------------------------------------------
zk:
image: confluentinc/cp-zookeeper:7.4.1
container_name: zk
ports:
- 2181:2181
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
healthcheck:
test: ["CMD", "echo", "healthy"]
start_period: 5s
interval: 5s

# KAFKA ----------------------------------------------------------------------------------------
kafka:
image: confluentinc/cp-kafka:7.4.1
container_name: kafka
depends_on:
zk:
condition: service_started
ports:
- 9092:9092
- 29092:29092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zk:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
healthcheck:
test: "if [[ $(kafka-topics --bootstrap-server localhost:9092 --list | sed '/^[[:blank:]]*$/ d' | wc -l) == 0 ]]; then crash_on_purpose; fi"
start_period: 15s
interval: 20s

kafka-setup:
image: confluentinc/cp-kafka:7.4.1
container_name: kafka-setup
depends_on:
kafka:
condition: service_started
command: "bash -c 'echo Waiting for Kafka to be ready... && \
cub kafka-ready -b kafka:29092 1 20 && \
kafka-topics --create --if-not-exists --bootstrap-server kafka:29092 --partitions 1 --replication-factor 1 --topic my-awesome-topic'"
environment:
# The following settings are listed here only to satisfy the image's requirements.
# We override the image's `command` anyways, hence this container will not start a broker.
KAFKA_BROKER_ID: ignored
KAFKA_ZOOKEEPER_CONNECT: ignored
15 changes: 15 additions & 0 deletions docker/compose/localstack/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
localstack:
container_name: localstack
image: localstack/localstack:3.0.2
environment:
# https://docs.localstack.cloud/references/configuration/
SERVICES: s3, sqs, dynamodb
DEBUG: 1
ports:
- 4566:4566
- 4510-4559:4510-4559
volumes:
# script to be executed when localstack is ready, see https://docs.localstack.cloud/references/init-hooks/
- "./ready.d:/etc/localstack/init/ready.d:ro"
- /var/run/docker.sock:/var/run/docker.sock
12 changes: 12 additions & 0 deletions docker/compose/localstack/ready.d/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

awslocal s3 mb s3://my-bucket

awslocal sqs create-queue --queue-name my-sqs-queue

awslocal dynamodb create-table \
--table-name my-dynamodb-table \
--key-schema AttributeName=id,KeyType=HASH \
--attribute-definitions AttributeName=id,AttributeType=S \
--billing-mode PAY_PER_REQUEST

14 changes: 14 additions & 0 deletions docker/compose/postgres/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
db:
image: postgres:13-alpine
container_name: my-db
volumes:
- ./initdb.d:/docker-entrypoint-initdb.d
healthcheck:
test: psql postgres --command "SELECT 1" -U postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: my_db
ports:
- 5432:5432
1 change: 1 addition & 0 deletions docker/compose/postgres/initdb.d/install-extensions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
9 changes: 9 additions & 0 deletions docker/compose/redis/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
redis:
image: redis:7.2.0-alpine
container_name: redis
ports:
- "6379:6379"
volumes:
- ./redis.conf:/usr/local/etc/redis/redis.conf:ro
command: "redis-server /usr/local/etc/redis/redis.conf"
1 change: 1 addition & 0 deletions docker/compose/redis/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
user my-username >my-password on ~* -@all +get +set +ttl +scan

0 comments on commit 0612bfa

Please sign in to comment.