Skip to content

Commit ca1b64e

Browse files
committed
build改为服务器build避免超时
1 parent caa6eca commit ca1b64e

2 files changed

Lines changed: 11 additions & 53 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,35 @@ on:
55
branches: [main]
66
workflow_dispatch:
77

8-
env:
9-
REGISTRY: ghcr.io
10-
IMAGE_NAME: ghcr.io/involutionhell/involutionhell-backend
11-
128
jobs:
13-
build-and-push:
14-
name: 编译 Native Image 并推送到 GHCR
15-
runs-on: ubuntu-latest
16-
permissions:
17-
contents: read
18-
packages: write
19-
20-
steps:
21-
- name: 检出代码
22-
uses: actions/checkout@v4
23-
24-
- name: 登录 GitHub Container Registry
25-
uses: docker/login-action@v3
26-
with:
27-
registry: ${{ env.REGISTRY }}
28-
username: ${{ github.actor }}
29-
password: ${{ secrets.GITHUB_TOKEN }}
30-
31-
- name: 设置 Docker Buildx
32-
uses: docker/setup-buildx-action@v3
33-
34-
- name: 构建并推送镜像
35-
uses: docker/build-push-action@v6
36-
with:
37-
context: .
38-
push: true
39-
platforms: linux/arm64
40-
tags: |
41-
${{ env.IMAGE_NAME }}:latest
42-
${{ env.IMAGE_NAME }}:${{ github.sha }}
43-
cache-from: type=gha
44-
cache-to: type=gha,mode=max
45-
469
deploy:
47-
name: SSH 部署到服务器
10+
name: 在服务器上编译并部署
4811
runs-on: ubuntu-latest
49-
needs: build-and-push
5012
environment: production
5113

5214
steps:
53-
- name: 检出代码(仅获取 docker-compose.yml 和 Caddyfile)
54-
uses: actions/checkout@v4
55-
56-
- name: 将 compose 文件同步到服务器
15+
- name: 将源码同步到服务器
5716
uses: appleboy/scp-action@v0.1.7
5817
with:
5918
host: ${{ secrets.SERVER_HOST }}
6019
username: ${{ secrets.SERVER_USER }}
6120
key: ${{ secrets.SERVER_SSH_KEY }}
62-
source: "docker-compose.yml,Caddyfile,docker/"
21+
source: "."
6322
target: "/home/ubuntu/involution-hell"
6423

65-
- name: 远程执行部署
24+
- name: 在服务器上构建并启动
6625
uses: appleboy/ssh-action@v1
6726
with:
6827
host: ${{ secrets.SERVER_HOST }}
6928
username: ${{ secrets.SERVER_USER }}
7029
key: ${{ secrets.SERVER_SSH_KEY }}
30+
# 命令超时设长一点,Native Image 编译需要时间
31+
command_timeout: 30m
7132
script: |
7233
cd /home/ubuntu/involution-hell
7334
74-
# 写入镜像名,确保拉取最新
75-
export BACKEND_IMAGE_NAME=${{ env.IMAGE_NAME }}:${{ github.sha }}
35+
# 构建新镜像(失败则整个 workflow 标红)
36+
docker build -t involutionhell-backend:latest .
7637
77-
# 登录 GHCR 后拉取镜像并重启服务
78-
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
79-
docker compose pull backend
38+
# 用新镜像重启服务
8039
docker compose up -d --remove-orphans

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
services:
22
backend:
3-
image: ${BACKEND_IMAGE_NAME:-ghcr.io/involutionhell/involutionhell-backend:latest}
4-
platform: linux/arm64
5-
pull_policy: always
3+
image: involutionhell-backend:latest
4+
pull_policy: never
65
container_name: involution-hell-backend
76
restart: always
87
env_file:

0 commit comments

Comments
 (0)