Skip to content

Commit

Permalink
Merge pull request #77 from LerianStudio/develop
Browse files Browse the repository at this point in the history
DTM-[MZ-511]
  • Loading branch information
MartinezAvellan authored Sep 27, 2024
2 parents 0bb8e71 + 84a6067 commit bac264c
Show file tree
Hide file tree
Showing 15 changed files with 1,850 additions and 519 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## [1.12.0-beta.1](https://github.com/LerianStudio/midaz/compare/v1.11.1-beta.2...v1.12.0-beta.1) (2024-09-27)


### Features

* create auth postman collections and environments ([206ffb1](https://github.com/LerianStudio/midaz/commit/206ffb14845f78a98180d72eafc02c4b281b43a1))
* create casdoor base infrastructure ✨ ([1d10d20](https://github.com/LerianStudio/midaz/commit/1d10d20a52df2d4f7e95b752eecd513c56565dca))


### Bug Fixes

* update postman and environments :bug: ([3f4d97e](https://github.com/LerianStudio/midaz/commit/3f4d97e7d3692ad30d8f0fe2dda55ddb44fd5e8b))

## [1.11.1-beta.2](https://github.com/LerianStudio/midaz/compare/v1.11.1-beta.1...v1.11.1-beta.2) (2024-09-26)

## [1.11.1-beta.1](https://github.com/LerianStudio/midaz/compare/v1.11.0...v1.11.1-beta.1) (2024-09-26)

## [1.11.0](https://github.com/LerianStudio/midaz/compare/v1.10.1...v1.11.0) (2024-09-23)

## [1.11.0-beta.1](https://github.com/LerianStudio/midaz/compare/v1.10.1...v1.11.0-beta.1) (2024-09-23)
Expand Down
72 changes: 45 additions & 27 deletions components/auth/.env.example
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
# AUTH
# Kratos
#Env
ENV_NAME=production
KRATOS_DB_USER=kratos
KRATOS_DB_PASSWORD=kratos
KRATOS_DB_NAME=kratos
KRATOS_DB_PORT=5432
KRATOS_ADMIN_URL=http://kratos:4434/
KRATOS_PUBLIC_URL=http://kratos:4433/
# generate a random secret to replace this example
KRATOS_COOKIE_SECRET= #< to create a secreat you may run this command to generate a new secret: pwgen -s -n 30 7 >
# generate a random secret to replace this example
KRATOS_CIPHER_SECRET= #< to create a secreat you may run this command to generate a new secret: pwgen -s -n 30 7 >
SMTP_USER=test
SMTP_PASSWORD=test
SMTP_ADDRESS=mailslurper
SMTP_PORT=1025
# Hydra
HYDRA_ADDRESS=http://hydra:4445/
HYDRA_DB_USER=hydra
HYDRA_DB_PASSWORD=hydra
HYDRA_DB_NAME=hydra
HYDRA_DB_PORT=5432
# generate a random secret to replace this example
HYDRA_SYSTEM_SECRET= #< to create a secreat you may run this command to generate a new secret: pwgen -s -n 30 7 >
# generate a random secret to replace this example
HYDRA_COOKIE_SECRET= #< to create a secreat you may run this command to generate a new secret: pwgen -s -n 30 7 >
# generate a random secret to replace this example
HYDRA_PAIRWISE_SALT= #< to create a secreat you may run this command to generate a new secret: pwgen -s -n 30 7 >

#APP - Auth
APP_CONTEXT=/auth/v1
SERVER_PORT=3004
SERVER_ADDRESS=:${SERVER_PORT}

# Casdoor
CASDOOR_PORT=8000
CASDOOR_ADDRESS=http://localhost:${CASDOOR_PORT}/
CASDOOR_CLIENT_ID=client_id
CASDOOR_CLIENT_SECRET=client_secret
# When this environment variable is set to true, localhost will be replaced with host.docker.internal so that Casdoor can access the database. ( Ref. https://casdoor.org/docs/basic/try-with-docker/#option-3-try-with-docker-compose)
RUNNING_IN_DOCKER=true

# Casdoor DB
DB_HOST=casdoor-db
CASDOOR_DB_USER=midaz
CASDOOR_DB_NAME=casdoor
CASDOOR_DB_PASSWORD=leriand
CASDOOR_DB_PORT=5436
USER_EXECUTE_COMMAND=postgres
LOG_LEVEL=debug

appname=casdoor
httpport=8000
runmode=dev
driverName=postgres
dataSourceName="user=${CASDOOR_DB_USER} password=${CASDOOR_DB_PASSWORD} host=${DB_HOST} port=${CASDOOR_DB_PORT} sslmode=disable dbname=${CASDOOR_DB_NAME}"
dbName=${CASDOOR_DB_NAME}
showSql=false
authState="casdoor"
socks5Proxy="127.0.0.1:10808"
verificationCodeTimeout=10
## Is used to determine whether only the post method is used to add a record.
logPostOnly=true
isUsernameLowered=false
origin=
batchSize=100
enableErrorMask=false
enableGzip=true
## Limit of creation for each type of resource, -1 means no limit.
quota='{"organization": -1, "user": -1, "application": -1, "provider": -1}'
logConfig='{"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"}'
initDataFile="./init_data.json"
25 changes: 1 addition & 24 deletions components/auth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ info:
@echo "make auth COMMAND=\"any\" "
@echo " "
@echo "This command will run the specified command inside the auth container. Replace \"any\" with the desired command you want to execute. "
@echo " "
@echo "## App commands:"
@echo " "
@echo " COMMAND=\"wire\" Generates all project code to connect components using Wire."
@echo " COMMAND=\"run\" Executes the Go program in internal/main.go using .env configuration."
@echo " COMMAND=\"test\" Runs all Go tests in the project with verbose output."
@echo " COMMAND=\"cover-html\" Generates an HTML report from Go test coverage data."
@echo " COMMAND=\"tidy\" Cleans and updates Go dependencies in the go.mod file."
@echo " "
@echo "## Docker commands:"
@echo " "
Expand All @@ -39,27 +31,12 @@ info:
@echo " COMMAND=\"auth-api\" Starts an interactive Bash shell session inside the running auth container defined in docker-compose.yml."
@echo " COMMAND=\"db-shell\" Starts a PostgreSQL interactive terminal inside the auth container, logging in as the postgres user."

gen:
@go generate ./...

run:
@go run internal/main.go .env

test:
@go test -v ./...

cover-html:
@go tool cover -html=$(artifacts_dir)/coverage.out -o $(artifacts_dir)/coverage.html

tidy:
@go mod tidy

# Docker Compose Commands
build:
@docker-compose -f docker-compose.yml build $(c)

up:
@docker-compose -f docker-compose.yml up $(c)
@docker-compose -f docker-compose.yml up $(c) -d

start:
@docker-compose -f docker-compose.yml start $(c)
Expand Down
176 changes: 16 additions & 160 deletions components/auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,182 +8,38 @@ x-postgres-common:
- app-tier

services:
keto-db:
<<: *postgres-common
container_name: keto-db
ports:
- "5436:5432"
environment:
- POSTGRES_USER=${KETO_DB_USER}
- POSTGRES_PASSWORD=${KETO_DB_PASSWORD}
- POSTGRES_DB=${KETO_DB_NAME}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${KETO_DB_USER} -d ${KETO_DB_NAME}" ]
interval: 10s
timeout: 5s
retries: 5

kratos:
container_name: kratos
image: oryd/kratos:v1.1.0
casdoor:
container_name: casdoor
image: casbin/casdoor:latest
env_file:
- .env
environment:
- DSN=postgres://${KRATOS_DB_USER}:${KRATOS_DB_PASSWORD}@kratos-db:${KRATOS_DB_PORT}/${KRATOS_DB_NAME}?sslmode=disable&max_conns=20&max_idle_conns=4
- OAUTH2_PROVIDER_URL=${HYDRA_ADDRESS}
- OAUTH2_PROVIDER_OVERRIDE_RETURN_TO=true
- SECRETS_COOKIE=${KRATOS_COOKIE_SECRET}
- SECRETS_CIPHER=${KRATOS_CIPHER_SECRET}
- COURIER_SMTP_CONNECTION_URI=smtps://${SMTP_USER}:${SMTP_PASSWORD}@${SMTP_ADDRESS}:${SMTP_PORT}/?skip_ssl_verify=true
command: serve -c /etc/kratos/config/kratos.yml --dev --watch-courier
depends_on:
- kratos-db
- kratos-migrate
ports:
- '4433:4433' # public
- '4434:4434' # admin
- ${CASDOOR_PORT}:${CASDOOR_PORT}
volumes:
- type: bind
source: ../../config/auth
target: /etc/kratos/config
- type: bind
source: ../../config/identity-schemas
target: /etc/kratos/identity-schemas
networks:
- app-tier

kratos-migrate:
- ./setup/init_data.json:/init_data.json
depends_on:
- kratos-db
container_name: kratos-migrate
image: oryd/kratos:v1.1.0
env_file:
- .env
environment:
- DSN=postgres://${KRATOS_DB_USER}:${KRATOS_DB_PASSWORD}@kratos-db:${KRATOS_DB_PORT}/${KRATOS_DB_NAME}?sslmode=disable&max_conns=20&max_idle_conns=4
command: migrate sql -e --yes
casdoor-db:
condition: service_healthy
networks:
- app-tier

hydra:
container_name: hydra
image: oryd/hydra:v2.2.0
env_file:
- .env
environment:
- DSN=postgres://${HYDRA_DB_USER}:${HYDRA_DB_PASSWORD}@hydra-db:${HYDRA_DB_PORT}/${HYDRA_DB_NAME}?sslmode=disable&max_conns=20&max_idle_conns=4
- OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT=${HYDRA_PAIRWISE_SALT}
- URLS_IDENTITY_PROVIDER_PUBLICURL=${KRATOS_PUBLIC_URL}
- URLS_IDENTITY_PROVIDER_URL=${KRATOS_ADMIN_URL}
- SECRETS_COOKIE=${HYDRA_COOKIE_SECRET}
- SECRETS_SYSTEM=${HYDRA_SYSTEM_SECRET}
command: serve -c /etc/hydra/config/hydra.yml all --dev
depends_on:
- hydra-db
- hydra-migrate
ports:
- "4444:4444" #public port
- "4445:4445" #admin port
- "5555:5555" #hydra token user port
restart: on-failure
volumes:
- type: bind
source: ../../config/auth
target: /etc/hydra/config
networks:
- app-tier

hydra-migrate:
depends_on:
- hydra-db
- kratos-migrate
container_name: hydra-migrate
image: oryd/hydra:v2.2.0
casdoor-db:
<<: *postgres-common
container_name: casdoor-db
env_file:
- .env
environment:
- DSN=postgres://${HYDRA_DB_USER}:${HYDRA_DB_PASSWORD}@hydra-db:${HYDRA_DB_PORT}/${HYDRA_DB_NAME}?sslmode=disable&max_conns=20&max_idle_conns=4
- SECRETS_SYSTEM=${HYDRA_SYSTEM_SECRET}
restart: on-failure
command: migrate sql -e --yes
networks:
- app-tier

keto:
container_name: keto
image: oryd/keto:v0.11.1-alpha.0
links:
- keto-db:keto-db
command: serve -c /etc/keto/config/keto.yml all
volumes:
- type: bind
source: ../../config/auth
target: /etc/keto/config
ports:
- "4466:4466"
- "4467:4467"
depends_on:
- keto-migrate
environment:
- DSN=postgres://${KETO_DB_USER}:${KETO_DB_PASSWORD}@keto-db:${KETO_DB_PORT}/${KETO_DB_NAME}?sslmode=disable&max_conns=20&max_idle_conns=4
restart: on-failure
networks:
- app-tier

keto-migrate:
container_name: keto-migrate
image: oryd/keto:v0.12.0-alpha.0
links:
- keto-db:keto-db
volumes:
- type: bind
source: ../../config/auth
target: /home/ory
environment:
- LOG_LEVEL=debug
- DSN=postgres://${KETO_DB_USER}:${KETO_DB_PASSWORD}@keto-db:${KETO_DB_PORT}/${KETO_DB_NAME}?sslmode=disable&max_conns=20&max_idle_conns=4
command: ["migrate", "up", "-y"]
restart: on-failure
networks:
- app-tier

kratos-db:
<<: *postgres-common
container_name: kratos-db
ports:
- "5434:5432"
- ${CASDOOR_DB_PORT}:${CASDOOR_DB_PORT}
environment:
- POSTGRES_USER=${KRATOS_DB_USER}
- POSTGRES_PASSWORD=${KRATOS_DB_PASSWORD}
- POSTGRES_DB=${KRATOS_DB_NAME}
- PGPORT=${CASDOOR_DB_PORT}
- POSTGRES_USER=${CASDOOR_DB_USER}
- POSTGRES_PASSWORD=${CASDOOR_DB_PASSWORD}
- POSTGRES_DB=${CASDOOR_DB_NAME}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${KRATOS_DB_USER} -d ${KRATOS_DB_NAME}" ]
test: [ "CMD-SHELL", "pg_isready -U ${CASDOOR_DB_USER} -d ${CASDOOR_DB_NAME} -p ${CASDOOR_DB_PORT}" ]
interval: 10s
timeout: 5s
retries: 5

hydra-db:
<<: *postgres-common
container_name: hydra-db
ports:
- "5435:5432"
environment:
- POSTGRES_USER=${HYDRA_DB_USER}
- POSTGRES_PASSWORD=${HYDRA_DB_PASSWORD}
- POSTGRES_DB=${HYDRA_DB_NAME}
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${HYDRA_DB_USER} -d ${HYDRA_DB_NAME}" ]
interval: 10s
timeout: 5s
retries: 5

mailslurper:
image: oryd/mailslurper:latest-smtps
ports:
- "4436:4436"
- "4437:4437"
networks:
- app-tier

networks:
app-tier:
Loading

0 comments on commit bac264c

Please sign in to comment.