Skip to content

Commit

Permalink
Change CI/CD (#16)
Browse files Browse the repository at this point in the history
* Refactor CI/CD and change sqlite to postgres (#15)
  • Loading branch information
slavoyar authored Aug 17, 2024
1 parent c56b78f commit f1a413c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 59 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/develop.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
name: CI Pipeline for Development
name: Lint and build

on:
pull_request:
branches:
- develop # Trigger on pull requests to the develop branch
paths:
- 'frontend/**'
- 'backend/**'
push:
branches:
- develop # Also trigger on direct pushes to develop
- develop
paths:
- 'frontend/**'
- 'backend/**'
Expand Down Expand Up @@ -51,11 +45,6 @@ jobs:
working-directory: ./backend
run: npm install

- name: Create .env file
run: |
echo "DATABASE_URL=${{ secrets.DB_HOST }}" >> ./backend/.env
- name: Build backend
working-directory: ./backend
run: |
npm run build # If you have a build step, otherwise omit this
run: npm run build
57 changes: 15 additions & 42 deletions .github/workflows/production.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
name: CI/CD Pipeline
name: Deploy to server

on:
pull_request:
branches:
- production # Trigger on pull requests to the production branch
paths:
- 'frontend/**'
- 'backend/**'
push:
branches:
- production # Also trigger on direct pushes to production
paths:
- 'frontend/**'
- 'backend/**'
- production

jobs:
lint-build-frontend:
build-and-deploy-frontend:
runs-on: ubuntu-latest

steps:
Expand All @@ -29,32 +20,10 @@ jobs:
working-directory: ./frontend
run: npm install

- name: Lint frontend
working-directory: ./frontend
run: npm run lint

- name: Build frontend
working-directory: ./frontend
run: npm run build

- name: Archive production artifacts
if: success()
uses: actions/upload-artifact@v2
with:
name: frontend-build
path: ./frontend/dist

deploy-frontend:
runs-on: ubuntu-latest
needs: lint-build-frontend

steps:
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: frontend-build
path: ./frontend/dist

- name: Deploy to remote server
uses: easingthemes/ssh-deploy@main
with:
Expand All @@ -68,28 +37,32 @@ jobs:

build-and-deploy-backend:
runs-on: ubuntu-latest
needs: deploy-frontend

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2

- name: Install backend dependencies
working-directory: ./backend
run: npm install

- name: Create .env file
run: |
echo "DATABASE_URL=${{ secrets.DB_HOST }}" >> ./backend/.env
echo "DB_URL=${{ secrets.DB_URL }}" > ./backend/.env
echo "SESSION_SECRET_KEY=${{ secrets.SESSION_SECRET_KEY }}" >> ./backend/.env
echo "SALT_ROUNDS=${{ secrets.SALT_ROUNDS }}" >> ./backend/.env
echo "PORT=${{ secrets.PORT }}" >> ./backend/.env
- name: Migrate database
working-directory: ./backend
run: npm run migrate:prod

- name: Build backend
working-directory: ./backend
run: |
npm run migrate:prod
npm run build # If you have a build step, otherwise omit this
run: npm run build

- name: Deploy to Remote Server
uses: easingthemes/ssh-deploy@main
Expand All @@ -100,4 +73,4 @@ jobs:
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
TARGET: ${{ secrets.REMOTE_BACKEND_PATH }}
EXCLUDE: "prod.db"
EXCLUDE: "/node_modules/"
2 changes: 1 addition & 1 deletion backend/@types/nodejs/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace NodeJS {
interface ProcessEnv {
DATABASE_URL: string;
DB_URL: string;
SESSION_SECRET_KEY: string;
PORT?: string;
SALT_ROUNDS: string;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/configs/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ generator client {
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
provider = "postgresql"
url = env("DB_URL")
}

model Card {
Expand Down

0 comments on commit f1a413c

Please sign in to comment.