- Git 钩子 (部署相关hooks仅支持私有服务器使用)
了解git裸仓库并利用post-receive自动化部署
部署git服务器实现自动发布代码
git init --bare projectA.git
touch projectA.git/hooks/post-receive
chmod 755 projectA.git/hooks/post-receive
vi projectA.git/hooks/post-receive
DIR=/data/publish/projectA
git --work-tree=${DIR} clean -fd
git --work-tree=${DIR} checkout --force
cd ${DIR}
chmod 755 build.sh
./build.sh
- Github Actions (需有外网访问通道供Github调用)
在 linux 服务器|上部署的 GitHub 操作
使用 Github Action 将静态页面发布到指定的服务器
使用GithubActions自动部署应用到自己的服务器
Github调戏Action手记——自动构建并发布到另一仓库
github action自动部署构建入门
Appleboy scp action master | Autoscripts.net
name: Auto Publish Website
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@main
- name: use Node.js 14
uses: actions/setup-node@main
with:
node-version: 14
- name: Build
uses: actions/setup-node@main
- run: npm install
- run: npm run build
- name: Deploy
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
port: "${{ secrets.SERVER_PORT }}"
password: ${{ secrets.SERVER_PASSWORD }}
source: ${{ secrets.Project_SOURCE }}
target: ${{ secrets.SERVER_TARGET }}