Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions VemProFutApi/Docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,62 @@
services:
# Serviço do Banco de Dados MySQL
db:
image: mysql:8.0
image: mysql:8.0.32
container_name: vemprofut-db
restart: always
ports:
- "3306:3306"
- "3307:3306"
env_file:
- .env
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
volumes:
- vemprofut-db-data:/var/lib/mysql
- ./mysql-init:/docker-entrypoint-initdb.d # criar o usuario automaticamente dentro do container MySQL

# 👇 Healthcheck para garantir que o MySQL está pronto
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h localhost -uroot -p$MYSQL_ROOT_PASSWORD"]
interval: 10s
timeout: 5s
retries: 15
start_period: 30s

# Serviço da API VemProFut
api:
build: .
container_name: vemprofut-api
env_file:
- .env
restart: on-failure
depends_on:
db:
condition: service_healthy
ports:
- "8080:8080"
depends_on:
- db
environment:
SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL}
SPRING_DATASOURCE_USERNAME: ${MYSQL_USER}
SPRING_DATASOURCE_PASSWORD: ${MYSQL_PASSWORD}
SPRING_PROFILES_ACTIVE: prod

# Conexão com MySQL com URL do banco dentro da rede Docker
SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${MYSQL_ROOT_PASSWORD}
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/${MYSQL_DATABASE}?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC&connectTimeout=30000&socketTimeout=60000

# Flyway - tenta reconectar várias vezes enquanto MySQL inicializa
SPRING_FLYWAY_CONNECT_RETRIES: 10
SPRING_FLYWAY_CONNECT_RETRIES_INTERVAL: 5s

# Auth0 - Dessa forma, o Spring vai ler direto do ambiente, sem precisar de '.properties' para mapear
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_AUTH0_CLIENT_ID: ${AUTH0_CLIENT_ID}
SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_AUTH0_CLIENT_SECRET: ${AUTH0_CLIENT_SECRET}
SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_AUTH0_ISSUER_URI: ${AUTH0_ISSUER}
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: ${AUTH0_ISSUER}

# Forca Spring Boot a ouvir em todas interfaces (necessario para Docker)
SERVER_ADDRESS: 0.0.0.0
SERVER_PORT: 8080
SERVER_SERVLET_SESSION_COOKIE_SECURE: false

volumes:
vemprofut-db-data: # garante que os dados do banco de dados não sejam perdidos quando o contêiner do MySQL for reiniciado.
vemprofut-db-data: # garante que os dados do DB não sejam perdidos quando o contêiner do MySQL for reiniciado.
8 changes: 7 additions & 1 deletion VemProFutApi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ===================== Builder (Maven + JDK 21) ========================
# Utilizei uma abordagem de múltiplos estágios (multi-stage build), que gera uma imagem final muito menor e mais segura.
# Estágio 1: Build da aplicação com Maven e JDK 21
FROM maven:3.9-eclipse-temurin-21 AS builder
Expand All @@ -11,11 +12,16 @@ RUN mvn dependency:go-offline

# Copia o restante do código-fonte e constrói o JAR
COPY src ./src
RUN mvn clean install -DskipTests
RUN mvn clean package -DskipTests
#package mais adequado que install quando construindo imagem...


# ===================== Runtime (JRE 21) ==========================
# Estágio 2: Criação da imagem final com JRE
FROM eclipse-temurin:21-jre-jammy
WORKDIR /app

COPY --from=builder /app/target/VemProFut-0.0.1-SNAPSHOT.jar app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
35 changes: 35 additions & 0 deletions VemProFutApi/excludeFilter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- arquivo para spotbugs ignorar algumas pastas-->
<FindBugsFilter>
<!-- Ignorar DTOs -->
<Match>
<Package name="~br.com.vemprofut.controllers.request.*"/>
</Match>
<Match>
<Package name="~br.com.vemprofut.controllers.response.*"/>
</Match>
<Match>
<Package name="~br.com.vemprofut.models.DTOs.*"/>
</Match>

<!-- Ignorar Models -->
<Match>
<Package name="~br.com.vemprofut.models.*"/>
</Match>

<!-- Ignorar Mappers gerados pelo MapStruct -->
<Match>
<Package name="~br.com.vemprofut.mappers.*"/>
</Match>

<!-- Não é bug real em injeção Spring -->
<Match>
<Bug pattern="EI_EXPOSE_REP2"/>
<Class name="~br.com.vemprofut.controllers.*"/>
</Match>

<Match>
<Bug pattern="EI_EXPOSE_REP2"/>
<Class name="~br.com.vemprofut.configs.*"/>
</Match>
</FindBugsFilter>
8 changes: 8 additions & 0 deletions VemProFutApi/mysql-init/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Cria o usuário
CREATE USER IF NOT EXISTS 'vpfadm'@'%' IDENTIFIED BY 'root123';

-- Dá permissões no banco
GRANT ALL PRIVILEGES ON vemprofutdb.* TO 'vpfadm'@'%';

-- Atualiza permissões
FLUSH PRIVILEGES;
41 changes: 32 additions & 9 deletions VemProFutApi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>br.com.vemprofut</groupId>
Expand All @@ -29,6 +29,7 @@
<properties>
<java.version>21</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -46,6 +47,7 @@
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.32</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -83,6 +85,7 @@
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.20.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -118,11 +121,25 @@
<version>10.6</version>
</dependency>

<!-- Se for enviar e-mail -->
<dependency>
<!-- Se for enviar e-mail( -->
<!--dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency-->

<!--Testes -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -180,24 +197,30 @@
</executions>
</plugin>

<!-- PMD Lint -->
<!-- SpotBugs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.0</version>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.3.0</version>
<configuration>
<printFailingErrors>true</printFailingErrors>
<effort>Max</effort> <!-- nível de profundidade da análise -->
<threshold>Low</threshold> <!-- severidade mínima reportada -->
<xmlOutput>true</xmlOutput> <!-- gera XML -->
<htmlOutput>true</htmlOutput> <!-- gera HTML -->
<outputDirectory>${project.build.directory}/spotbugs</outputDirectory>
<excludeFilterFile>${project.basedir}/excludeFilter.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
<goal>spotbugs</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
Expand All @@ -25,7 +24,7 @@ public class OAuth2LoginSuccessHandler implements AuthenticationSuccessHandler {
// Agora vamos interceptar o retorno do Auth0...

private final PeladeiroRepository peladeiroRepository;
private final OAuth2AuthorizedClientService authorizedClientService;
// private final OAuth2AuthorizedClientService authorizedClientService;
private final IHistoricoPeladeiroService historicoPeladeiroService;
private final IHistoricoPeladeiroMapper historicoPeladeiroMapper;

Expand Down
Loading