-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from LerianStudio/refactor/MZ-574
Refactor/MZ-574
- Loading branch information
Showing
20 changed files
with
363 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# INFRA | ||
|
||
# DB POSTGRESQL PRIMARY AND REPLICA | ||
DB_HOST=primary-ledger | ||
DB_USER=midaz | ||
DB_PASSWORD=lerian | ||
DB_PORT=5701 | ||
|
||
DB_REPLICA_HOST=replica-ledger | ||
DB_REPLICA_USER=midaz | ||
DB_REPLICA_PASSWORD=lerian | ||
DB_REPLICA_PORT=5702 | ||
|
||
REPLICATION_USER=replicator | ||
REPLICATION_PASSWORD=replicator_password | ||
USER_EXECUTE_COMMAND=postgres | ||
|
||
# MONGO DB | ||
MONGO_HOST=mongodb | ||
MONGO_USER=midaz | ||
MONGO_PASSWORD=lerian | ||
MONGO_PORT=5703 | ||
|
||
# REDIS | ||
REDIS_PORT=5704 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
service_name := infra-service | ||
bin_dir := ./.bin | ||
artifacts_dir := ./artifacts | ||
|
||
$(shell mkdir -p $(artifacts_dir)) | ||
|
||
.PHONY: help build up start down destroy stop restart logs logs-api ps login-timescale login-api db-shell | ||
|
||
# Display available commands | ||
info: | ||
@echo " " | ||
@echo " " | ||
@echo "To run a specific command inside the infra container using make, you can execute: " | ||
@echo " " | ||
@echo "make infra COMMAND=\"any\" " | ||
@echo " " | ||
@echo "This command will run the specified command inside the infra container. Replace \"any\" with the desired command you want to execute. " | ||
@echo " " | ||
@echo " " | ||
@echo "## Docker commands:" | ||
@echo " " | ||
@echo " COMMAND=\"build\" Builds all Docker images defined in docker-compose.yml." | ||
@echo " COMMAND=\"up\" Starts and runs all services defined in docker-compose.yml." | ||
@echo " COMMAND=\"start\" Starts existing containers defined in docker-compose.yml without creating them." | ||
@echo " COMMAND=\"stop\" Stops running containers defined in docker-compose.yml without removing them." | ||
@echo " COMMAND=\"down\" Stops and removes containers, networks, and volumes defined in docker-compose.yml." | ||
@echo " COMMAND=\"destroy\" Stops and removes containers, networks, and volumes (including named volumes) defined in docker-compose.yml." | ||
@echo " COMMAND=\"restart\" Stops and removes containers, networks, and volumes, then starts all services in detached mode." | ||
@echo " COMMAND=\"logs\" Shows the last 100 lines of logs and follows live log output for services defined in docker-compose.yml." | ||
@echo " COMMAND=\"infra-api\" Shows the last 100 lines of logs and follows live log output for the infra service defined in docker-compose.yml." | ||
@echo " COMMAND=\"ps\" Lists the status of containers defined in docker-compose.yml." | ||
@echo " COMMAND=\"db-shell\" Starts a PostgreSQL interactive terminal inside the infra container, logging in as the postgres user." | ||
|
||
|
||
# Docker Compose Commands | ||
build: | ||
@docker-compose -f docker-compose.yml build | ||
|
||
up: | ||
@docker-compose -f docker-compose.yml up -d | ||
|
||
start: | ||
@docker-compose -f docker-compose.yml start | ||
|
||
down: | ||
@docker-compose -f docker-compose.yml down | ||
|
||
destroy: | ||
@docker-compose -f docker-compose.yml down -v | ||
|
||
stop: | ||
@docker-compose -f docker-compose.yml stop | ||
|
||
restart: | ||
docker-compose -f docker-compose.yml down && \ | ||
docker-compose -f docker-compose.yml up -d | ||
|
||
logs: | ||
@docker-compose -f docker-compose.yml logs --tail=100 -f | ||
|
||
logs-api: | ||
@docker-compose -f docker-compose.yml logs --tail=100 -f infra | ||
|
||
ps: | ||
@docker-compose -f docker-compose.yml ps | ||
|
||
infra-api: | ||
@docker-compose -f docker-compose.yml exec infra /bin/bash | ||
|
||
db-shell: | ||
@docker-compose -f docker-compose.yml exec infra psql -Upostgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
x-postgres-ledger-common: | ||
&postgres-ledger-common | ||
image: postgres:16-alpine | ||
user: ${USER_EXECUTE_COMMAND} | ||
restart: always | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready -U ${DB_USER} -p ${DB_PORT}" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
networks: | ||
- infra_network | ||
|
||
x-mongodb-common: | ||
&mongodb-common | ||
image: mongo:latest | ||
restart: always | ||
healthcheck: | ||
test: echo 'db.runCommand("ping").ok' | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
networks: | ||
- infra_network | ||
|
||
x-redis-common: | ||
&redis-common | ||
image: redis:latest | ||
env_file: | ||
- .env | ||
networks: | ||
- infra_network | ||
|
||
services: | ||
mongodb: | ||
<<: *mongodb-common | ||
container_name: midaz-mongodb | ||
environment: | ||
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER} | ||
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD} | ||
command: mongod --port ${MONGO_PORT} | ||
ports: | ||
- ${MONGO_PORT}:${MONGO_PORT} | ||
volumes: | ||
- mongodb_data_container:/data/db | ||
|
||
redis: | ||
<<: *redis-common | ||
container_name: midaz-redis | ||
ports: | ||
- ${REDIS_PORT}:${REDIS_PORT} | ||
|
||
primary-ledger: | ||
<<: *postgres-ledger-common | ||
container_name: midaz-postgres-primary | ||
ports: | ||
- ${DB_PORT}:${DB_PORT} | ||
environment: | ||
PGPORT: ${DB_PORT} | ||
POSTGRES_USER: ${DB_USER} | ||
POSTGRES_PASSWORD: ${DB_PASSWORD} | ||
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5" | ||
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256" | ||
command: | | ||
postgres | ||
-c wal_level=replica | ||
-c hot_standby=on | ||
-c max_wal_senders=10 | ||
-c max_replication_slots=10 | ||
-c hot_standby_feedback=on | ||
volumes: | ||
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql | ||
|
||
replica-ledger: | ||
<<: *postgres-ledger-common | ||
container_name: midaz-postgres-replica | ||
ports: | ||
- ${DB_REPLICA_PORT}:${DB_REPLICA_PORT} | ||
environment: | ||
PGPORT: ${DB_REPLICA_PORT} | ||
PGUSER: ${REPLICATION_USER} | ||
PGPASSWORD: ${REPLICATION_PASSWORD} | ||
command: | | ||
bash -c " | ||
if [ ! -d \"/var/lib/postgresql/data\" ] || [ ! -f \"/var/lib/postgresql/data/postgresql.conf\" ]; then | ||
until pg_basebackup --pgdata=/var/lib/postgresql/data -R --slot=replication_slot --host=primary-ledger --port=${DB_PORT} | ||
do | ||
echo 'Waiting for primary-ledger to connect...' | ||
sleep 1s | ||
done | ||
echo 'Backup done..., starting replica-ledger...' | ||
chmod 0700 /var/lib/postgresql/data | ||
# Ensure the port is set to use for the replica | ||
sed -i 's/^#port.*/port = ${DB_REPLICA_PORT}/' /var/lib/postgresql/data/postgresql.conf | ||
fi | ||
exec postgres -c config_file=/var/lib/postgresql/data/postgresql.conf | ||
" | ||
healthcheck: | ||
test: [ "CMD-SHELL", "pg_isready -U ${DB_REPLICA_USER} -p ${DB_REPLICA_PORT}" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 5 | ||
depends_on: | ||
primary-ledger: | ||
condition: service_healthy | ||
|
||
volumes: | ||
mongodb_data_container: | ||
|
||
networks: | ||
infra_network: | ||
name: infra_network | ||
driver: bridge |
Oops, something went wrong.