55 lines
1.4 KiB
YAML
55 lines
1.4 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
|
|
- name: Cache npm dependencies
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.npm
|
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-node-
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Build React app
|
|
run: npm run build
|
|
|
|
- name: Deploy files to Remote Server via rsync
|
|
uses: easingthemes/ssh-deploy@main
|
|
with:
|
|
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
|
REMOTE_HOST: ${{ secrets.SERVER_HOST }}
|
|
REMOTE_USER: ${{ secrets.SERVER_USER }}
|
|
TARGET: ${{ secrets.SERVER_TARGET_PATH }}
|
|
SOURCE: "dist/ Dockerfile docker-compose.yml"
|
|
ARGS: "-avz --delete"
|
|
|
|
- name: Run Docker container on Remote Server
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: ${{ secrets.SERVER_USER }}
|
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
|
script: |
|
|
cd ${{ secrets.SERVER_TARGET_PATH }}
|
|
docker compose down || true
|
|
docker compose up -d --build
|