feat: add self-built Docker image from local hapi source

Add a new Docker image variant (tag: self) that uses compiled binaries
from the hapi self branch instead of installing from npm.

- self/Dockerfile: runtime image copying pre-built binary by arch
- self/build.sh: local build script from ../hapi/dist-exe
- .github/workflows/docker-build-self.yml: CI workflow to build and
  push multi-arch image to GHCR with tag "self"

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
i
2026-05-21 22:28:25 +08:00
co-authored by HAPI
parent 88c9c12804
commit 002e0b5e46
4 changed files with 139 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
name: Build and Push Self 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
- name: Checkout hapi self branch
uses: actions/checkout@v4
with:
repository: arkylin/hapi
ref: self
path: hapi-src
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.3.14
- name: Install dependencies
working-directory: hapi-src
run: bun install
- name: Build Linux binaries
working-directory: hapi-src
run: |
bun run download:tunwg
bun run build:web
cd hub && bun run generate:embedded-web-assets
cd ../cli && bun run build:exe:allinone --target bun-linux-x64-baseline
bun run build:exe:allinone --target bun-linux-arm64
- name: Copy binaries to Docker context
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
- 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=raw,value=self
- uses: docker/build-push-action@v6
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
+1
View File
@@ -1,2 +1,3 @@
.env .env
hapi-data/ hapi-data/
self/hapi-*
+19
View File
@@ -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
View File
@@ -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}"