71 lines
1.8 KiB
YAML
71 lines
1.8 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build -t awesome-index:${{ github.sha }} .
|
|
docker tag awesome-index:${{ github.sha }} awesome-index:latest
|
|
|
|
deploy:
|
|
needs: build
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Deploy to server
|
|
uses: appleboy/ssh-action@master
|
|
with:
|
|
host: 114.134.187.170
|
|
username: root
|
|
password: ${{ secrets.SERVER_PASSWORD }}
|
|
script: |
|
|
# 创建部署目录
|
|
mkdir -p /app/awesome/data /app/awesome/logs
|
|
|
|
- name: Copy files to server
|
|
uses: appleboy/scp-action@master
|
|
with:
|
|
host: 114.134.187.170
|
|
username: root
|
|
password: ${{ secrets.SERVER_PASSWORD }}
|
|
source: "docker-compose.yml,start.sh"
|
|
target: "/app/awesome/"
|
|
|
|
- name: Load and start container
|
|
uses: appleboy/ssh-action@master
|
|
with:
|
|
host: 114.134.187.170
|
|
username: root
|
|
password: ${{ secrets.SERVER_PASSWORD }}
|
|
script: |
|
|
cd /app/awesome
|
|
|
|
# 停止旧容器
|
|
docker compose down --remove-orphans 2>/dev/null || true
|
|
|
|
# 启动新容器
|
|
docker compose up -d
|
|
|
|
# 等待启动
|
|
sleep 10
|
|
|
|
# 健康检查
|
|
curl -sf http://localhost:3000/healthz && echo " - 服务已启动" || echo " - 启动失败"
|