Skip to content

Commit 3fefc55

Browse files
committed
feat:Docker
1 parent 2cf2897 commit 3fefc55

File tree

9 files changed

+219
-1
lines changed

9 files changed

+219
-1
lines changed

README.MD

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,57 @@ O sistema é composto por duas partes principais: **back-end** e **front-end**.
1919
- **`fe/`**: Contém o front-end, desenvolvido com **React**, que fornece uma interface web interativa para os usuários.
2020

2121
Cada diretório possui seu próprio arquivo `README.md`, onde você encontrará instruções para configuração e execução de suas respectivas partes.
22+
23+
## 🐳 Executando com Docker
24+
25+
O SINAPHEATMAP está totalmente configurado para execução com **Docker**, facilitando o deployment e garantindo consistência entre diferentes ambientes.
26+
27+
### Pré-requisitos
28+
29+
- [Docker](https://www.docker.com/get-started)
30+
- [Docker Compose](https://docs.docker.com/compose/install/)
31+
32+
### Configuração Rápida
33+
34+
1. **Clone o repositório:**
35+
```bash
36+
git clone https://github.com/lucas231090/sinapheatmap.git
37+
cd sinapheatmap
38+
```
39+
40+
2. **Configure as variáveis de ambiente:**
41+
```bash
42+
# Windows
43+
copy be\.env.docker.example be\.env.docker
44+
45+
# Linux/Mac
46+
cp be/.env.docker.example be/.env.docker
47+
```
48+
49+
3. **Edite o arquivo `be/.env.docker`** com suas configurações:
50+
```env
51+
PORT=3333
52+
MONGO_URL=mongodb://root:SUA_SENHA_MONGO@mongodb:27017/sinapheatmap?authSource=admin
53+
JWT_SECRET=SEU_JWT_SECRET_SUPER_SEGURO
54+
NODE_ENV=production
55+
```
56+
57+
4. **Execute o sistema:**
58+
```bash
59+
# Build e execução
60+
docker-compose up --build
61+
62+
# Ou use o script automatizado (Windows)
63+
.\deploy.ps1
64+
65+
# Ou use o script automatizado (Linux/Mac)
66+
./deploy.sh
67+
```
68+
69+
### Acessos
70+
71+
Após a execução, o sistema estará disponível em:
72+
73+
- **🌐 Frontend (Interface Web)**: http://localhost
74+
- **🔧 Backend (API)**: http://localhost:3333
75+
- **🗄️ MongoDB**: localhost:27017

be/.dockerignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
node_modules
2+
.vscode
3+
.git
4+
*.log
5+
.env
6+
.env.*
7+
.env.local
8+
.env.development.local
9+
.env.test.local
10+
.env.production.local
11+
coverage
12+
.nyc_output
13+
.DS_Store
14+
Thumbs.db
15+
uploads/*
16+
!uploads/.gitkeep
17+
logs/*
18+
!logs/.gitkeep

be/.env.docker.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Arquivo de exemplo para variáveis de ambiente do Docker
2+
# Copie este arquivo para .env.docker e preencha com os valores corretos
3+
4+
PORT=3333
5+
MONGO_URL=mongodb://root:SUA_SENHA_MONGO@mongodb:27017/sinapheatmap?authSource=admin
6+
JWT_SECRET=SEU_JWT_SECRET_AQUI
7+
NODE_ENV=production
8+
9+
# Outras variáveis que você pode precisar:
10+
# CORS_ORIGIN=*
11+
# API_VERSION=v1

be/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PORT=
2+
MONGO_URL=
3+
JWT_SECRET=

be/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ src/uploads/*
66
!src/uploads/
77
!src/uploads/.gitkeep
88

9-
.env
9+
.env
10+
.env.docker

docker-compose.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: "3.8"
2+
3+
services:
4+
mongodb:
5+
image: mongo:6
6+
container_name: sinapheatmap-mongo
7+
restart: unless-stopped
8+
ports:
9+
- "27017:27017"
10+
volumes:
11+
- mongo_data:/data/db
12+
environment:
13+
MONGO_INITDB_ROOT_USERNAME: root
14+
MONGO_INITDB_ROOT_PASSWORD: sinapsense123
15+
MONGO_INITDB_DATABASE: sinapheatmap
16+
networks:
17+
- sinapheatmap-network
18+
19+
backend:
20+
build:
21+
context: ./be
22+
dockerfile: Dockerfile
23+
container_name: sinapheatmap-backend
24+
restart: unless-stopped
25+
ports:
26+
- "3333:3333"
27+
env_file:
28+
- ./be/.env.docker
29+
volumes:
30+
- ./be/uploads:/usr/src/app/uploads
31+
- ./be/logs:/usr/src/app/logs
32+
depends_on:
33+
- mongodb
34+
networks:
35+
- sinapheatmap-network
36+
healthcheck:
37+
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3333/server', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"]
38+
interval: 30s
39+
timeout: 10s
40+
retries: 5
41+
frontend:
42+
build:
43+
context: ./fe
44+
dockerfile: Dockerfile
45+
args:
46+
VITE_API_BASE_URL: "http://localhost:3333"
47+
container_name: sinapheatmap-frontend
48+
restart: unless-stopped
49+
ports:
50+
- "80:80"
51+
depends_on:
52+
- backend
53+
networks:
54+
- sinapheatmap-network
55+
56+
volumes:
57+
mongo_data:
58+
driver: local
59+
60+
networks:
61+
sinapheatmap-network:
62+
driver: bridge

fe/.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules
2+
dist
3+
.vscode
4+
.git
5+
*.log
6+
.env
7+
.env.local
8+
.env.development.local
9+
.env.test.local
10+
.env.production.local
11+
coverage
12+
.nyc_output
13+
.DS_Store
14+
Thumbs.db

fe/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:18-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
7+
RUN npm ci
8+
9+
COPY . .
10+
11+
ARG VITE_API_BASE_URL
12+
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
13+
14+
RUN npm run build
15+
16+
FROM nginx:stable-alpine
17+
18+
COPY --from=builder /app/dist /usr/share/nginx/html
19+
20+
COPY nginx.conf /etc/nginx/conf.d/default.conf
21+
22+
EXPOSE 80
23+
24+
CMD ["nginx", "-g", "daemon off;"]

fe/nginx.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
7+
location / {
8+
try_files $uri $uri/ /index.html;
9+
}
10+
11+
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
12+
expires 1y;
13+
add_header Cache-Control "public, immutable";
14+
}
15+
16+
location /api {
17+
proxy_pass http://backend:3333;
18+
proxy_set_header Host $host;
19+
proxy_set_header X-Real-IP $remote_addr;
20+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21+
proxy_set_header X-Forwarded-Proto $scheme;
22+
}
23+
24+
location /uploads {
25+
proxy_pass http://backend:3333;
26+
proxy_set_header Host $host;
27+
proxy_set_header X-Real-IP $remote_addr;
28+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29+
proxy_set_header X-Forwarded-Proto $scheme;
30+
}
31+
}

0 commit comments

Comments
 (0)