ZhaoShanGeng
commited on
Commit
·
d842c73
1
Parent(s):
b8044d3
feat: 添加二进制 Docker 镜像支持
Browse files- 添加 Dockerfile.binary 用于二进制构建
- 修改 docker-publish.yml 支持 binary-build 分支的二进制构建
- 修改 build-binaries.yml 自动发布 Release
- binary-build 分支专用的实验性功能
- .github/workflows/build-binaries.yml +21 -5
- .github/workflows/docker-publish.yml +56 -1
- Dockerfile.binary +38 -0
.github/workflows/build-binaries.yml
CHANGED
|
@@ -2,8 +2,7 @@ name: Build Binaries
|
|
| 2 |
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
-
branches: [ 'binary-build'
|
| 6 |
-
tags: [ 'v*' ]
|
| 7 |
workflow_dispatch:
|
| 8 |
inputs:
|
| 9 |
platforms:
|
|
@@ -91,7 +90,6 @@ jobs:
|
|
| 91 |
release:
|
| 92 |
needs: build
|
| 93 |
runs-on: ubuntu-latest
|
| 94 |
-
if: startsWith(github.ref, 'refs/tags/v')
|
| 95 |
permissions:
|
| 96 |
contents: write
|
| 97 |
|
|
@@ -106,14 +104,32 @@ jobs:
|
|
| 106 |
echo "=== Downloaded artifacts ==="
|
| 107 |
find artifacts -type f -ls
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
- name: Create Release
|
| 110 |
uses: softprops/action-gh-release@v1
|
| 111 |
with:
|
|
|
|
|
|
|
| 112 |
files: |
|
| 113 |
artifacts/**/*.zip
|
| 114 |
artifacts/**/*.tar.gz
|
| 115 |
-
generate_release_notes:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
draft: false
|
| 117 |
-
prerelease:
|
| 118 |
env:
|
| 119 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
| 2 |
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
+
branches: [ 'binary-build' ]
|
|
|
|
| 6 |
workflow_dispatch:
|
| 7 |
inputs:
|
| 8 |
platforms:
|
|
|
|
| 90 |
release:
|
| 91 |
needs: build
|
| 92 |
runs-on: ubuntu-latest
|
|
|
|
| 93 |
permissions:
|
| 94 |
contents: write
|
| 95 |
|
|
|
|
| 104 |
echo "=== Downloaded artifacts ==="
|
| 105 |
find artifacts -type f -ls
|
| 106 |
|
| 107 |
+
- name: Get short SHA
|
| 108 |
+
id: sha
|
| 109 |
+
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
| 110 |
+
|
| 111 |
- name: Create Release
|
| 112 |
uses: softprops/action-gh-release@v1
|
| 113 |
with:
|
| 114 |
+
tag_name: binary-${{ steps.sha.outputs.short }}
|
| 115 |
+
name: Binary Build ${{ steps.sha.outputs.short }}
|
| 116 |
files: |
|
| 117 |
artifacts/**/*.zip
|
| 118 |
artifacts/**/*.tar.gz
|
| 119 |
+
generate_release_notes: false
|
| 120 |
+
body: |
|
| 121 |
+
自动构建的二进制文件 (实验性)
|
| 122 |
+
|
| 123 |
+
分支: `binary-build`
|
| 124 |
+
提交: ${{ github.sha }}
|
| 125 |
+
|
| 126 |
+
## 下载
|
| 127 |
+
- Windows x64: `antigravity-win-x64.zip`
|
| 128 |
+
- Linux x64: `antigravity-linux-x64.tar.gz`
|
| 129 |
+
- Linux ARM64 (Termux): `antigravity-linux-arm64.tar.gz`
|
| 130 |
+
- macOS x64: `antigravity-macos-x64.tar.gz`
|
| 131 |
+
- macOS ARM64: `antigravity-macos-arm64.tar.gz`
|
| 132 |
draft: false
|
| 133 |
+
prerelease: true
|
| 134 |
env:
|
| 135 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
.github/workflows/docker-publish.yml
CHANGED
|
@@ -23,6 +23,46 @@ jobs:
|
|
| 23 |
- name: Checkout
|
| 24 |
uses: actions/checkout@v4
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
- name: Set up Docker Buildx
|
| 27 |
uses: docker/setup-buildx-action@v3
|
| 28 |
|
|
@@ -45,7 +85,22 @@ jobs:
|
|
| 45 |
type=semver,pattern={{major}}.{{minor}}
|
| 46 |
type=raw,value=latest,enable={{is_default_branch}}
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
uses: docker/build-push-action@v5
|
| 50 |
with:
|
| 51 |
context: .
|
|
|
|
| 23 |
- name: Checkout
|
| 24 |
uses: actions/checkout@v4
|
| 25 |
|
| 26 |
+
# 检查是否是 binary-build 分支
|
| 27 |
+
- name: Check if binary build branch
|
| 28 |
+
id: check_branch
|
| 29 |
+
run: |
|
| 30 |
+
if [[ "${{ github.ref }}" == "refs/heads/binary-build" ]] || [[ "${{ github.ref }}" == refs/heads/release/* ]]; then
|
| 31 |
+
echo "is_binary=true" >> $GITHUB_OUTPUT
|
| 32 |
+
else
|
| 33 |
+
echo "is_binary=false" >> $GITHUB_OUTPUT
|
| 34 |
+
fi
|
| 35 |
+
|
| 36 |
+
# 二进制构建:先编译再构建 Docker
|
| 37 |
+
- name: Setup Node.js (for binary build)
|
| 38 |
+
if: steps.check_branch.outputs.is_binary == 'true'
|
| 39 |
+
uses: actions/setup-node@v4
|
| 40 |
+
with:
|
| 41 |
+
node-version: '18'
|
| 42 |
+
cache: 'npm'
|
| 43 |
+
|
| 44 |
+
- name: Install dependencies (for binary build)
|
| 45 |
+
if: steps.check_branch.outputs.is_binary == 'true'
|
| 46 |
+
run: npm ci
|
| 47 |
+
|
| 48 |
+
- name: Build Linux binary
|
| 49 |
+
if: steps.check_branch.outputs.is_binary == 'true'
|
| 50 |
+
run: npm run build:linux
|
| 51 |
+
|
| 52 |
+
- name: List dist contents
|
| 53 |
+
if: steps.check_branch.outputs.is_binary == 'true'
|
| 54 |
+
run: |
|
| 55 |
+
echo "=== dist directory contents ==="
|
| 56 |
+
ls -la dist/
|
| 57 |
+
echo "=== bin directory ==="
|
| 58 |
+
ls -la dist/bin/ || echo "No bin directory"
|
| 59 |
+
|
| 60 |
+
- name: Set executable permissions
|
| 61 |
+
if: steps.check_branch.outputs.is_binary == 'true'
|
| 62 |
+
run: |
|
| 63 |
+
chmod +x dist/antigravity-linux-x64
|
| 64 |
+
chmod +x dist/bin/* || true
|
| 65 |
+
|
| 66 |
- name: Set up Docker Buildx
|
| 67 |
uses: docker/setup-buildx-action@v3
|
| 68 |
|
|
|
|
| 85 |
type=semver,pattern={{major}}.{{minor}}
|
| 86 |
type=raw,value=latest,enable={{is_default_branch}}
|
| 87 |
|
| 88 |
+
# 二进制构建使用 Dockerfile.binary
|
| 89 |
+
- name: Build and push (binary)
|
| 90 |
+
if: steps.check_branch.outputs.is_binary == 'true'
|
| 91 |
+
uses: docker/build-push-action@v5
|
| 92 |
+
with:
|
| 93 |
+
context: .
|
| 94 |
+
file: ./Dockerfile.binary
|
| 95 |
+
push: true
|
| 96 |
+
tags: ${{ steps.meta.outputs.tags }}
|
| 97 |
+
labels: ${{ steps.meta.outputs.labels }}
|
| 98 |
+
cache-from: type=gha
|
| 99 |
+
cache-to: type=gha,mode=max
|
| 100 |
+
|
| 101 |
+
# 源码构建使用默认 Dockerfile
|
| 102 |
+
- name: Build and push (source)
|
| 103 |
+
if: steps.check_branch.outputs.is_binary != 'true'
|
| 104 |
uses: docker/build-push-action@v5
|
| 105 |
with:
|
| 106 |
context: .
|
Dockerfile.binary
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 使用编译后的二进制文件运行
|
| 2 |
+
# 这个镜像更小,启动更快,内存占用更低
|
| 3 |
+
#
|
| 4 |
+
# 构建方式:
|
| 5 |
+
# 1. 先运行 npm run build:linux 生成 dist 目录
|
| 6 |
+
# 2. 然后运行 docker build -f Dockerfile.binary -t antigravity .
|
| 7 |
+
|
| 8 |
+
FROM debian:bookworm-slim
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
# 安装必要的运行时依赖
|
| 13 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 14 |
+
ca-certificates \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
+
|
| 17 |
+
# 复制编译后的文件(由 CI 工作流预先编译)
|
| 18 |
+
COPY dist/antigravity-linux-x64 /app/antigravity
|
| 19 |
+
COPY dist/public /app/public
|
| 20 |
+
COPY dist/bin /app/bin
|
| 21 |
+
COPY dist/config.json /app/config.json
|
| 22 |
+
COPY dist/.env.example /app/.env.example
|
| 23 |
+
|
| 24 |
+
# 设置执行权限
|
| 25 |
+
RUN chmod +x /app/antigravity && \
|
| 26 |
+
(chmod +x /app/bin/* 2>/dev/null || true)
|
| 27 |
+
|
| 28 |
+
# 创建数据和图片目录
|
| 29 |
+
RUN mkdir -p /app/data /app/public/images
|
| 30 |
+
|
| 31 |
+
# 复制 .env.example 为默认 .env
|
| 32 |
+
RUN cp /app/.env.example /app/.env
|
| 33 |
+
|
| 34 |
+
# 暴露端口
|
| 35 |
+
EXPOSE 8045
|
| 36 |
+
|
| 37 |
+
# 启动应用
|
| 38 |
+
CMD ["/app/antigravity"]
|