From ed247c423e4dea88fed9f3be3f2eaea00b011918 Mon Sep 17 00:00:00 2001 From: Artur Oliveira Date: Tue, 16 Dec 2025 17:37:41 -0300 Subject: [PATCH] chore(devops): adicionar suporte a docker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - adiciona dockerfiles e docker-compose para backend, frontend e postgres - atualiza README com instruções e libera CORS para porta 4173 --- README.md | 13 +++++ backend/.dockerignore | 6 +++ backend/Dockerfile | 20 ++++++++ .../config/security/SecurityConfig.java | 4 +- docker-compose.yml | 50 +++++++++++++++++++ frontend/.dockerignore | 6 +++ frontend/Dockerfile | 22 ++++++++ 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 backend/.dockerignore create mode 100644 backend/Dockerfile create mode 100644 docker-compose.yml create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile diff --git a/README.md b/README.md index 78c9062..89ee0c8 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,19 @@ Plataforma interna para catalogar servidores corporativos e facilitar consultas 3. **Testar via Postman** Importe `postman_collection.json`. Rode "Auth / Login" para setar cookies e seguir para os demais endpoints. +## Executar com Docker +1. Crie um `.env` na pasta `frontend/` se precisar sobrescrever variáveis (opcional). +2. Construa e suba tudo (Postgres + backend + frontend): + ```bash + docker compose up --build + ``` +3. Endpoints expostos: + - API: `http://localhost:8080` + - Swagger UI: `http://localhost:8080/swagger-ui.html` + - Frontend: `http://localhost:4173` + +Variáveis sensíveis (ex.: `JWT_SECRET`, credenciais do banco) podem ser ajustadas diretamente no `docker-compose.yml` ou via arquivos `.env`. + ## Documentação específica - Backend: `backend/README.md` - Frontend: `frontned/README.md` diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..cf83ae1 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,6 @@ +build +.gradle +.idea +*.iml +*.log +HELP.md diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..46ad0b9 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,20 @@ +FROM gradle:8.10.2-jdk21 AS builder +WORKDIR /workspace + +COPY gradlew . +COPY gradle gradle +COPY build.gradle settings.gradle ./ +COPY src src + +RUN chmod +x gradlew && ./gradlew bootJar --no-daemon + +FROM eclipse-temurin:21-jre-alpine +WORKDIR /app + +ENV JAVA_OPTS="" + +COPY --from=builder /workspace/build/libs/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"] diff --git a/backend/src/main/java/com/hitcommunications/servermanager/config/security/SecurityConfig.java b/backend/src/main/java/com/hitcommunications/servermanager/config/security/SecurityConfig.java index 5bc0d35..be0d8a9 100644 --- a/backend/src/main/java/com/hitcommunications/servermanager/config/security/SecurityConfig.java +++ b/backend/src/main/java/com/hitcommunications/servermanager/config/security/SecurityConfig.java @@ -80,7 +80,9 @@ public class SecurityConfig { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(List.of( "http://localhost:5173", - "http://127.0.0.1:5173" + "http://127.0.0.1:5173", + "http://localhost:4173", + "http://127.0.0.1:4173" )); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(List.of("*")); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f963132 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +services: + db: + image: postgres:15-alpine + container_name: servers-db + restart: unless-stopped + environment: + POSTGRES_DB: servermanager + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + ports: + - "5433:5432" + volumes: + - db-data:/var/lib/postgresql/data + + backend: + build: + context: ./backend + dockerfile: Dockerfile + container_name: servers-backend + depends_on: + - db + environment: + DB_HOST: db + DB_PORT: 5432 + DB_NAME: servermanager + DB_SCHEMA: server-manager + DB_USER: postgres + DB_PASSWD: postgres + JWT_SECRET: change-me-change-me-change-me-change-me-change-me + ports: + - "8081:8080" + restart: unless-stopped + + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + args: + VITE_BACKEND_URL: http://localhost:8081 + container_name: servers-frontend + depends_on: + - backend + environment: + PORT: 4173 + ports: + - "4173:4173" + restart: unless-stopped + +volumes: + db-data: diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..681f1c3 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,6 @@ +node_modules +dist +.turbo +.vite +.idea +*.log diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..c3ba6f5 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,22 @@ +FROM node:20-alpine AS builder +WORKDIR /app + +COPY package.json yarn.lock ./ +RUN corepack enable && yarn install --frozen-lockfile + +COPY . . +ARG VITE_BACKEND_URL=http://localhost:8080 +ENV VITE_BACKEND_URL=$VITE_BACKEND_URL +RUN yarn build + +FROM node:20-alpine +WORKDIR /app + +RUN npm install -g serve +ENV PORT=4173 + +COPY --from=builder /app/dist ./dist + +EXPOSE 4173 + +CMD ["sh", "-c", "serve -s dist -l ${PORT}"]