Skip to content

Commit

Permalink
chore: deploy workflow manually
Browse files Browse the repository at this point in the history
  • Loading branch information
sobird committed Nov 20, 2024
1 parent 42be4f7 commit 95f41c3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
public
assets
58 changes: 37 additions & 21 deletions .github/workflows/nextjs.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#
# To get started with Next.js see: https://nextjs.org/docs/getting-started
#
name: Build and Deploy SSR
name: Deploy Mix

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
# push:
# branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -30,60 +30,76 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "22"
registry-url: https://registry.npmjs.org/
# cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Restore cache node_modules
id: cache-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
**/node_modules
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package.json') }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
restore-keys: ${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: yarn
- name: Build ☕️
run: yarn build

- name: Copy Files
run: |
cp pm2.config.js .next
cp -r .next/static .next/standalone/.next
- name: Deploy node_modules 🚀
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: cp pm2.config.js .next/standalone

- name: Deploy Standalone 🚀
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: ".next/standalone/**"
target: ${{ secrets.TARGET }}
source: "node_modules/**"
strip_components: 0
- name: Deploy public 🚀
strip_components: 2

- name: Deploy Static 🚀
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: ".next/static/**"
target: ${{ secrets.TARGET }}
source: "public/**"
strip_components: 0
- name: Deploy SSR 🚀

# - name: Deploy node_modules 🚀
# if: steps.cache-dependencies.outputs.cache-hit != 'true'
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.HOST }}
# username: ${{ secrets.USERNAME }}
# key: ${{ secrets.KEY }}
# port: ${{ secrets.PORT }}
# target: ${{ secrets.TARGET }}
# source: "node_modules/**"
# strip_components: 0

- name: Deploy public 🚀
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: ".next/standalone/**,.next/package.json,.next/pm2.config.js"
target: ${{ secrets.TARGET }}
strip_components: 1
- name: Reload SSR
source: "public/**"
strip_components: 0

- name: Reload Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
Expand Down
52 changes: 26 additions & 26 deletions pm2.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ module.exports = {
/** application name (default to script filename without extension) */
name: 'mix',
/** script path relative to pm2 start */
script: 'standalone/server.js',
script: 'server.js',
// args: '-p 3000',
/** the directory from which your app will be launched */
// cwd: "",
/** true by default. if false, PM2 will not restart your app if it crashes or ends peacefully */
autorestart: true,
/** enable watch & restart feature, if a file change in the folder or subfolder, your app will get reloaded */
watch: false,
// watch: false,
/** Delay between restart */
watch_delay: 1000,
// watch_delay: 1000,
/** list of regex to ignore some file or folder names by the watch feature */
ignore_watch: [
'public',
'node_modules',
],
// ignore_watch: [
// 'public',
// 'node_modules',
// ],
/**
* PM2 is giving chokidar these Default options:
* watch_options: {
Expand All @@ -33,34 +33,34 @@ module.exports = {
* }
* @see https://github.com/paulmillr/chokidar#api
*/
watch_options: {
followSymlinks: false,
},
// watch_options: {
// followSymlinks: false,
// },
/** The interpreter used. */
exec_interpreter: 'bash',
// exec_interpreter: 'bash',
/** alias to interpreter_args */
// node_args: "--harmony",
/**
* 启用多少个实例,可用于负载均衡
* 如果设为 0或者 max,则根据当前机器核数确定实例数目。
*/
instances: 0,
// instances: 0,
/** mode to start your app, can be “cluster” or “fork”, default fork */
exec_mode: 'cluster_mode',
// exec_mode: 'cluster_mode',

log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
// log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
}],

deploy: {
production: {
user: 'SSH_USERNAME',
host: 'SSH_HOSTMACHINE',
ref: 'origin/master',
repo: 'GIT_REPOSITORY',
path: 'DESTINATION_PATH',
'pre-deploy-local': '',
'post-deploy': 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': '',
},
},
// deploy: {
// production: {
// user: 'SSH_USERNAME',
// host: 'SSH_HOSTMACHINE',
// ref: 'origin/master',
// repo: 'GIT_REPOSITORY',
// path: 'DESTINATION_PATH',
// 'pre-deploy-local': '',
// 'post-deploy': 'npm install && pm2 reload ecosystem.config.js --env production',
// 'pre-setup': '',
// },
// },
};

0 comments on commit 95f41c3

Please sign in to comment.