Skip to content

Commit

Permalink
feat(#90): Corrigindo Dockerfile docker-compose e adicionando nginx
Browse files Browse the repository at this point in the history
Corrigindo dockerfile, docker compose e adicionando nginx para executar o front

Co-authored-by: Ana-Luiza-SC <ssoares.analuiza@gmail.com>
  • Loading branch information
Neoprot and Ana-Luiza-SC committed Jan 31, 2025
1 parent 1344588 commit 0696b23
Showing 3 changed files with 72 additions and 33 deletions.
42 changes: 31 additions & 11 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
# Usa uma imagem oficial do Node.js como base
FROM node:18-alpine
# Build Stage
FROM node:latest as build-stage

# Define o diretório de trabalho dentro do container
WORKDIR /app

# Copia os arquivos do projeto para o container
COPY package.json package-lock.json ./
# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Instala as dependências
# Install dependencies
RUN npm install

# Copia o restante do código do projeto
# Copy the rest of the application files to the working directory
COPY . .

# Expõe a porta padrão do React
EXPOSE 3000
# Build the React application
RUN npm run build

# Comando para iniciar a aplicação
CMD ["npm", "start"]
# Production Stage
FROM nginx:latest

# Copy the NGINX configuration file
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf

COPY --from=build-stage /app/build/ /usr/share/nginx/html

# We need to make sure not to run the container as a non root user
# for better security
WORKDIR /app
RUN chown -R nginx:nginx /app && chmod -R 755 /app && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chown -R nginx:nginx /etc/nginx/conf.d
RUN touch /var/run/nginx.pid && \
chown -R nginx:nginx /var/run/nginx.pid

USER nginx

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
19 changes: 19 additions & 0 deletions client/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location /health {
return 200;
}
}
44 changes: 22 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
services:
backend:
build:
context: .
dockerfile: server/Dockerfile
ports:
- "8000:8000"
volumes:
- ./server:/app
environment:
- DB_NAME=YOUR_DB_NAME
- DB_USER=YOUR_DB_USER
- DB_PASSWORD=YOUR_DB_PASSWORD
- DB_HOST=YOUR_DB_HOST
build:
context: .
dockerfile: server/Dockerfile
ports:
- "8000:8000"
volumes:
- ./server:/app
environment:
- DB_NAME=YOUR_DB_NAME
- DB_USER=YOUR_DB_USER
- DB_PASSWORD=YOUR_DB_PASSWORD
- DB_HOST=YOUR_DB_HOST
- DB_PORT=3306

frontend:
build:
context: .
dockerfile: client/Dockerfile
ports:
- "3000:3000"
volumes:
- ./client:/app
- /app/node_modules
environment:
- CHOKIDAR_USEPOLLING=true
build:
context: ./client
dockerfile: Dockerfile
container_name: frontend
ports:
- "3000:80"
depends_on:
- backend

0 comments on commit 0696b23

Please sign in to comment.