Skip to content

refactor: Improve code structure with error handling (#87) #13

refactor: Improve code structure with error handling (#87)

refactor: Improve code structure with error handling (#87) #13

Workflow file for this run

name: Server CI/CD
on:
push:
branches: [develop]
paths:
- "server/**"
- ".github/workflows/server-ci-cd.yml"
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: "9"
- name: Install dependencies
working-directory: ./server
run: pnpm install --frozen-lockfile
- name: Create .env file
working-directory: ./server
run: |
echo "REDIS_HOST=${{ secrets.REDIS_HOST }}" >> .env
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> .env
- name: Run tests
working-directory: ./server
run: pnpm test | true
docker-deploy:
needs: ci
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Docker Setup
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: ./server
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter:latest
build-args: |
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PORT=${{ secrets.REDIS_PORT }}
- name: Deploy to Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: mira
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter:latest
docker stop troublepainter || true
docker rm troublepainter || true
docker run -d --name troublepainter -p 3000:3000 -e REDIS_HOST=${{ secrets.REDIS_HOST }} -e REDIS_PORT=${{ secrets.REDIS_PORT }} --restart unless-stopped ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter:latest