Skip to content

Improve background animation #108

Improve background animation

Improve background animation #108

name: Deploy Ardent Website to Production
# ABOUT
#
# This deployment script assumes the following are configured in GitHub actions:
#
# SSH_PRIVATE_KEY [secret]
# DEPLOY_HOST [variable]
# DEPLOY_USER [variable]
# DEPLOY_DIR [variable]
#
# Note:
# * DEPLOY_DIR should be an absolute path.
# * SERVICE_NAME should match the name of the repository in GitHub.
#
# This deployment script differs slightly from the other ardent deployment
# scripts. Updating the service in place would cause Next.js runtime errors
# during the build step. To avoid that, instead of simply updating the project
# and restarting it, it creates a copy of the current deployment, updates that
# copy and then swaps directories and restarts the service.
#
# SETUP
#
# This script assumes that Node.js is installed, that "pm2" is installed
# globally and that pm2 has been used to already run the program once, as the
# same user the deploy script will run as (which should not be root).
#
# How to install pm2 and configure pm2 to run at startup:
# npm i pm2 -g
# pm2 startup
#
# An example of how to start this program using pm2:
# export DEPLOY_DIR=/opt/ardent
# export SERVICE_NAME=ardent-www
# cd $DEPLOY_DIR}/SERVICE_NAME
# pm2 start npm --name "$SERVICE_NAME" -- run start
# pm2 save
on:
push:
branches: [ "main" ]
env:
SERVICE_NAME: ${{ github.event.repository.name }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Generate env.GITH_SHA_SHORT
run: echo "GIT_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Deploy to Server
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i"
SOURCE: "./"
REMOTE_HOST: ${{ vars.DEPLOY_HOST }}
REMOTE_USER: ${{ vars.DEPLOY_USER }}
TARGET: "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}-${{ env.GIT_SHA_SHORT}}"
EXCLUDE: ".git*, *.md, .next, LICENSE, node_modules/"
SCRIPT_BEFORE: |
rm -rf "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}.tmp"
cp -R "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}" "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}-${{ env.GIT_SHA_SHORT}}" || :
SCRIPT_AFTER: |
cd "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}-${{ env.GIT_SHA_SHORT}}"
npm install --omit=dev
npm run build
cd ..
mv "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}" "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}.tmp" || :
mv "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}-${{ env.GIT_SHA_SHORT}}" "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}"
pm2 restart "${{ env.SERVICE_NAME }}"
pm2 save
rm -rf "${{ vars.DEPLOY_DIR }}/${{ env.SERVICE_NAME }}.tmp"
echo $RSYNC_STDOUT