-
Notifications
You must be signed in to change notification settings - Fork 21
85 lines (70 loc) · 2.82 KB
/
deploy-to-vps.old.yaml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# This is a basic workflow to help you get started with Actions
name: CI/CD For the Deployment
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
# push:
# branches:
# - main
# Allows you to run this workflow manually from the Actions tab+1
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest
environment: production
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_SERVER_KEY }}
name: id_rsa # optional
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Deploy to Server
run: |
echo Copying env files...
cat > .env.local << EOF
NEXT_PUBLIC_VERCEL_URL="gh.fredkiss.dev"
SESSION_SECRET=${{ secrets.SESSION_SECRET }}
DATABASE_URL=${{ secrets.POSTGRES_DB_URL }}
GITHUB_CLIENT_ID=${{ secrets.GH_CLIENT_ID }}
GITHUB_REDIRECT_URI="https://gh.fredkiss.dev/api/auth/callback"
GITHUB_SECRET=${{ secrets.GH_SECRET }}
GITHUB_PERSONAL_ACCESS_TOKEN=${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
REDIS_HTTP_URL="http://127.0.0.1:6380"
REDIS_HTTP_USERNAME=${{ secrets.REDIS_HTTP_USERNAME }}
REDIS_HTTP_PASSWORD=${{ secrets.REDIS_HTTP_PASSWORD }}
EOF
scp -P $DEPLOY_PORT ./.env.local $DEPLOY_USER@$DEPLOY_DOMAIN:$DEPLOY_DIR/.env.local
echo env copied ✅
ssh -p $DEPLOY_PORT $DEPLOY_USER@$DEPLOY_DOMAIN "
source ~/.zshrc
set -e -o errexit
cd $DEPLOY_DIR
echo use node version 20
nvm use 20
echo Pulling latest version...
git pull origin ${GITHUB_REF##*/}
echo Building packages...
pnpm install --shamefully-hoist --strict-peer-dependencies=false --frozen-lockfile
# Return to root dir
cd $DEPLOY_DIR
pnpm run db:migrate
pnpm run build
echo build success ✅
# Copy standalone static files
rsync -a .next/static/ .next/standalone/.next/static
cp .env.local .next/standalone/.env.local
# Start 3 pm2 processes
echo Starting processes...
pm2 startOrReload ecosystem.config.cjs --update-env
echo processes succesfully started ✅
"
env:
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }}
DEPLOY_DOMAIN: ${{ secrets.DEPLOY_DOMAIN }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}