Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
61 changes: 61 additions & 0 deletions .github/workflows/backend-cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Backend CI/CD

on:
push:
branches: [ main, feature/my-active-tasks ]
paths:
- 'backend/**'
pull_request:
branches: [ main ]
paths:
- 'backend/**'

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: backend/package-lock.json

- name: Install Dependencies
run: |
cd backend
npm ci

- name: Build Backend
run: |
cd backend
npm run build


deploy:
needs: build-and-test
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main')

steps:
- name: Checkout Repository
uses: actions/checkout@v4


- name: Deploy to EC2 via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd ~/teamup
git pull origin main
cd backend
docker-compose down
docker-compose up --build -d
docker image prune -f
10 changes: 10 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
dist
src
.env
.git
.github
*.md
Dockerfile
.dockerignore
npm-debug.log
23 changes: 23 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . .
RUN npm run build

FROM node:18-alpine AS runner

WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules

EXPOSE 5000

ENV NODE_ENV=production

CMD ["npm", "start"]
14 changes: 14 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'

services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- "5000:5000"
env_file:
- .env
environment:
- NODE_ENV=production
restart: always