From f1ca3a4bfd18f72c33d782f10bc46df40fc8c4a0 Mon Sep 17 00:00:00 2001 From: elisangeladias Date: Fri, 28 Nov 2025 13:38:08 -0300 Subject: [PATCH] =?UTF-8?q?Submiss=C3=A3o=20Docker=20Compose=20-=20Elis?= =?UTF-8?q?=C3=A2ngela=20Aparecida=20Dias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- participantes/elisangeladias/Dockerfile-api01 | 8 ++ participantes/elisangeladias/Dockerfile-api02 | 8 ++ participantes/elisangeladias/README.md | 28 +++++++ .../elisangeladias/application.properties | 16 ++++ .../elisangeladias/docker-compose.yml | 78 +++++++++++++++++++ participantes/elisangeladias/init.sql | 38 +++++++++ participantes/elisangeladias/nginx.conf | 36 +++++++++ 7 files changed, 212 insertions(+) create mode 100644 participantes/elisangeladias/Dockerfile-api01 create mode 100644 participantes/elisangeladias/Dockerfile-api02 create mode 100644 participantes/elisangeladias/README.md create mode 100644 participantes/elisangeladias/application.properties create mode 100644 participantes/elisangeladias/docker-compose.yml create mode 100644 participantes/elisangeladias/init.sql create mode 100644 participantes/elisangeladias/nginx.conf diff --git a/participantes/elisangeladias/Dockerfile-api01 b/participantes/elisangeladias/Dockerfile-api01 new file mode 100644 index 0000000..d16db2c --- /dev/null +++ b/participantes/elisangeladias/Dockerfile-api01 @@ -0,0 +1,8 @@ +# Dockerfile-api01 +FROM eclipse-temurin:17-jdk-jammy + +WORKDIR /app +COPY build/libs/sizebay-0.0.1-SNAPSHOT.jar app.jar + +EXPOSE 9999 +ENTRYPOINT ["java", "-jar", "app.jar", "--server.port=9999"] diff --git a/participantes/elisangeladias/Dockerfile-api02 b/participantes/elisangeladias/Dockerfile-api02 new file mode 100644 index 0000000..d16db2c --- /dev/null +++ b/participantes/elisangeladias/Dockerfile-api02 @@ -0,0 +1,8 @@ +# Dockerfile-api01 +FROM eclipse-temurin:17-jdk-jammy + +WORKDIR /app +COPY build/libs/sizebay-0.0.1-SNAPSHOT.jar app.jar + +EXPOSE 9999 +ENTRYPOINT ["java", "-jar", "app.jar", "--server.port=9999"] diff --git a/participantes/elisangeladias/README.md b/participantes/elisangeladias/README.md new file mode 100644 index 0000000..699d38e --- /dev/null +++ b/participantes/elisangeladias/README.md @@ -0,0 +1,28 @@ +# Submissão — Teste Backend Sizebay + +**Nome:** +Elisângela Aparecida Dias + +**Tecnologias utilizadas:** +- Java 17 +- Spring Boot +- Docker / Docker Compose +- NGINX +- Gatling (para testes locais) + +**Repositório do projeto :** +👉 https://github.com/elisangeladias/test-backend-sizebay + +> **Importante:** As imagens Docker das APIs estão publicamente disponíveis no Docker Hub: +> - API01: `elisd2604/api01:latest` +> - API02: `elisd2604/api02:latest` + +--- + +## Como executar + +Clone este repositório: + +```bash +git clone https://github.com/sizebay/test-backend.git +cd participantes/elisangela-dias diff --git a/participantes/elisangeladias/application.properties b/participantes/elisangeladias/application.properties new file mode 100644 index 0000000..0ecf7aa --- /dev/null +++ b/participantes/elisangeladias/application.properties @@ -0,0 +1,16 @@ +spring.application.name=sizebay + +spring.datasource.url=jdbc:postgresql://localhost:5432/teste_elis_db +spring.datasource.username=postgres +spring.datasource.password=1234 + +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect + +spring.jackson.time-zone=UTC +spring.jackson.date-format=yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z' + + + diff --git a/participantes/elisangeladias/docker-compose.yml b/participantes/elisangeladias/docker-compose.yml new file mode 100644 index 0000000..55b727d --- /dev/null +++ b/participantes/elisangeladias/docker-compose.yml @@ -0,0 +1,78 @@ +version: '3.9' + +services: + + # Nginx + nginx: + image: nginx:latest + container_name: nginx + ports: + - "9999:9999" # porta acesso extero + depends_on: + - api01 + - api02 + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf:ro + deploy: + resources: + limits: + cpus: "0.17" + memory: "10MB" + + # Bd PostgreSQL + db: + image: postgres:18-alpine + container_name: db + environment: + POSTGRES_DB: teste_elis_db + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 1234 + ports: + - "5432:5432" + volumes: + - db_data:/var/lib/postgresql/data + - ./db/init.sql:/docker-entrypoint-initdb.d/init.sql:ro + deploy: + resources: + limits: + cpus: "0.23" + memory: "140MB" + + # API01 imagem pública no Docker Hub + api01: + image: elisd2604/api01:latest + container_name: api01 + depends_on: + - db + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/teste_elis_db + SPRING_DATASOURCE_USERNAME: postgres + SPRING_DATASOURCE_PASSWORD: 1234 + expose: + - "9999" # acessível via rede Docker + deploy: + resources: + limits: + cpus: "0.55" + memory: "200MB" + + # API02 imagem pública no Docker Hub + api02: + image: elisd2604/api02:latest + container_name: api02 + depends_on: + - db + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/teste_elis_db + SPRING_DATASOURCE_USERNAME: postgres + SPRING_DATASOURCE_PASSWORD: 1234 + expose: + - "9999" + deploy: + resources: + limits: + cpus: "0.55" + memory: "200MB" + +volumes: + db_data: diff --git a/participantes/elisangeladias/init.sql b/participantes/elisangeladias/init.sql new file mode 100644 index 0000000..40c2d7f --- /dev/null +++ b/participantes/elisangeladias/init.sql @@ -0,0 +1,38 @@ +-- apagar tabelas antigas se existirem +DROP TABLE IF EXISTS transacoes; +DROP TABLE IF EXISTS clientes; + +-- criar tabelas +CREATE TABLE clientes ( + id SERIAL PRIMARY KEY, + limite INTEGER NOT NULL, + saldo INTEGER NOT NULL +); + +CREATE TABLE transacoes ( + id SERIAL PRIMARY KEY, + cliente_id INTEGER NOT NULL, + valor INTEGER NOT NULL, + tipo CHAR(1) NOT NULL, + descricao VARCHAR(10), + realizada_em TIMESTAMP NOT NULL, + FOREIGN KEY (cliente_id) REFERENCES clientes(id) +); + +-- inserir 5 clientes +INSERT INTO clientes (id, limite, saldo) VALUES + (1, 100000, 0), + (2, 80000, 0), + (3, 1000000, 0), + (4, 10000000, 0), + (5, 500000, 0); + +-- inserir 20 transações aleatórias para o cliente 1 +INSERT INTO transacoes (cliente_id, valor, tipo, descricao, realizada_em) +SELECT + 1, + (random() * 500)::int + 1, + CASE WHEN random() > 0.5 THEN 'c' ELSE 'd' END, + 'mock', + NOW() - (random() * interval '10 days') +FROM generate_series(1, 20); diff --git a/participantes/elisangeladias/nginx.conf b/participantes/elisangeladias/nginx.conf new file mode 100644 index 0000000..bb50fd7 --- /dev/null +++ b/participantes/elisangeladias/nginx.conf @@ -0,0 +1,36 @@ +worker_processes 1; + +events { worker_connections 1024; } + +http { + # NGINX faz round-robin por padrão + upstream backend { + server api01:9999; + server api02:9999; + } + + server { + listen 9999; + + # Passa tudo (/) para o upstream + location / { + proxy_pass http://backend; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # timeout + proxy_connect_timeout 5s; + proxy_send_timeout 30s; + proxy_read_timeout 30s; + } + + + location /_nginx_health { + return 200 'OK'; + add_header Content-Type text/plain; + } + } +}