Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ccc8520
Implementando testes integrados
RMastronauta Jun 20, 2025
d389f1a
feat: criação pipeline de CI
Ramon-denv Jun 20, 2025
389b814
created pipeline ic
Ramon-denv Jun 20, 2025
0656421
corrigindo pipeline
Ramon-denv Jun 20, 2025
fa265af
teste pipline
Ramon-denv Jun 20, 2025
c49694e
Merge pull request #1 from RMastronauta/teste-pipeline
Ramon-denv Jun 20, 2025
b947833
teste pipeline
Ramon-denv Jun 20, 2025
736c669
fix(pipeline): ajustando nomenclatura da branch
Ramon-denv Jun 20, 2025
6f14309
ajustes para evitar erros de depedencias
Ramon-denv Jun 20, 2025
bda7422
Merge branch 'master' of https://github.com/RMastronauta/nestjs-realw…
Ramon-denv Jun 20, 2025
6653385
fix(pipeline): ajsutando registro para instalar dependencia
Ramon-denv Jun 20, 2025
fa3f6fd
fix(pipeline): ajustando pipeline para rodar as dependencias
Ramon-denv Jun 20, 2025
9c43816
fix(pipeline): ajuste pipeline
Ramon-denv Jun 20, 2025
2150240
fix(pipeline): ajuste
Ramon-denv Jun 20, 2025
499822a
fix(ajuste): ajuste
RMastronauta Jun 20, 2025
81e3f65
fix(pipeline): ajustando build
Ramon-denv Jun 20, 2025
7433627
fix(pipeline): corrigindo ordem de build
Ramon-denv Jun 20, 2025
ef5b94e
feat(pipeline): configuração pipeline
Ramon-denv Jun 20, 2025
7b17ed4
fix(pipeline): ajuste para rodar testes integrados
Ramon-denv Jun 20, 2025
71af5ad
ajustes
Ramon-denv Jun 20, 2025
8910b01
fix(dependencia): adicionando dependencia
Ramon-denv Jun 20, 2025
8d542d8
ajuste
Ramon-denv Jun 20, 2025
5ae4f25
Ajuste pipeline use prisma
Ramon-denv Jun 20, 2025
4c5afbc
ajustando version prisma
Ramon-denv Jun 20, 2025
4039327
feat(prisma): Adicionando arquivo scherman do prisma
RMastronauta Jun 20, 2025
010738a
correção do pipeline
Ramon-denv Jun 20, 2025
83833e6
Alterando pipeline
Ramon-denv Jun 20, 2025
7632be9
Ajuste pipeline
Ramon-denv Jun 20, 2025
155bf77
ajuste para rodar o pipeline
Ramon-denv Jun 20, 2025
776e968
feat: adiciona testes de aceitção e containeriza app
marcotulio21mm Jun 21, 2025
fcc65c7
fix: ajuste pipeline
marcotulio21mm Jun 21, 2025
55e44eb
fix: corrigindo pipeline ci
Ramon-denv Jun 21, 2025
d7c0506
feat: criando pipeline cd
Ramon-denv Jun 21, 2025
3c85ad0
fix: corrigindo pipeline cd
Ramon-denv Jun 21, 2025
ab017f4
Correção pipeline
Ramon-denv Jun 21, 2025
0452f48
Test(master): implements unit tests
EduardoABrito Jun 22, 2025
f852818
Feat(master): added view coverage
EduardoABrito Jun 22, 2025
9194fca
fix: adicionando os testes unitarios
Ramon-denv Jun 22, 2025
fb2df36
corrigindo pipeline
Ramon-denv Jun 22, 2025
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
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
dist
coverage
141 changes: 141 additions & 0 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: continuous-integration

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: nestjsrealworld
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=3

steps:
- uses: actions/checkout@v3

- name: using node.js
uses: actions/setup-node@v2
with:
node-version: 16.x

- name: Ignore SSL errors (insecure)
run: npm config set registry https://registry.npmjs.org/

- name: Install dependencies
run: |
rm -rf node_modules
rm -f package-lock.json
npm install

- name: Criar ormconfig.json
run: |
cat <<EOF > ormconfig.json
{
"type": "mysql",
"host": "painel.eduardoabrito.com.br",
"port": 3031,
"username": "mysql",
"password": "f9f6cff4c6c4071a9b5c",
"database": "nestjsrealworld",
"entities": ["src/*/*.entity{.ts,.js}"],
"synchronize": true
}
EOF

- name: Build
run: npm run build

unit-test:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: using node.js
uses: actions/setup-node@v2
with:
node-version: 16.x

- name: Install dependencies
run: npm install

- name: Run unit tests
run: npm run test:coverage

integration-test:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: using node.js
uses: actions/setup-node@v2
with:
node-version: 16.x

- name: Install dependencies
run: npm install

- name: Run integration tests
run: npm run test:integration

acceptance-test:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: using node.js
uses: actions/setup-node@v2
with:
node-version: 16.x

- name: Install dependencies
run: npm install

- name: Run acceptance tests
run: npm run test:acceptance
deploy:
needs:
- unit-test
- integration-test
- acceptance-test
runs-on: ubuntu-latest
environment: DOCKER_PIPELINE

steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
run: docker build -t deployconfig/nestjs-realworld-app:latest .

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker image to Docker Hub
run: docker push deployconfig/nestjs-realworld-app:latest

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ node_modules

#config files
ormconfig.json
src/config.ts

# code testing coverage
coverage
Expand Down
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Dockerfile para NestJS Realworld Example App
FROM node:18-alpine

# Instalar dependências do sistema incluindo OpenSSL
RUN apk add --no-cache bash openssl

# Criar diretório da aplicação
WORKDIR /usr/src/app

# Copiar arquivos de dependências
COPY package*.json ./
COPY yarn.lock ./

# Instalar todas as dependências (incluindo devDependencies para testes)
RUN npm ci

# Copiar código fonte
COPY . .

# Instalar Prisma CLI globalmente
RUN npm install -g prisma

# Gerar cliente Prisma
RUN npx prisma generate

# Compilar TypeScript
RUN npm run build

# Expor porta
EXPOSE 3000

# Comando para iniciar a aplicação em produção
CMD [ "npm", "run", "start:prod" ]
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,89 @@ This applications uses JSON Web Token (JWT) to handle authentication. The token
# Swagger API docs

This example repo uses the NestJS swagger module for API documentation. [NestJS Swagger](https://github.com/nestjs/swagger) - [www.swagger.io](https://swagger.io/)

# Como rodar o projeto localmente

## Pré-requisitos

- Node.js 16.x ou superior
- npm ou yarn
- Docker e Docker Compose (opcional, mas recomendado)

## 1. Rodando com Docker (recomendado)

1. **Clone o repositório:**
```bash
git clone <url-do-repositorio>
cd nestjs-realworld-example-app
```

2. **Suba os containers:**
```bash
docker-compose up --build
```
Isso irá:
- Subir o banco de dados MySQL já configurado
- Subir a aplicação em modo desenvolvimento (hot reload)

3. **Acesse a aplicação:**
- API: http://localhost:3000/api
- Documentação Swagger: http://localhost:3000/api/docs (se habilitado)

4. **Parar os containers:**
```bash
docker-compose down
```

## 2. Rodando sem Docker (apenas Node.js)

1. **Instale as dependências:**
```bash
npm install
# ou
yarn install
```

2. **Configure o banco de dados:**
- Crie um banco MySQL local ou use um banco externo.
- Copie o arquivo de exemplo:
```bash
cp src/config.ts.example src/config.ts
```
- Edite `src/config.ts` com as credenciais do seu banco.

3. **Rode as migrations (se necessário):**
- O projeto está configurado para sincronizar as entidades automaticamente (`synchronize: true`), mas em produção recomenda-se usar migrations.

4. **Inicie a aplicação:**
```bash
npm run start:dev
# ou
yarn start:dev
```

5. **Acesse a aplicação:**
- API: http://localhost:3000/api

## 3. Rodando os testes de aceitação

- **Com Docker:**
```bash
docker-compose run --rm app npm run test:acceptance
```
- **Localmente:**
```bash
npm run test:acceptance
```

## 4. Gerando relatório visual dos testes de aceitação

Após rodar os testes de aceitação, gere o relatório:
```bash
node scripts/generate-acceptance-report.js
```
O relatório estará em `coverage/acceptance-report.html`.

---

Dúvidas? Abra uma issue ou consulte os scripts e exemplos no repositório.
10 changes: 10 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.8'

services:
app:
environment:
- DB_HOST=mysql
- DB_PORT=3306
- DB_USERNAME=nestjsuser
- DB_PASSWORD=nestjspassword
- DB_DATABASE=nestjsrealworld
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.8'

services:
mysql:
image: mysql:8.0
container_name: nestjs-mysql-container
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: nestjsrealworld
MYSQL_USER: nestjsuser
MYSQL_PASSWORD: nestjspassword
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
networks:
- nestjs-network

app:
build: .
container_name: nestjs-app-container
restart: unless-stopped
ports:
- "3000:3000"
environment:
- NODE_ENV=development
depends_on:
- mysql
volumes:
- .:/app
- /app/node_modules
command: npm run start:watch
networks:
- nestjs-network

networks:
nestjs-network:
driver: bridge

volumes:
mysql_data:
Loading