Skip to content

Fontlay Deploy Prod #16

Fontlay Deploy Prod

Fontlay Deploy Prod #16

Workflow file for this run

name: Fontlay Deploy Prod
on:
workflow_dispatch:
push:
branches: [main]
paths-ignore:
- 'README.md'
- '.gitignore'
- '.gitattributes'
- '.vscode/**'
env:
APP_ARTIFACTS_NAME: fontlay-web
APP_BUILD_NAME: build-web
APP_DIR: /var/www/fontlay-web
BUILD_DIR: dist
jobs:
build:
name: Build
runs-on: ubuntu-latest
environment: build-production
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: '8'
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'pnpm'
# - uses: actions/cache@v3
# with:
# path: |
# ${{ github.workspace }}/.next/cache
# key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx') }}
# restore-keys: |
# ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- name: Create .env file πŸ”‘
run: |
touch .env
echo NEXT_TELEMETRY_DISABLED=1 >> .env
- name: Install dependencies πŸ‘¨πŸ»β€πŸ’»
run: pnpm install -no-frozen-lockfile
- name: Build Apps 🚦
run: pnpm build
- name: Build App Artifacts 🚧
run: |
mkdir ${{ env.BUILD_DIR }}
mv .env .nvmrc ecosystem.config.js ${{ env.BUILD_DIR }}
mv next.config.js public package.json .next ${{ env.BUILD_DIR }}
tar -czf ${{ env.APP_BUILD_NAME }}.tar.gz ${{ env.BUILD_DIR }}
- name: Upload Artifact ${{ env.APP_ARTIFACTS_NAME }} ✈️
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP_ARTIFACTS_NAME }}
path: ${{ env.APP_BUILD_NAME }}.tar.gz
deploy-prod:
name: Deploy Production
runs-on: ubuntu-latest
needs: [build]
environment: production
steps:
- name: Download Artifact ${{ env.APP_ARTIFACTS_NAME }} πŸ›¬
uses: actions/download-artifact@v3
with:
name: ${{ env.APP_ARTIFACTS_NAME }}
- name: Upload ${{ env.APP_BUILD_NAME }}.tar.gz πŸš€
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
source: ${{ env.APP_BUILD_NAME }}.tar.gz
target: ${{ env.APP_DIR }}
- name: Deploy to Ponyo πŸ˜„
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script_stop: true
script: |
cd ${{ env.APP_DIR }}
rm -rf dist
tar -xzf ${{ env.APP_BUILD_NAME }}.tar.gz && rm -rf ${{ env.APP_BUILD_NAME }}.tar.gz
cd ${{ env.APP_DIR }}/dist
nvm use
pnpm install -no-frozen-lockfile
pnpm pm2:restart
- name: Success Notification πŸ˜‰
uses: sarisia/actions-status-discord@v1.12.0
with:
webhook: ${{ secrets.WEBHOOK_DISCORD }}
status: 'Success'
title: 'fontlay back-end πŸŽ‰'
description: 'Deploy fontlay back-end to ponyo server.'
color: 0x99FF66
url: 'https://fontlay.com'
- name: Failed Notification 🀑
if: ${{ failure() }}
uses: sarisia/actions-status-discord@v1.12.0
with:
webhook: ${{ secrets.WEBHOOK_DISCORD }}
status: 'Failure'
content: 'Hey <@&735080822465495090>'
title: 'fontlay front-end πŸ₯΅'
description: 'Failed to deploy fontlay front-end.'
color: 0xF44336
clean-up:
name: Clean up Artifact
runs-on: ubuntu-latest
needs: [deploy-prod]
steps:
- uses: geekyeggo/delete-artifact@v1
with:
name: ${{ env.APP_ARTIFACTS_NAME }}