Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci/cd #5

Merged
merged 4 commits into from
Aug 26, 2023
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
37 changes: 37 additions & 0 deletions .Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Estágio de desenvolvimento
FROM node:14 AS development

WORKDIR /app

# Copia apenas os arquivos necessários para aproveitar o cache de camadas do Docker
COPY package*.json ./
RUN npm install

# Instala o pacote "vite" globalmente no contêiner
RUN npm install -g vite

# Copia todos os arquivos do projeto
COPY . .

# Executa o comando para iniciar o servidor de desenvolvimento do Vite
CMD ["npm", "run", "dev"]

# Estágio de produção
FROM development AS production

# Executa o comando para fazer o build da aplicação usando o Vite
RUN npm run build

# Estágio final para servir os arquivos com o Nginx
FROM nginx:alpine AS final

# Remove a configuração padrão do Nginx
RUN rm -rf /usr/share/nginx/html/*

# Copia todos os arquivos do projeto da etapa de produção para o diretório padrão do Nginx
COPY --from=production /app/dist /usr/share/nginx/html

EXPOSE 80

# Comando para iniciar o servidor Nginx em modo daemon
CMD ["nginx", "-g", "daemon off;"]
30 changes: 30 additions & 0 deletions .github/workflows/CIDocker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Docker Image CI

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout do Repositório
uses: actions/checkout@v2

- name: Construir a Imagem Docker
run: |
NOME_DA_IMAGEM="${{ github.repository }}"
ETIQUETA_DA_IMAGEM="$(date +%s)"
COMANDO_DE_CONSTRUCAO="docker build . --file Dockerfile --tag $NOME_DA_IMAGEM:$ETIQUETA_DA_IMAGEM"
echo "Construindo imagem Docker: $COMANDO_DE_CONSTRUCAO"
$COMANDO_DE_CONSTRUCAO

- name: Display Image Tag
run: echo "Docker image tag: ${{ github.repository }}:$IMAGE_TAG"
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3"

project_name: ecommece-compass

services:
# Serviço para o ambiente de desenvolvimento com o Vite
development:
build:
context: .
target: development
ports:
- "3000:3000" # Porta para acesso ao servidor de desenvolvimento do Vite
volumes:
- .:/app # Monta o diretório local como volume para refletir as alterações no contêiner em tempo real

# Serviço para o ambiente de produção com o Nginx
production:
build:
context: .
target: final
ports:
- "80:80" # Porta para acesso ao servidor Nginx em modo de produção
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"build-docker": "docker build -t ecommece-compass .",
"deploy-s3": "aws s3 sync dist/ s3://seu-bucket-s3"
},
"dependencies": {
"axios": "^1.4.0",
Expand Down
Loading