Merge branch 'main' of https://mybugs.work/i/Hapi-Docker
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
||||
# 必填:Hub 的认证令牌,CLI 连接时需要
|
||||
CLI_API_TOKEN=your-secure-token-here
|
||||
|
||||
# 必填:Hub 的公网地址(客户端访问用)
|
||||
# 可选:Hub 的公网地址(用于 Telegram 等回调)
|
||||
HAPI_PUBLIC_URL=http://your-server-ip:3006
|
||||
|
||||
# 可选:CORS 允许的域名(逗号分隔),默认 *
|
||||
# 可选:CORS 允许的域名(逗号分隔),默认 *。反向代理场景下 WebSocket 终端需要设为 *
|
||||
CORS_ORIGINS=*
|
||||
|
||||
# 可选:时区
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
name: Build and Release HAPI
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
repository:
|
||||
description: 'Source repository (e.g. tiann/hapi or arkylin/hapi)'
|
||||
required: true
|
||||
default: 'tiann/hapi'
|
||||
ref:
|
||||
description: 'Git ref (branch, tag, or commit SHA)'
|
||||
required: true
|
||||
default: 'main'
|
||||
docker_tag:
|
||||
description: 'Docker image tag (e.g. origin, self, custom)'
|
||||
required: true
|
||||
default: 'origin'
|
||||
release_tag:
|
||||
description: 'Release tag (leave empty to skip binary release)'
|
||||
required: false
|
||||
build_docker:
|
||||
description: 'Build and push Docker image'
|
||||
type: boolean
|
||||
default: true
|
||||
release_binaries:
|
||||
description: 'Release binaries'
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Checkout hapi source
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ github.event.inputs.repository }}
|
||||
ref: ${{ github.event.inputs.ref }}
|
||||
path: hapi-src
|
||||
|
||||
- name: Get version info
|
||||
id: info
|
||||
working-directory: hapi-src
|
||||
run: |
|
||||
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||
VERSION=$(jq -r '.version' cli/package.json)
|
||||
echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
|
||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||
echo "Building version $VERSION @ $SHORT_SHA"
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: 1.3.14
|
||||
|
||||
- name: Build all platform binaries
|
||||
working-directory: hapi-src
|
||||
run: |
|
||||
bun install
|
||||
bun run build:single-exe:all
|
||||
|
||||
- name: Copy binaries for Docker
|
||||
if: ${{ github.event.inputs.build_docker == 'true' }}
|
||||
run: |
|
||||
mkdir -p self
|
||||
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi self/hapi-amd64
|
||||
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi self/hapi-arm64
|
||||
|
||||
- uses: docker/setup-qemu-action@v3
|
||||
if: ${{ github.event.inputs.build_docker == 'true' }}
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
if: ${{ github.event.inputs.build_docker == 'true' }}
|
||||
|
||||
- uses: docker/login-action@v3
|
||||
if: ${{ github.event.inputs.build_docker == 'true' }}
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract Docker metadata
|
||||
id: meta
|
||||
if: ${{ github.event.inputs.build_docker == 'true' }}
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=raw,value=${{ github.event.inputs.docker_tag }}
|
||||
|
||||
- uses: docker/build-push-action@v6
|
||||
if: ${{ github.event.inputs.build_docker == 'true' }}
|
||||
with:
|
||||
context: ./self
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Prepare release artifacts
|
||||
if: ${{ github.event.inputs.release_binaries == 'true' && github.event.inputs.release_tag != '' }}
|
||||
run: |
|
||||
mkdir -p release
|
||||
cp hapi-src/cli/dist-exe/bun-linux-x64-baseline/hapi release/hapi-linux-x64
|
||||
cp hapi-src/cli/dist-exe/bun-linux-arm64/hapi release/hapi-linux-arm64
|
||||
cp hapi-src/cli/dist-exe/bun-darwin-x64/hapi release/hapi-darwin-x64
|
||||
cp hapi-src/cli/dist-exe/bun-darwin-arm64/hapi release/hapi-darwin-arm64
|
||||
cp hapi-src/cli/dist-exe/bun-windows-x64/hapi.exe release/hapi-windows-x64.exe
|
||||
ls -la release/
|
||||
|
||||
- name: Create Release
|
||||
if: ${{ github.event.inputs.release_binaries == 'true' && github.event.inputs.release_tag != '' }}
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ github.event.inputs.release_tag }}
|
||||
name: ${{ github.event.inputs.release_tag }} (${{ steps.info.outputs.short_sha }})
|
||||
body: |
|
||||
HAPI binaries built from [${{ github.event.inputs.repository }}](https://github.com/${{ github.event.inputs.repository }}) `${{ github.event.inputs.ref }}`.
|
||||
|
||||
- Version: ${{ steps.info.outputs.version }}
|
||||
- Commit: `${{ steps.info.outputs.short_sha }}`
|
||||
files: release/*
|
||||
fail_on_unmatched_files: true
|
||||
@@ -1,2 +1,3 @@
|
||||
.env
|
||||
hapi-data/
|
||||
self/hapi-*
|
||||
|
||||
@@ -30,8 +30,11 @@ services:
|
||||
- CLI_API_TOKEN=这里填一个只有你知道的随机字符串
|
||||
- HAPI_LISTEN_HOST=0.0.0.0
|
||||
- HAPI_LISTEN_PORT=3006
|
||||
- CORS_ORIGINS=*
|
||||
```
|
||||
|
||||
> 如果使用 nginx 反向代理,必须设置 `CORS_ORIGINS=*`,否则 Web 终端(Socket.IO WebSocket)会因 CORS 校验失败返回 403。
|
||||
|
||||
### 3. 启动
|
||||
|
||||
```bash
|
||||
@@ -306,7 +309,7 @@ docker exec hapi-hub hapi runner start --foreground
|
||||
|------|------|--------|------|
|
||||
| `CLI_API_TOKEN` | 是 | - | 认证令牌,CLI 和 Web 登录使用 |
|
||||
| `HAPI_PUBLIC_URL` | 否 | - | Hub 公网地址(用于 Telegram 等回调) |
|
||||
| `CORS_ORIGINS` | 否 | `*` | 允许的 CORS 域名 |
|
||||
| `CORS_ORIGINS` | 否 | `*` | 允许的 CORS 域名。反向代理(如 nginx)场景下 WebSocket 终端必设 `*` |
|
||||
| `TZ` | 否 | `Asia/Shanghai` | 时区 |
|
||||
|
||||
## 持久化数据
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG TARGETARCH
|
||||
COPY hapi-${TARGETARCH} /usr/local/bin/hapi
|
||||
RUN chmod +x /usr/local/bin/hapi
|
||||
|
||||
RUN mkdir -p /root/.hapi
|
||||
|
||||
EXPOSE 3006
|
||||
|
||||
ENV HAPI_LISTEN_HOST=0.0.0.0
|
||||
ENV HAPI_LISTEN_PORT=3006
|
||||
|
||||
ENTRYPOINT ["hapi"]
|
||||
CMD ["hub"]
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64)
|
||||
HAPI_ARCH="amd64"
|
||||
BINARY_DIR="bun-linux-x64-baseline"
|
||||
;;
|
||||
aarch64|arm64)
|
||||
HAPI_ARCH="arm64"
|
||||
BINARY_DIR="bun-linux-arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
BUILD_DIR=$(mktemp -d)
|
||||
trap 'rm -rf "$BUILD_DIR"' EXIT
|
||||
|
||||
echo "Cloning tiann/hapi@main into $BUILD_DIR ..."
|
||||
git clone --depth 1 --branch main https://github.com/tiann/hapi.git "$BUILD_DIR"
|
||||
|
||||
cd "$BUILD_DIR"
|
||||
bun install
|
||||
bun run build:single-exe
|
||||
|
||||
BINARY_PATH="$BUILD_DIR/cli/dist-exe/$BINARY_DIR/hapi"
|
||||
if [ ! -f "$BINARY_PATH" ]; then
|
||||
echo "Binary not found: $BINARY_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$BINARY_PATH" "$SCRIPT_DIR/hapi-${HAPI_ARCH}"
|
||||
|
||||
docker build \
|
||||
--build-arg "TARGETARCH=${HAPI_ARCH}" \
|
||||
-t "hapi:origin" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" \
|
||||
"$SCRIPT_DIR/"
|
||||
|
||||
rm -f "$SCRIPT_DIR/hapi-${HAPI_ARCH}"
|
||||
|
||||
echo "Built hapi:origin for ${HAPI_ARCH}"
|
||||
@@ -0,0 +1,19 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ARG TARGETARCH
|
||||
COPY hapi-${TARGETARCH} /usr/local/bin/hapi
|
||||
RUN chmod +x /usr/local/bin/hapi
|
||||
|
||||
RUN mkdir -p /root/.hapi
|
||||
|
||||
EXPOSE 3006
|
||||
|
||||
ENV HAPI_LISTEN_HOST=0.0.0.0
|
||||
ENV HAPI_LISTEN_PORT=3006
|
||||
|
||||
ENTRYPOINT ["hapi"]
|
||||
CMD ["hub"]
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HAPI_DIR="$(cd "$SCRIPT_DIR/../../hapi" && pwd)"
|
||||
|
||||
ARCH=$(uname -m)
|
||||
case "$ARCH" in
|
||||
x86_64)
|
||||
HAPI_ARCH="amd64"
|
||||
BINARY_DIR="bun-linux-x64-baseline"
|
||||
;;
|
||||
aarch64|arm64)
|
||||
HAPI_ARCH="arm64"
|
||||
BINARY_DIR="bun-linux-arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
BINARY_PATH="$HAPI_DIR/cli/dist-exe/$BINARY_DIR/hapi"
|
||||
if [ ! -f "$BINARY_PATH" ]; then
|
||||
echo "Binary not found: $BINARY_PATH"
|
||||
echo "Please build hapi first: cd ../hapi && bun run build:single-exe"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp "$BINARY_PATH" "$SCRIPT_DIR/hapi-${HAPI_ARCH}"
|
||||
|
||||
docker build \
|
||||
--build-arg "TARGETARCH=${HAPI_ARCH}" \
|
||||
-t "hapi:self" \
|
||||
-f "$SCRIPT_DIR/Dockerfile" \
|
||||
"$SCRIPT_DIR/"
|
||||
|
||||
rm -f "$SCRIPT_DIR/hapi-${HAPI_ARCH}"
|
||||
|
||||
echo "Built hapi:self for ${HAPI_ARCH}"
|
||||
Reference in New Issue
Block a user