Skip to content

Commit

Permalink
Create backend.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ckekula authored Oct 14, 2024
1 parent e59f366 commit 98c8a84
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: CI/CD Backend

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
ports:
- 5432:5432
env:
DATABASE_HOST: ${{ secrets.DATABASE_HOST }}
DATABASE_PORT: ${{ secrets.DATABASE_PORT }}
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18.19.1"

- name: Install dependencies
run: |
cd backend
npm install
- name: Set executable permissions
run: |
cd backend
chmod +x node_modules/.bin/eslint node_modules/.bin/jest
- name: Run lint
run: |
cd backend
npm run lint
- name: Run tests
env:
DATABASE_HOST: ${{ secrets.DATABASE_HOST }}
DATABASE_PORT: ${{ secrets.DATABASE_PORT }}
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
run: |
cd backend
npm test
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest -f backend/Dockerfile ./backend
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push Docker image
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
- name: Deploy to Render
if: github.ref == 'refs/heads/main'
env:
_API_KEY: ${{ secrets.RENDER_API_KEY }}
run: |
curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" -d '' https://api.render.com/deploy/srv-xxxxxxxxxxxxxxxxxx

0 comments on commit 98c8a84

Please sign in to comment.