Skip to content

Deploy Dashboard

Deploy Dashboard #40

name: Deploy Frontend
on:
# Production deployment is explicit and independent from Backend, Hub, and Collectors.
workflow_dispatch:
env:
IMAGE: ghcr.io/shenxianovo/heartbeat-frontend
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm ci
working-directory: frontend
- name: Type check
run: npm run typecheck
working-directory: frontend
- name: Test
run: npm test
working-directory: frontend
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./frontend
push: true
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:sha-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest
concurrency: deploy-frontend-production
steps:
- uses: actions/checkout@v4
- name: Sync compose.yml to server
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: compose.yml
target: /srv/heartbeat
- name: Pull and restart frontend container
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
set -eu
cd /srv/heartbeat
docker compose pull frontend
docker compose up -d --no-deps frontend
docker compose ps frontend