Skip to content

Commit

Permalink
feat: cd docker deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheusafonsouza committed Jan 10, 2025
1 parent 4452218 commit f71f45e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.eslintrc.js
src/database/migrations/
22 changes: 22 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CD
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Build, Push and Release a Docker container to Heroku.
uses: gonuit/heroku-docker-deploy@v1.3.3
with:
email: ${{ secrets.LIVRO_LIVRE_HEROKU_EMAIL }}
heroku_api_key: ${{ secrets.LIVRO_LIVRE_HEROKU_API_KEY }}
heroku_app_name: "livro-livre-users"
dockerfile_directory: ./
dockerfile_name: Dockerfile
docker_options: "--no-cache"
process_type: web
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: Lint
run:
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install dependencies
run: npm install
- name: Test and coverage
- name: Run lint
run: npm run lint
- name: Run tests
run: npm run test
2 changes: 1 addition & 1 deletion src/auth/roles.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetMetadata } from '@nestjs/common';
import { UserRoles } from 'src/database/entities/user.entity';
import { UserRoles } from '../database/entities/user.entity';

export const Roles = (...roles: UserRoles[]) => SetMetadata('roles', roles);
7 changes: 5 additions & 2 deletions src/auth/roles.guard.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { UserRoles } from 'src/database/entities/user.entity';
import { UserRoles } from '../database/entities/user.entity';

@Injectable()
export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {}

canActivate(context: ExecutionContext): boolean {
const requiredRoles = this.reflector.get<UserRoles[]>('roles', context.getHandler());
const requiredRoles = this.reflector.get<UserRoles[]>(
'roles',
context.getHandler(),
);
if (!requiredRoles) {
return true;
}
Expand Down
19 changes: 10 additions & 9 deletions src/database/migrations/1736291880582-create-users.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateUsers1736291880582 implements MigrationInterface {
name = 'CreateUsers1736291880582'
name = 'CreateUsers1736291880582';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, "password" character varying NOT NULL, "email" character varying NOT NULL, "phone" character varying NOT NULL, "role" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "user"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "user" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "firstName" character varying NOT NULL, "lastName" character varying NOT NULL, "password" character varying NOT NULL, "email" character varying NOT NULL, "phone" character varying NOT NULL, "role" character varying NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "user"`);
}
}
6 changes: 3 additions & 3 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '@nestjs/common';
import { UpdateUserDto } from './dtos/updateUser.dto';
import { AuthGuard } from '../auth/auth.guard';
import { Roles } from 'src/auth/roles.decorator';
import { UserRoles } from 'src/database/entities/user.entity';
import { RolesGuard } from 'src/auth/roles.guard';
import { Roles } from '../auth/roles.decorator';
import { UserRoles } from '../database/entities/user.entity';
import { RolesGuard } from '../auth/roles.guard';

@Controller('users')
export class UsersController {
Expand Down

0 comments on commit f71f45e

Please sign in to comment.