From 92888779e6e9e8ab74200f1f7cb1c419c87da349 Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Sun, 3 Nov 2024 19:10:05 -0500 Subject: [PATCH 1/8] initialize Docker setup, and CI workflows --- .dockerignore | 26 ++++++++++++++++++ .env.example | 10 +++++-- Dockerfile | 45 ++++++++++++++++++++++++++++++ README.md | 55 ++++++++++++++++++------------------- docker-compose.yml | 48 ++++++++++++++++++++++++++++++++ package.json | 5 +++- src/config/configuration.ts | 4 --- src/main.ts | 7 +++-- 8 files changed, 162 insertions(+), 38 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b8fd49b --- /dev/null +++ b/.dockerignore @@ -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 \ No newline at end of file diff --git a/.env.example b/.env.example index 6e661bc..f0b249c 100644 --- a/.env.example +++ b/.env.example @@ -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" \ No newline at end of file +# Logging Levels +LOG_LEVELS="log,error,warn,debug" # Options: log,error,warn,debug,fatal,verbose \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a170ab2 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index d6751b0..956a6a0 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,42 @@ -

- Nest Logo +

+ PlanifETS +
-
- PlanifÉTS Project +

+ + + + CI Status + + + CI Status +

-## 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 -``` \ No newline at end of file +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. \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..496d9d8 --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/package.json b/package.json index 1f7054a..45e4042 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "author": "", "private": true, - "license": "UNLICENSED", + "license": "Apache-2.0", "scripts": { "build": "nest build", "start": "nest start", @@ -12,6 +12,9 @@ "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", diff --git a/src/config/configuration.ts b/src/config/configuration.ts index 831c33d..bfc2dbb 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -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), - }, }); diff --git a/src/main.ts b/src/main.ts index 71a98a5..8f26cb3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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(); From 5c7d93f28d38f349dcd3f53449fecef3fb80b5ce Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Mon, 4 Nov 2024 15:56:18 -0500 Subject: [PATCH 2/8] add cd --- .github/workflows/cd.yml | 79 ++++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 11 +++--- README.md | 2 +- 3 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..82fb7ec --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,79 @@ +name: CD + +on: + push: + branches: + - main + tags: + - 'v*' + pull_request: + branches: ['main'] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + cache-dependency-path: 'yarn.lock' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run tests + run: yarn run test + + - name: Build project + run: yarn run build + docker: + runs-on: ubuntu-latest + needs: [build-and-test] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Login to Registry + # if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true # ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Semantic Release + # if: github.event_name != 'pull_request' + uses: cycjimmy/semantic-release-action@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa5153b..4c5a80d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,5 @@ -name: ci +name: CI + on: push: branches: [main] @@ -13,7 +14,7 @@ jobs: node-version: [18.x] steps: - - name: Checkout to code + - name: Checkout code uses: actions/checkout@v3 - name: Setup Node.js @@ -26,11 +27,11 @@ jobs: - name: Install dependencies run: yarn install --frozen-lockfile - - name: lint + - name: Lint code run: yarn run lint - name: Run tests - run: yarn test + run: yarn run test - - name: Build + - name: Build project run: yarn run build diff --git a/README.md b/README.md index 956a6a0..8685859 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ It fetches and synchronizes course and program data directly from ÉTS servers, ## 🛠️ Onboarding -For onboarding instructions, please refer to our detailed documentation on [Notion](https://www.notion.so/Onboarding-662062ca7e0e421eb59baf3a63dad2e6). +For onboarding instructions, please refer to our documentation on [Notion](https://www.notion.so/Onboarding-662062ca7e0e421eb59baf3a63dad2e6). --- From 5531927a937933731dffbe32ea8cf0dee878ecf7 Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Mon, 4 Nov 2024 16:03:48 -0500 Subject: [PATCH 3/8] fix cd --- .github/workflows/cd.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 82fb7ec..5b9f211 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -58,7 +58,7 @@ jobs: type=semver,pattern={{major}}.{{minor}} - name: Login to Registry - # if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -66,6 +66,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push + if: github.event_name != 'pull_request' uses: docker/build-push-action@v5 with: context: . @@ -73,7 +74,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - name: Semantic Release - # if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' uses: cycjimmy/semantic-release-action@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 565c269dc9c71ebf4bdcfc98e82331952be6886e Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Mon, 4 Nov 2024 16:15:10 -0500 Subject: [PATCH 4/8] fix cd --- .github/workflows/cd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 5b9f211..2625c82 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -6,8 +6,6 @@ on: - main tags: - 'v*' - pull_request: - branches: ['main'] env: REGISTRY: ghcr.io @@ -47,6 +45,7 @@ jobs: uses: actions/checkout@v4 - name: Docker meta + if: github.event_name != 'pull_request' id: meta uses: docker/metadata-action@v5 with: From d2b1c4b667c4d4fb9357f82f7b4138afc5586d67 Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Mon, 4 Nov 2024 16:16:46 -0500 Subject: [PATCH 5/8] another one --- .github/workflows/cd.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 2625c82..a95f6be 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -57,7 +57,6 @@ jobs: type=semver,pattern={{major}}.{{minor}} - name: Login to Registry - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -65,7 +64,6 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push - if: github.event_name != 'pull_request' uses: docker/build-push-action@v5 with: context: . @@ -73,7 +71,6 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - name: Semantic Release - if: github.event_name != 'pull_request' uses: cycjimmy/semantic-release-action@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 4dba93cf4ea5c5df32b0f78cf01a29e5967fb7fb Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Mon, 4 Nov 2024 22:31:01 -0500 Subject: [PATCH 6/8] remove volumes for prod docker --- .github/workflows/cd.yml | 19 ++++++++++---- Dockerfile | 4 +-- README.md | 55 ++++++++++++++++++++-------------------- docker-compose.dev.yml | 48 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 15 ++++------- package.json | 6 ++--- 6 files changed, 99 insertions(+), 48 deletions(-) create mode 100644 docker-compose.dev.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a95f6be..8fb0015 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -6,6 +6,8 @@ on: - main tags: - 'v*' + pull_request: # fixme: test purpose only + branches: ['main'] env: REGISTRY: ghcr.io @@ -37,6 +39,7 @@ jobs: - name: Build project run: yarn run build + docker: runs-on: ubuntu-latest needs: [build-and-test] @@ -45,7 +48,7 @@ jobs: uses: actions/checkout@v4 - name: Docker meta - if: github.event_name != 'pull_request' + # if: github.event_name != 'pull_request' id: meta uses: docker/metadata-action@v5 with: @@ -57,6 +60,7 @@ jobs: type=semver,pattern={{major}}.{{minor}} - name: Login to Registry + # if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -70,7 +74,12 @@ jobs: push: true # ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - name: Semantic Release - uses: cycjimmy/semantic-release-action@v4 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + + semantic-release: + runs-on: ubuntu-latest + needs: [docker] + steps: + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a170ab2..5e3a0c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,9 +11,7 @@ FROM base AS development WORKDIR /app COPY . ./ -RUN yarn install --frozen-lockfile -RUN yarn global add @nestjs/cli -RUN yarn prisma:generate +RUN yarn install --frozen-lockfile && yarn global add @nestjs/cli && yarn prisma:generate ENV NODE_ENV=development # Required for hot-reloading diff --git a/README.md b/README.md index 8685859..d6751b0 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,43 @@ -
- PlanifETS -
-

- - - - CI Status - - - CI Status - + Nest Logo + +
+ PlanifÉTS Project

-> _Session planner for students at the École de technologie supérieure_ +## Description -This backend provides an API to support academic session planning at ÉTS. +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. -It fetches and synchronizes course and program data directly from ÉTS servers, giving students up-to-date information for planning their academic paths. +## Installation ---- +```bash +$ yarn install +``` -## 🚀 Technologies used +## Running the app -- [NestJS](https://docs.nestjs.com/) -- [Prisma](https://www.prisma.io/nestjs) -- [PostgreSQL](https://www.postgresql.org/) (version 16+) -- [Docker](https://www.docker.com/) +```bash +# development +$ yarn run start ---- +# watch mode +$ yarn run start:dev -## 🛠️ Onboarding +# production mode +$ yarn run start:prod +``` -For onboarding instructions, please refer to our documentation on [Notion](https://www.notion.so/Onboarding-662062ca7e0e421eb59baf3a63dad2e6). +## Test ---- +```bash +# unit tests +$ yarn run test -## ⚖️ License +# e2e tests +$ yarn run test:e2e -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. \ No newline at end of file +# test coverage +$ yarn run test:cov +``` \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..e0dfcb7 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,48 @@ +services: + app: + build: + context: . + target: ${TARGET:-development} + ports: + - "${PORT:-3000}:${PORT:-3000}" + environment: + DATABASE_URL: ${DATABASE_URL} + 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 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 496d9d8..31c5de4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,21 +2,16 @@ services: app: build: context: . - target: ${TARGET:-development} + target: production ports: - - '3000:3000' + - "${PORT:-3000}:${PORT:-3000}" environment: DATABASE_URL: ${DATABASE_URL} - NODE_ENV: ${NODE_ENV:-development} - PORT: ${PORT} - env_file: - - .env + NODE_ENV: production + PORT: ${PORT:-3000} depends_on: db: condition: service_healthy - volumes: - - .:/app - - /app/node_modules networks: - app-network restart: unless-stopped @@ -45,4 +40,4 @@ volumes: networks: app-network: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/package.json b/package.json index 45e4042..09ae7ad 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "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", + "docker:dev": "docker-compose -f docker-compose.dev.yml up -d", + "docker:build-dev": "docker-compose -f docker-compose.dev.yml up -d --build", + "docker:prod": "docker-compose -f docker-compose.yml up -d --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", From 63010d296559239d8c7fb271de13b5211888e295 Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Wed, 6 Nov 2024 19:40:01 -0500 Subject: [PATCH 7/8] wip --- .env.example | 4 +- charts/planifets-backend/Chart.yaml | 6 ++ .../templates/app-deployment.yaml | 56 ++++++++++++++ .../planifets-backend/templates/ingress.yaml | 17 +++++ .../templates/postgres-pvc.yaml | 10 +++ .../templates/postgres-secret.yaml | 10 +++ .../planifets-backend/templates/postgres.yaml | 73 +++++++++++++++++++ charts/planifets-backend/values.yaml | 26 +++++++ 8 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 charts/planifets-backend/Chart.yaml create mode 100644 charts/planifets-backend/templates/app-deployment.yaml create mode 100644 charts/planifets-backend/templates/ingress.yaml create mode 100644 charts/planifets-backend/templates/postgres-pvc.yaml create mode 100644 charts/planifets-backend/templates/postgres-secret.yaml create mode 100644 charts/planifets-backend/templates/postgres.yaml create mode 100644 charts/planifets-backend/values.yaml diff --git a/.env.example b/.env.example index f0b249c..892a972 100644 --- a/.env.example +++ b/.env.example @@ -2,12 +2,12 @@ NODE_ENV=development PORT=3000 # Database Configuration -DATABASE_URL="postgresql://postgres@localhost:5432/planifetsDB?schema=public" +DATABASE_URL="postgresql://postgres@localhost:5433/planifetsDB?schema=public" POSTGRES_HOST="db" POSTGRES_DB="planifetsDB" POSTGRES_PASSWORD="postgres" POSTGRES_USER="postgres" -POSTGRES_PORT=5433 +POSTGRES_PORT=5433 # Logging Levels LOG_LEVELS="log,error,warn,debug" # Options: log,error,warn,debug,fatal,verbose \ No newline at end of file diff --git a/charts/planifets-backend/Chart.yaml b/charts/planifets-backend/Chart.yaml new file mode 100644 index 0000000..b6d3969 --- /dev/null +++ b/charts/planifets-backend/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: planifets-backend +description: A Helm chart for Kubernetes +type: application +version: 0.2.0 +appVersion: '0.1.0' \ No newline at end of file diff --git a/charts/planifets-backend/templates/app-deployment.yaml b/charts/planifets-backend/templates/app-deployment.yaml new file mode 100644 index 0000000..d7230b6 --- /dev/null +++ b/charts/planifets-backend/templates/app-deployment.yaml @@ -0,0 +1,56 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-{{ .Chart.Name }} + labels: + app: {{ .Chart.Name }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ .Chart.Name }} + template: + metadata: + labels: + app: {{ .Chart.Name }} + spec: + containers: + - name: app + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + ports: + - containerPort: {{ .Values.service.port }} + env: + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ .Values.postgresSecretName }} + key: DATABASE_URL + - name: NODE_ENV + value: production + - name: PORT + value: "{{ .Values.service.port }}" + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.port }} + initialDelaySeconds: 15 + periodSeconds: 20 + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.port }} + initialDelaySeconds: 5 + periodSeconds: 10 +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-{{ .Chart.Name }}-service +spec: + selector: + app: {{ .Chart.Name }} + ports: + - protocol: TCP + port: {{ .Values.service.port }} + targetPort: {{ .Values.service.port }} + type: {{ .Values.service.type }} diff --git a/charts/planifets-backend/templates/ingress.yaml b/charts/planifets-backend/templates/ingress.yaml new file mode 100644 index 0000000..e66ed5b --- /dev/null +++ b/charts/planifets-backend/templates/ingress.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ .Release.Name }}-{{ .Chart.Name }}-ingress +spec: + ingressClassName: nginx + rules: + - host: {{ (index .Values.ingress.hosts 0).host }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ .Release.Name }}-{{ .Chart.Name }}-service + port: + number: {{ .Values.service.port }} diff --git a/charts/planifets-backend/templates/postgres-pvc.yaml b/charts/planifets-backend/templates/postgres-pvc.yaml new file mode 100644 index 0000000..ae36da5 --- /dev/null +++ b/charts/planifets-backend/templates/postgres-pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi # todo \ No newline at end of file diff --git a/charts/planifets-backend/templates/postgres-secret.yaml b/charts/planifets-backend/templates/postgres-secret.yaml new file mode 100644 index 0000000..ddf3ef4 --- /dev/null +++ b/charts/planifets-backend/templates/postgres-secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Values.postgresSecretName }} +type: Opaque +stringData: + POSTGRES_USER: {{ .Values.postgres.user }} + POSTGRES_PASSWORD: {{ .Values.postgres.password }} + POSTGRES_DB: {{ .Values.postgres.db }} + DATABASE_URL: "postgresql://{{ .Values.postgres.user }}:{{ .Values.postgres.password }}@postgres:5432/{{ .Values.postgres.db }}?schema=public" diff --git a/charts/planifets-backend/templates/postgres.yaml b/charts/planifets-backend/templates/postgres.yaml new file mode 100644 index 0000000..42dc642 --- /dev/null +++ b/charts/planifets-backend/templates/postgres.yaml @@ -0,0 +1,73 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres + labels: + app: postgres +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:16 + ports: + - containerPort: 5432 + env: + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: {{ .Values.postgresSecretName }} + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: {{ .Values.postgresSecretName }} + key: POSTGRES_PASSWORD + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: {{ .Values.postgresSecretName }} + key: POSTGRES_DB + volumeMounts: + - name: postgres-storage + mountPath: /var/lib/postgresql/data + livenessProbe: + exec: + command: + - pg_isready + - -U + - {{ .Values.postgres.user }} + initialDelaySeconds: 30 + periodSeconds: 10 + readinessProbe: + exec: + command: + - pg_isready + - -U + - {{ .Values.postgres.user }} + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: postgres-storage + persistentVolumeClaim: + claimName: postgres-pvc +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres +spec: + selector: + app: postgres + ports: + - port: 5432 + targetPort: 5432 + protocol: TCP + type: ClusterIP diff --git a/charts/planifets-backend/values.yaml b/charts/planifets-backend/values.yaml new file mode 100644 index 0000000..6484048 --- /dev/null +++ b/charts/planifets-backend/values.yaml @@ -0,0 +1,26 @@ +replicaCount: 1 + +image: + repository: ghcr.io/applets/planifets-backend + pullPolicy: Always + tag: 'pr-47' # todo + +imagePullSecrets: [] +nameOverride: '' +fullnameOverride: '' + +service: + port: 3000 + type: LoadBalancer + +postgres: + user: postgres # todo + password: bEL8BZZU^BF8Rqe9 # todo + db: planifetsDB # todo + +ingress: + enabled: true + hosts: + - host: localhost # fixme (not sure) + +postgresSecretName: postgres-secret From cd7ac6dd1838278f0590a029a733588a10cc2f09 Mon Sep 17 00:00:00 2001 From: Mohamed Idrissi Date: Wed, 6 Nov 2024 19:51:03 -0500 Subject: [PATCH 8/8] add quotes to prevent compilation error --- charts/planifets-backend/Chart.yaml | 2 +- .../templates/app-deployment.yaml | 14 +++++++------- charts/planifets-backend/templates/ingress.yaml | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/charts/planifets-backend/Chart.yaml b/charts/planifets-backend/Chart.yaml index b6d3969..4104841 100644 --- a/charts/planifets-backend/Chart.yaml +++ b/charts/planifets-backend/Chart.yaml @@ -3,4 +3,4 @@ name: planifets-backend description: A Helm chart for Kubernetes type: application version: 0.2.0 -appVersion: '0.1.0' \ No newline at end of file +appVersion: '0.1.0' diff --git a/charts/planifets-backend/templates/app-deployment.yaml b/charts/planifets-backend/templates/app-deployment.yaml index d7230b6..bd88a7b 100644 --- a/charts/planifets-backend/templates/app-deployment.yaml +++ b/charts/planifets-backend/templates/app-deployment.yaml @@ -1,18 +1,18 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ .Release.Name }}-{{ .Chart.Name }} + name: "{{ .Release.Name }}-{{ .Chart.Name }}" labels: - app: {{ .Chart.Name }} + app: "{{ .Chart.Name }}" spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: - app: {{ .Chart.Name }} + app: "{{ .Chart.Name }}" template: metadata: labels: - app: {{ .Chart.Name }} + app: "{{ .Chart.Name }}" spec: containers: - name: app @@ -23,7 +23,7 @@ spec: - name: DATABASE_URL valueFrom: secretKeyRef: - name: {{ .Values.postgresSecretName }} + name: "{{ .Values.postgresSecretName }}" key: DATABASE_URL - name: NODE_ENV value: production @@ -45,10 +45,10 @@ spec: apiVersion: v1 kind: Service metadata: - name: {{ .Release.Name }}-{{ .Chart.Name }}-service + name: "{{ .Release.Name }}-{{ .Chart.Name }}-service" spec: selector: - app: {{ .Chart.Name }} + app: "{{ .Chart.Name }}" ports: - protocol: TCP port: {{ .Values.service.port }} diff --git a/charts/planifets-backend/templates/ingress.yaml b/charts/planifets-backend/templates/ingress.yaml index e66ed5b..fc2b161 100644 --- a/charts/planifets-backend/templates/ingress.yaml +++ b/charts/planifets-backend/templates/ingress.yaml @@ -1,7 +1,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ .Release.Name }}-{{ .Chart.Name }}-ingress + name: "{{ .Release.Name }}-{{ .Chart.Name }}-ingress" spec: ingressClassName: nginx rules: @@ -12,6 +12,6 @@ spec: pathType: Prefix backend: service: - name: {{ .Release.Name }}-{{ .Chart.Name }}-service + name: "{{ .Release.Name }}-{{ .Chart.Name }}-service" port: number: {{ .Values.service.port }}