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

Feat/dockerize app #47

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
initialize Docker setup, and CI workflows
mhd-hi committed Nov 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 92888779e6e9e8ab74200f1f7cb1c419c87da349
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Node modules
node_modules
npm-debug.log
yarn-error.log

# Logs
logs
*.log
npm-debug.log*

# Environment variables
.env
.env.*

# Docker files
Dockerfile
docker-compose.yml
.dockerignore

# Git files
.git
.gitignore

# Others
dist
coverage
10 changes: 8 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
NODE_ENV=development

PORT=3000

# Database Configuration
DATABASE_URL="postgresql://postgres@localhost:5432/planifetsDB?schema=public"
POSTGRES_HOST="db"
POSTGRES_DB="planifetsDB"
POSTGRES_PASSWORD="postgres"
POSTGRES_USER="postgres"
POSTGRES_PORT=5433

LOG_LEVELS="log,error,warn,debug" # Log levels: "log,error,warn,debug,fatal,verbose"
# Logging Levels
LOG_LEVELS="log,error,warn,debug" # Options: log,error,warn,debug,fatal,verbose
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# syntax=docker/dockerfile:1

# Base dependencies
FROM node:18-alpine AS base
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install

# Development
FROM base AS development
WORKDIR /app
COPY . ./

RUN yarn install --frozen-lockfile
RUN yarn global add @nestjs/cli
RUN yarn prisma:generate

ENV NODE_ENV=development
# Required for hot-reloading
ENV CHOKIDAR_USEPOLLING=true

CMD [ "yarn", "start:dev" ]

# Build
FROM base AS build
WORKDIR /app
COPY . ./

RUN yarn build

# Production
FROM node:18-alpine AS production
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --production --frozen-lockfile

COPY --from=build /app/dist ./dist
COPY prisma ./prisma
RUN yarn prisma:generate

ENV NODE_ENV=production

CMD [ "yarn", "start:prod" ]

EXPOSE 3000
55 changes: 27 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
<div align="center" style="font-family: Arial, sans-serif; font-size: 48px; font-weight: bold; color: #F0F4FF; margin: 60px;">
Planif<span style="color: #ff0000;">ETS</span>
</div>

<br />
<strong>PlanifÉTS Project</strong>
<p align="center">
<a href="https://github.com/PlanifETS/planifets-backend/actions" target="_blank">
</a>
<a href="https://github.com/ApplETS/planifETS-backend/actions/workflows/ci.yml/badge.svg" target="_blank">
<img src="https://github.com/ApplETS/planifETS-backend/actions/workflows/ci.yml/badge.svg" alt="CI Status" style="height: 20px; margin-right: 5px;">
</a>
<a href="https://www.notion.so/PlanifETS-29cdf43623ec4c749dc5280dcaa3dba4" target="_blank">
<img src="https://img.shields.io/badge/Notion-%23000000.svg?style=for-the-badge&logo=notion&logoColor=white" alt="CI Status" style="height: 20px; margin-right: 5px;">
</a>
</p>


## Description
> _Session planner for students at the École de technologie supérieure_
This project is built on top of the Angular CLI. It uses the Dgeni documentation generator to compile source documentation in markdown format into the published format. The Repository contains docs.nestjs.com/first-steps source code, the official Nest documentation.
This backend provides an API to support academic session planning at ÉTS.

## Installation
It fetches and synchronizes course and program data directly from ÉTS servers, giving students up-to-date information for planning their academic paths.

```bash
$ yarn install
```
---

## Running the app
## 🚀 Technologies used

```bash
# development
$ yarn run start
- [NestJS](https://docs.nestjs.com/)
- [Prisma](https://www.prisma.io/nestjs)
- [PostgreSQL](https://www.postgresql.org/) (version 16+)
- [Docker](https://www.docker.com/)

# watch mode
$ yarn run start:dev
---

# production mode
$ yarn run start:prod
```
## 🛠️ Onboarding

## Test
For onboarding instructions, please refer to our detailed documentation on [Notion](https://www.notion.so/Onboarding-662062ca7e0e421eb59baf3a63dad2e6).

```bash
# unit tests
$ yarn run test
---

# e2e tests
$ yarn run test:e2e
## ⚖️ License

# test coverage
$ yarn run test:cov
```
This projet is licensed under the Apache License V2.0. See the [LICENSE](https://github.com/ApplETS/Notre-Dame/blob/master/LICENSE) file for more info.
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
services:
app:
build:
context: .
target: ${TARGET:-development}
ports:
- '3000:3000'
environment:
DATABASE_URL: ${DATABASE_URL}
NODE_ENV: ${NODE_ENV:-development}
PORT: ${PORT}
env_file:
- .env
depends_on:
db:
condition: service_healthy
volumes:
- .:/app
- /app/node_modules
networks:
- app-network
restart: unless-stopped

db:
image: postgres:16
ports:
- '5433:5432'
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- db-data:/var/lib/postgresql/data
networks:
- app-network
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
interval: 10s
timeout: 5s
retries: 5

volumes:
db-data:
driver: local

networks:
app-network:
driver: bridge
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -4,14 +4,17 @@
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"license": "Apache-2.0",
"scripts": {
"build": "nest build",
"start": "nest start",
"dev": "nest start --watch",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"docker:dev": "docker-compose up -d",
"docker:build": "docker-compose up -d --build",
"docker:prod": "set TARGET=production&& docker-compose up --build --force-recreate --remove-orphans",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint src --ext .ts",
"refresh": "rm -rf dist && rm -rf node_modules && yarn cache clean && yarn install",
4 changes: 0 additions & 4 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -2,8 +2,4 @@ import * as path from 'path';

export default () => ({
pdfOutputPath: path.resolve(__dirname, '../../test/pdf/output'),
redis: {
host: process.env.REDIS_HOST ?? 'localhost',
port: parseInt(process.env.REDIS_PORT ?? '6379', 10),
},
});
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import { HttpExceptionFilter } from './common/exceptions/http-exception.filter';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;

app.useGlobalFilters(new HttpExceptionFilter());

@@ -22,7 +23,7 @@ async function bootstrap() {
.setTitle('PlanifÉTS API')
.setExternalDoc('JSON API Documentation', '/api-json')
.setVersion('1.0')
.addServer('http://localhost:3000/', 'Local environment')
.addServer(`http://localhost:${port}/`, 'Local environment')
.build();
const document = SwaggerModule.createDocument(app, swaggerConfig);
const swaggerOptions = {
@@ -33,7 +34,7 @@ async function bootstrap() {
SwaggerModule.setup('api', app, document, swaggerOptions);

//Start the app
await app.listen(process.env.PORT ? parseInt(process.env.PORT) : 3000);
console.log(`Swagger is running on http://localhost:${process.env.PORT}/api`);
await app.listen(port);
console.log(`Swagger is running on http://localhost:${port}/api`);
}
bootstrap();