mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 00:15:28 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b73315df0 | ||
|
|
a086e0cfa1 | ||
|
|
f3bc022a36 | ||
|
|
b7cb7ef0c1 | ||
|
|
267420a46a | ||
|
|
3c66ab958a | ||
|
|
cf2f79b6f4 | ||
|
|
ab6e817c8e | ||
|
|
9ae4630a3b | ||
|
|
d1b8537cfb | ||
|
|
d32b4481da |
@@ -10,7 +10,9 @@ __pycache__
|
|||||||
.Python
|
.Python
|
||||||
build/
|
build/
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
dist/
|
dist/*
|
||||||
|
!dist/docker-input/
|
||||||
|
!dist/docker-input/*.tar.gz
|
||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
|
|||||||
83
.github/workflows/release-artifacts.yml
vendored
83
.github/workflows/release-artifacts.yml
vendored
@@ -4,6 +4,12 @@ on:
|
|||||||
release:
|
release:
|
||||||
types:
|
types:
|
||||||
- published
|
- published
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
release_tag:
|
||||||
|
description: "Release tag to build/publish (e.g. v2.1.6)"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -12,6 +18,8 @@ permissions:
|
|||||||
jobs:
|
jobs:
|
||||||
build-and-upload:
|
build-and-upload:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RELEASE_TAG: ${{ github.event.release.tag_name || github.event.inputs.release_tag }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -42,7 +50,7 @@ jobs:
|
|||||||
- name: Build Multi-Platform Archives
|
- name: Build Multi-Platform Archives
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG="${{ github.event.release.tag_name }}"
|
TAG="${RELEASE_TAG}"
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
targets=(
|
targets=(
|
||||||
@@ -79,18 +87,44 @@ jobs:
|
|||||||
rm -rf "${STAGE}"
|
rm -rf "${STAGE}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
- name: Prepare Docker release inputs
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG="${RELEASE_TAG}"
|
||||||
|
mkdir -p dist/docker-input
|
||||||
|
cp "dist/ds2api_${TAG}_linux_amd64.tar.gz" "dist/docker-input/linux_amd64.tar.gz"
|
||||||
|
cp "dist/ds2api_${TAG}_linux_arm64.tar.gz" "dist/docker-input/linux_arm64.tar.gz"
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Log in to GHCR
|
- name: Wait for GHCR endpoint
|
||||||
uses: docker/login-action@v3
|
run: |
|
||||||
with:
|
set -euo pipefail
|
||||||
registry: ghcr.io
|
for i in {1..6}; do
|
||||||
username: ${{ github.actor }}
|
code="$(curl -sS -o /dev/null -w '%{http_code}' --max-time 15 https://ghcr.io/v2/ || true)"
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
if [ "${code}" = "200" ] || [ "${code}" = "401" ] || [ "${code}" = "405" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep "$((i * 10))"
|
||||||
|
done
|
||||||
|
echo "GHCR endpoint is unreachable after multiple retries (last status: ${code:-unknown})." >&2
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: Log in to GHCR (with retry)
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
for i in {1..6}; do
|
||||||
|
if echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep "$((i * 10))"
|
||||||
|
done
|
||||||
|
echo "Failed to login to GHCR after multiple retries." >&2
|
||||||
|
exit 1
|
||||||
|
|
||||||
- name: Extract Docker metadata
|
- name: Extract Docker metadata
|
||||||
id: meta_release
|
id: meta_release
|
||||||
@@ -99,14 +133,18 @@ jobs:
|
|||||||
images: |
|
images: |
|
||||||
ghcr.io/${{ github.repository }}
|
ghcr.io/${{ github.repository }}
|
||||||
tags: |
|
tags: |
|
||||||
type=raw,value=${{ github.event.release.tag_name }}
|
type=raw,value=${{ env.RELEASE_TAG }}
|
||||||
type=raw,value=latest
|
type=raw,value=latest
|
||||||
|
|
||||||
- name: Build and Push Docker Image
|
- name: Build and Push Docker Image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
|
env:
|
||||||
|
DOCKER_BUILD_RECORD_UPLOAD: "false"
|
||||||
|
DOCKER_BUILD_SUMMARY: "false"
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
target: runtime-from-dist
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
tags: ${{ steps.meta_release.outputs.tags }}
|
tags: ${{ steps.meta_release.outputs.tags }}
|
||||||
@@ -115,15 +153,17 @@ jobs:
|
|||||||
- name: Export Docker image archives for release assets
|
- name: Export Docker image archives for release assets
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG="${{ github.event.release.tag_name }}"
|
TAG="${RELEASE_TAG}"
|
||||||
|
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
|
--target runtime-from-dist \
|
||||||
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_amd64.tar" \
|
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_amd64.tar" \
|
||||||
.
|
.
|
||||||
|
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
|
--target runtime-from-dist \
|
||||||
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_arm64.tar" \
|
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_arm64.tar" \
|
||||||
.
|
.
|
||||||
|
|
||||||
@@ -135,10 +175,29 @@ jobs:
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
(cd dist && sha256sum *.tar.gz *.zip > sha256sums.txt)
|
(cd dist && sha256sum *.tar.gz *.zip > sha256sums.txt)
|
||||||
|
|
||||||
|
- name: Validate release tag
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG="${RELEASE_TAG}"
|
||||||
|
if [ -z "${TAG}" ]; then
|
||||||
|
echo "release tag is empty; set release_tag when using workflow_dispatch." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Upload Release Assets
|
- name: Upload Release Assets
|
||||||
uses: softprops/action-gh-release@v2
|
env:
|
||||||
with:
|
GH_TOKEN: ${{ github.token }}
|
||||||
files: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG="${RELEASE_TAG}"
|
||||||
|
FILES=(
|
||||||
dist/*.tar.gz
|
dist/*.tar.gz
|
||||||
dist/*.zip
|
dist/*.zip
|
||||||
dist/sha256sums.txt
|
dist/sha256sums.txt
|
||||||
|
)
|
||||||
|
|
||||||
|
if gh release view "${TAG}" >/dev/null 2>&1; then
|
||||||
|
gh release upload "${TAG}" "${FILES[@]}" --clobber
|
||||||
|
else
|
||||||
|
gh release create "${TAG}" "${FILES[@]}" --title "${TAG}" --notes ""
|
||||||
|
fi
|
||||||
|
|||||||
11
DEPLOY.en.md
11
DEPLOY.en.md
@@ -135,11 +135,12 @@ docker-compose up -d --build
|
|||||||
|
|
||||||
### 2.3 Docker Architecture
|
### 2.3 Docker Architecture
|
||||||
|
|
||||||
The `Dockerfile` uses a three-stage build:
|
The `Dockerfile` now provides two image paths:
|
||||||
|
|
||||||
1. **WebUI build stage**: `node:20` image, runs `npm ci && npm run build`
|
1. **Default local/dev path (`runtime-from-source`)**: a three-stage build (WebUI build + Go build + runtime).
|
||||||
2. **Go build stage**: `golang:1.24` image, compiles the binary
|
2. **Release path (`runtime-from-dist`)**: CI first creates `dist/ds2api_<tag>_linux_<arch>.tar.gz`, then Docker directly reuses the binary and `static/admin` assets from those release archives, without running `npm build`/`go build` again.
|
||||||
3. **Runtime stage**: `debian:bookworm-slim` minimal image
|
|
||||||
|
The release path keeps Docker images aligned with release archives and reduces duplicate build work.
|
||||||
|
|
||||||
Container entry command: `/usr/local/bin/ds2api`, default exposed port: `5001`.
|
Container entry command: `/usr/local/bin/ds2api`, default exposed port: `5001`.
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ Docker Compose includes a built-in health check:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "-qO-", "http://localhost:${PORT:-5001}/healthz"]
|
test: ["CMD", "/usr/local/bin/busybox", "wget", "-qO-", "http://localhost:${PORT:-5001}/healthz"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|||||||
11
DEPLOY.md
11
DEPLOY.md
@@ -135,11 +135,12 @@ docker-compose up -d --build
|
|||||||
|
|
||||||
### 2.3 Docker 架构说明
|
### 2.3 Docker 架构说明
|
||||||
|
|
||||||
`Dockerfile` 使用三阶段构建:
|
`Dockerfile` 提供两条构建路径:
|
||||||
|
|
||||||
1. **WebUI 构建阶段**:`node:20` 镜像,执行 `npm ci && npm run build`
|
1. **本地/开发默认路径(`runtime-from-source`)**:三阶段构建(WebUI 构建 + Go 构建 + 运行阶段)。
|
||||||
2. **Go 构建阶段**:`golang:1.24` 镜像,编译二进制文件
|
2. **Release 路径(`runtime-from-dist`)**:CI 先生成 `dist/ds2api_<tag>_linux_<arch>.tar.gz`,再由 Docker 直接复用该发布包内的二进制和 `static/admin` 产物组装运行镜像,不再重复执行 `npm build`/`go build`。
|
||||||
3. **运行阶段**:`debian:bookworm-slim` 精简镜像
|
|
||||||
|
Release 路径可确保 Docker 镜像与 release 压缩包使用同一套产物,减少重复构建带来的差异。
|
||||||
|
|
||||||
容器内启动命令:`/usr/local/bin/ds2api`,默认暴露端口 `5001`。
|
容器内启动命令:`/usr/local/bin/ds2api`,默认暴露端口 `5001`。
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ Docker Compose 已配置内置健康检查:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "-qO-", "http://localhost:${PORT:-5001}/healthz"]
|
test: ["CMD", "/usr/local/bin/busybox", "wget", "-qO-", "http://localhost:${PORT:-5001}/healthz"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|||||||
40
Dockerfile
40
Dockerfile
@@ -15,12 +15,44 @@ RUN go mod download
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/ds2api ./cmd/ds2api
|
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/ds2api ./cmd/ds2api
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM busybox:1.36.1-musl AS busybox-tools
|
||||||
|
|
||||||
|
FROM debian:bookworm-slim AS runtime-base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/*
|
COPY --from=go-builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
|
COPY --from=busybox-tools /bin/busybox /usr/local/bin/busybox
|
||||||
|
EXPOSE 5001
|
||||||
|
CMD ["/usr/local/bin/ds2api"]
|
||||||
|
|
||||||
|
FROM runtime-base AS runtime-from-source
|
||||||
COPY --from=go-builder /out/ds2api /usr/local/bin/ds2api
|
COPY --from=go-builder /out/ds2api /usr/local/bin/ds2api
|
||||||
COPY --from=go-builder /app/sha3_wasm_bg.7b9ca65ddd.wasm /app/sha3_wasm_bg.7b9ca65ddd.wasm
|
COPY --from=go-builder /app/sha3_wasm_bg.7b9ca65ddd.wasm /app/sha3_wasm_bg.7b9ca65ddd.wasm
|
||||||
COPY --from=go-builder /app/config.example.json /app/config.example.json
|
COPY --from=go-builder /app/config.example.json /app/config.example.json
|
||||||
COPY --from=webui-builder /app/static/admin /app/static/admin
|
COPY --from=webui-builder /app/static/admin /app/static/admin
|
||||||
EXPOSE 5001
|
|
||||||
CMD ["/usr/local/bin/ds2api"]
|
FROM busybox-tools AS dist-extract
|
||||||
|
ARG TARGETARCH
|
||||||
|
COPY dist/docker-input/linux_amd64.tar.gz /tmp/ds2api_linux_amd64.tar.gz
|
||||||
|
COPY dist/docker-input/linux_arm64.tar.gz /tmp/ds2api_linux_arm64.tar.gz
|
||||||
|
RUN set -eux; \
|
||||||
|
case "${TARGETARCH}" in \
|
||||||
|
amd64) ARCHIVE="/tmp/ds2api_linux_amd64.tar.gz" ;; \
|
||||||
|
arm64) ARCHIVE="/tmp/ds2api_linux_arm64.tar.gz" ;; \
|
||||||
|
*) echo "unsupported TARGETARCH: ${TARGETARCH}" >&2; exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
tar -xzf "${ARCHIVE}" -C /tmp; \
|
||||||
|
PKG_DIR="$(find /tmp -maxdepth 1 -type d -name "ds2api_*_linux_${TARGETARCH}" | head -n1)"; \
|
||||||
|
test -n "${PKG_DIR}"; \
|
||||||
|
mkdir -p /out/static; \
|
||||||
|
cp "${PKG_DIR}/ds2api" /out/ds2api; \
|
||||||
|
cp "${PKG_DIR}/sha3_wasm_bg.7b9ca65ddd.wasm" /out/sha3_wasm_bg.7b9ca65ddd.wasm; \
|
||||||
|
cp "${PKG_DIR}/config.example.json" /out/config.example.json; \
|
||||||
|
cp -R "${PKG_DIR}/static/admin" /out/static/admin
|
||||||
|
|
||||||
|
FROM runtime-base AS runtime-from-dist
|
||||||
|
COPY --from=dist-extract /out/ds2api /usr/local/bin/ds2api
|
||||||
|
COPY --from=dist-extract /out/sha3_wasm_bg.7b9ca65ddd.wasm /app/sha3_wasm_bg.7b9ca65ddd.wasm
|
||||||
|
COPY --from=dist-extract /out/config.example.json /app/config.example.json
|
||||||
|
COPY --from=dist-extract /out/static/admin /app/static/admin
|
||||||
|
|
||||||
|
FROM runtime-from-source AS final
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ services:
|
|||||||
- HOST=0.0.0.0
|
- HOST=0.0.0.0
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "wget", "-qO-", "http://localhost:${PORT:-5001}/healthz"]
|
test: ["CMD", "/usr/local/bin/busybox", "wget", "-qO-", "http://localhost:${PORT:-5001}/healthz"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|||||||
Reference in New Issue
Block a user