-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (54 loc) · 1.52 KB
/
deploy.yml
File metadata and controls
68 lines (54 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: CI + Deploy to VPS
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: deploy-nextjs-main
cancel-in-progress: false
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test -- --runInBand
deploy:
runs-on: ubuntu-latest
needs: test
environment: production
steps:
- name: Deploy over SSH
uses: appleboy/ssh-action@v1.2.0
env:
DEPLOY_BRANCH: main
DEPLOY_PATH: ${{ vars.VPS_NEXTJS_APP_DIR }}
IMAGE_NAME: nextjs-app
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
script_stop: true
envs: DEPLOY_BRANCH,DEPLOY_PATH,IMAGE_NAME
script: |
set -euo pipefail
cd "$DEPLOY_PATH"
git fetch origin "$DEPLOY_BRANCH"
git checkout "$DEPLOY_BRANCH"
git reset --hard "origin/$DEPLOY_BRANCH"
docker build -t "$IMAGE_NAME" .
cd ~/app
docker compose up -d mysql_nextjs redis
docker compose run --rm -e RUN_MIGRATIONS=1 nextjs true
docker compose up -d nextjs
docker image prune -f