init: HAPI Hub Docker 部署 (Dockerfile + docker-compose + GHCR workflow)
Build and Push Docker Image to GHCR / build-and-push (push) Has been cancelled
Build and Push Docker Image to GHCR / build-and-push (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# 必填:Hub 的认证令牌,CLI 连接时需要
|
||||
CLI_API_TOKEN=your-secure-token-here
|
||||
|
||||
# 必填:Hub 的公网地址(客户端访问用)
|
||||
HAPI_PUBLIC_URL=http://your-server-ip:3006
|
||||
|
||||
# 可选:CORS 允许的域名(逗号分隔),默认 *
|
||||
CORS_ORIGINS=*
|
||||
|
||||
# 可选:时区
|
||||
TZ=Asia/Shanghai
|
||||
@@ -0,0 +1,51 @@
|
||||
name: Build and Push Docker Image to GHCR
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*"]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
REGISTRY: ghcr.io
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: docker/setup-qemu-action@v3
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
- uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=sha,prefix=,suffix=,format=short
|
||||
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
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
|
||||
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
hapi-data/
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
FROM node:20-slim AS build
|
||||
|
||||
RUN npm install -g @twsxtd/hapi --registry=https://registry.npmjs.org
|
||||
|
||||
FROM node:20-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY --from=build /usr/local/lib/node_modules /usr/local/lib/node_modules
|
||||
COPY --from=build /usr/local/bin/hapi /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"]
|
||||
@@ -0,0 +1,87 @@
|
||||
# HAPI Hub Docker 部署
|
||||
|
||||
一键 Docker 部署 [HAPI](https://github.com/tiann/hapi) Hub,支持远程访问 AI 编程助手(Claude Code / Codex / Gemini / OpenCode)。
|
||||
|
||||
## GHCR 镜像
|
||||
|
||||
每次推送 `main` 分支或 `v*` 标签时,GitHub Actions 自动构建多架构镜像(linux/amd64, linux/arm64)并推送至 GHCR:
|
||||
|
||||
```
|
||||
ghcr.io/<你的 GitHub 用户名>/hapi-docker:main
|
||||
ghcr.io/<你的 GitHub 用户名>/hapi-docker:<sha>
|
||||
ghcr.io/<你的 GitHub 用户名>/hapi-docker:<tag>
|
||||
```
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 配置环境变量
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
编辑 `.env`,填写必要参数。
|
||||
|
||||
### 2. 构建并启动
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### 3. 查看状态
|
||||
|
||||
```bash
|
||||
docker compose logs -f
|
||||
```
|
||||
|
||||
### 使用预构建镜像(跳过本地构建)
|
||||
|
||||
编辑 `docker-compose.yml`,将 `build` 替换为 `image`:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
hapi-hub:
|
||||
image: ghcr.io/your-username/hapi-docker:main
|
||||
container_name: hapi-hub
|
||||
...
|
||||
```
|
||||
|
||||
然后:
|
||||
|
||||
```bash
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
|
||||
| 变量 | 必填 | 默认值 | 说明 |
|
||||
|------|------|--------|------|
|
||||
| `CLI_API_TOKEN` | 是 | - | 认证令牌,CLI 连接时使用 |
|
||||
| `HAPI_PUBLIC_URL` | 否 | - | Hub 公网地址,如 `http://1.2.3.4:3006` |
|
||||
| `CORS_ORIGINS` | 否 | `*` | 允许的 CORS 域名 |
|
||||
| `TZ` | 否 | `Asia/Shanghai` | 时区 |
|
||||
|
||||
## 客户端连接
|
||||
|
||||
在其他机器上配置 CLI 连接:
|
||||
|
||||
```bash
|
||||
export HAPI_API_URL="http://your-server-ip:3006"
|
||||
export CLI_API_TOKEN="your-token"
|
||||
|
||||
hapi
|
||||
```
|
||||
|
||||
支持 Runner 模式:
|
||||
|
||||
```bash
|
||||
docker exec hapi-hub hapi runner start --foreground
|
||||
```
|
||||
|
||||
## 持久化数据
|
||||
|
||||
Hub 数据存储在当前目录 `./hapi-data/` 中,对应容器内 `/root/.hapi/`:
|
||||
|
||||
- `settings.json` — 配置文件
|
||||
- `hapi.db` — SQLite 数据库
|
||||
@@ -0,0 +1,18 @@
|
||||
services:
|
||||
hapi-hub:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: hapi-hub
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "3006:3006"
|
||||
volumes:
|
||||
- ./hapi-data:/root/.hapi
|
||||
environment:
|
||||
- CLI_API_TOKEN=${CLI_API_TOKEN:?请设置 CLI_API_TOKEN 环境变量}
|
||||
- HAPI_LISTEN_HOST=0.0.0.0
|
||||
- HAPI_LISTEN_PORT=3006
|
||||
- HAPI_PUBLIC_URL=${HAPI_PUBLIC_URL}
|
||||
- CORS_ORIGINS=${CORS_ORIGINS:-*}
|
||||
- TZ=${TZ:-Asia/Shanghai}
|
||||
Reference in New Issue
Block a user