Skip to content

Commit

Permalink
Merge pull request #366 from LerianStudio/feature/MIDAZ-255
Browse files Browse the repository at this point in the history
Feature/MIDAZ-255
  • Loading branch information
ClaraTersi authored Dec 6, 2024
2 parents f64ea93 + eb8f647 commit 0629b73
Show file tree
Hide file tree
Showing 55 changed files with 3,149 additions and 147 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [ ] Ledger
- [ ] Mdz
- [ ] Transaction
- [ ] Audit
- [ ] Pipeline
- [ ] Documentation

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/midaz-update-repos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
cp midaz/components/ledger/api/swagger.json LerianStudio.github.io/ledger/
cp midaz/components/audit/api/swagger.json LerianStudio.github.io/audit/
cp midaz/components/ledger/api/swagger.json LerianStudio.github.io/ledger/
cp midaz/components/transaction/api/swagger.json LerianStudio.github.io/transaction/
- name: Commit and Push Swagger to Git Page
Expand All @@ -132,6 +134,9 @@ jobs:
git remote set-url origin https://${{ secrets.MANAGE_TOKEN }}@github.com/LerianStudio/LerianStudio.github.io.git
git add audit
git commit -S -m "Update Swagger.json from Repo Audit"
git add ledger
git commit -S -m "Update Swagger.json from Repo Ledger"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/update-env-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ jobs:
echo "LEDGER version: $VERSION"
echo "::set-output name=version::$VERSION"
- name: Update AUDIT Env
if: steps.latest_release.outputs.tag != steps.env_release.outputs.version
run: |
sed -i "s/^VERSION=.*/VERSION=${{ steps.latest_release.outputs.tag }}/" ./components/audit/.env.example
- name: Update LEDGER Env
if: steps.latest_release.outputs.tag != steps.env_release.outputs.version
run: |
Expand Down
30 changes: 20 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ INFRA_DIR := ./components/infra
LEDGER_DIR := ./components/ledger
TRANSACTION_DIR := ./components/transaction
MDZ_DIR := ./components/mdz
AUDIT_DIR := ./components/audit

.PHONY: help test cover lint format check-logs check-tests \
setup-git-hooks check-hooks goreleaser tidy sec set-env up auth infra ledger \
transaction all-services
transaction audit all-services

BLUE := \033[36m
NC := \033[0m
Expand Down Expand Up @@ -46,6 +47,7 @@ help:
@echo " make infra Run a command inside the infra app in the components directory to see available commands."
@echo " make ledger Run a command inside the ledger app in the components directory to see available commands."
@echo " make transaction Run a command inside the transaction app in the components directory to see available commands."
@echo " make audit Run a command inside the audit app in the components directory to see available commands."
@echo " make set-env Run a command to copy all .env.example to .env into respective folders."
@echo " make all-services Run a command to all services passing any individual container command."
@echo " make generate-docs-all Run a command to inside the ledger and transaction app to generate swagger docs."
Expand All @@ -56,6 +58,7 @@ help:
@echo " make infra COMMAND=<cmd> - Run command in infra service"
@echo " make ledger COMMAND=<cmd> - Run command in ledger service"
@echo " make transaction COMMAND=<cmd> - Run command in transaction service"
@echo " make audit COMMAND=<cmd> - Run command in audit service"
@echo " make all-services COMMAND=<cmd> - Run command across all services"
@echo ""
@echo "$(BOLD)Development Commands:$(NC)"
Expand All @@ -70,6 +73,15 @@ test:
fi
go test -v ./... ./...

cover:
@echo -e "$(BLUE)Generating test coverage...$(NC)"
@if ! command -v go >/dev/null 2>&1; then \
echo "$(RED)Error: go is not installed$(NC)"; \
exit 1; \
fi
@sh ./scripts/coverage.sh
@go tool cover -html=coverage.out -o coverage.html

lint:
@echo "$(BLUE)Running linter and performance checks...$(NC)"
./make.sh "lint"
Expand Down Expand Up @@ -110,6 +122,7 @@ set-env:
cp -r $(LEDGER_DIR)/.env.example $(LEDGER_DIR)/.env
cp -r $(TRANSACTION_DIR)/.env.example $(TRANSACTION_DIR)/.env
cp -r $(MDZ_DIR)/.env.example $(MDZ_DIR)/.env
cp -r $(AUDIT_DIR)/.env.example $(AUDIT_DIR)/.env
@echo "$(BLUE)Environment files created successfully$(NC)"

up:
Expand All @@ -136,6 +149,10 @@ transaction:
@echo "$(BLUE)Executing command in transaction service...$(NC)"
$(MAKE) -C $(TRANSACTION_DIR) $(COMMAND)

audit:
@echo "$(BLUE)Executing command in audit service...$(NC)"
$(MAKE) -C $(AUDIT_DIR) $(COMMAND)

all-services:
@echo "$(BLUE)Executing command across all services...$(NC)"
$(MAKE) -C $(AUTH_DIR) $(COMMAND) && \
Expand All @@ -154,15 +171,8 @@ tidy:
@echo "$(BLUE)Running go mod tidy...$(NC)"
go mod tidy

cover:
@echo -e "$(BLUE)Generating test coverage...$(NC)"
@if ! command -v go >/dev/null 2>&1; then \
echo "$(RED)Error: go is not installed$(NC)"; \
exit 1; \
fi
@sh ./scripts/coverage.sh

generate-docs-all:
@echo "$(BLUE)Executing command to generate swagger...$(NC)"
$(MAKE) -C $(LEDGER_DIR) generate-docs && \
$(MAKE) -C $(TRANSACTION_DIR) generate-docs
$(MAKE) -C $(TRANSACTION_DIR) generate-docs && \
$(MAKE) -C $(AUDIT_DIR) generate-docs
65 changes: 65 additions & 0 deletions components/audit/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# DEFAULT local
# ENV_NAME=production

# APP
VERSION=v1.31.0
SERVER_PORT=3005
SERVER_ADDRESS=:${SERVER_PORT}

# LOG LEVEL
LOG_LEVEL=debug

# MONGO DB
MONGO_HOST=midaz-mongodb
MONGO_NAME=audit
MONGO_USER=midaz
MONGO_PASSWORD=lerian
MONGO_PORT=5703

# CASDOOR
CASDOOR_PORT=8080
CASDOOR_ADDRESS=http://midaz-casdoor:${CASDOOR_PORT}
CASDOOR_CLIENT_ID=9670e0ca55a29a466d31
CASDOOR_CLIENT_SECRET=dd03f916cacf4a98c6a413d9c38ba102dce436a9
CASDOOR_ORGANIZATION_NAME=lerian
CASDOOR_APPLICATION_NAME=app-midaz
CASDOOR_MODEL_NAME=api-model
CASDOOR_JWK_ADDRESS=${CASDOOR_ADDRESS}/.well-known/jwks

# OPEN TELEMETRY
OTEL_RESOURCE_SERVICE_NAME=audit
OTEL_LIBRARY_NAME=github.com/LerianStudio/midaz/components/audit
OTEL_RESOURCE_SERVICE_VERSION=${VERSION}
OTEL_RESOURCE_DEPLOYMENT_ENVIRONMENT=${ENV_NAME}
OTEL_EXPORTER_OTLP_ENDPOINT_PORT=4317
OTEL_EXPORTER_OTLP_ENDPOINT=midaz-otel-lgtm:${OTEL_EXPORTER_OTLP_ENDPOINT_PORT}

# RABBITMQ
RABBITMQ_HOST=midaz-rabbitmq
RABBITMQ_PORT_HOST=3003
RABBITMQ_PORT_AMPQ=3004
RABBITMQ_DEFAULT_USER=audit
RABBITMQ_DEFAULT_PASS=lerian
RABBITMQ_QUEUE=audit_queue

# TRILLIAN
TRILLIAN_DATABASE_NAME=audit-db
TRILLIAN_DATABASE_USER=midaz
TRILLIAN_DATABASE_PASSWORD=lerian
TRILLIAN_DATABASE_ROOT_PASSWORD=lerian
TRILLIAN_DATABASE_PORT=5705
TRILLIAN_GRPC_PORT=8082
TRILLIAN_HTTP_PORT=8083
TRILLIAN_SIGNER_PORT=8084
TRILLIAN_GRPC_ADDRESS=midaz-audit-server:${TRILLIAN_GRPC_PORT}
TRILLIAN_HTTP_ADDRESS=http://midaz-audit-server:${TRILLIAN_HTTP_PORT}

# SWAGGER
SWAGGER_TITLE=Audit API
SWAGGER_DESCRIPTION=Documentation for the Midaz Audit API
SWAGGER_VERSION=${VERSION}
SWAGGER_HOST=${SERVER_ADDRESS}
SWAGGER_BASE_PATH=/
SWAGGER_SCHEMES=http
SWAGGER_LEFT_DELIMITER={{
SWAGGER_RIGHT_DELIMITER=}}
15 changes: 15 additions & 0 deletions components/audit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.23-alpine AS builder

WORKDIR /audit-app

COPY . .

RUN CGO_ENABLE=0 GOOS=linux go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o /app components/audit/cmd/app/main.go

FROM alpine:latest

COPY --from=builder /app /app

EXPOSE 3005

ENTRYPOINT ["/app"]
69 changes: 69 additions & 0 deletions components/audit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
service_name := audit-service
bin_dir := ./.bin
artifacts_dir := ./artifacts

$(shell mkdir -p $(artifacts_dir))

.PHONY: info gen run test cover-html tidy help build up start down destroy stop restart logs logs-api ps generate-docs

# Display available commands
info:
@echo " "
@echo " "
@echo "To run a specific command inside the auth container using make, you can execute: "
@echo " "
@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=\"generate-docs\" Generates Swagger API documentation using swag."
@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=\"logs-api\" Shows the last 100 lines of logs and follows live log output for the auth service defined in docker-compose.yml."
@echo " COMMAND=\"ps\" Lists the status of containers defined in docker-compose.yml."

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

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

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

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

destroy:
@docker-compose -f docker-compose.yml down -v $(c)

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

restart:
docker-compose -f docker-compose.yml down $(c) && \
docker-compose -f docker-compose.yml up -d $(c)

logs:
@docker-compose -f docker-compose.yml logs --tail=100 -f $(c)

logs-api:
@docker-compose -f docker-compose.yml logs --tail=100 -f auth

ps:
@docker-compose -f docker-compose.yml ps

generate-docs:
@swag init -g ../../../cmd/app/main.go -d ./internal/adapters/http -o ./api --parseDependency --parseInternal
Loading

0 comments on commit 0629b73

Please sign in to comment.