deploy: add k3s test image pipeline

This commit is contained in:
Your Name
2026-10-11 13:49:39 +08:00
parent 779141e2c6
commit df95801672
4 changed files with 121 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
.git
.gitea
.idea
.vscode
**/.DS_Store
web/node_modules
web/dist
server/temp
server/logs
server/storage/cache
server/storage/diskqueue
server/resource/public/admin
docs
tools
*.docx
*.pdf
+37
View File
@@ -0,0 +1,37 @@
name: Deploy olons-admin (k3s test cluster)
on:
workflow_dispatch:
inputs:
image_tag:
description: '镜像 tag,默认 test'
required: false
jobs:
deploy:
runs-on: deploy-host
steps:
- uses: actions/checkout@v4
- name: 确定镜像 tag
id: vars
run: |
TAG="${{ github.event.inputs.image_tag }}"
[ -z "$TAG" ] && TAG=test
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: 登录镜像仓库
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.118im.com -u admin --password-stdin
- name: 构建并推送前后端一体镜像
run: |
docker build -t git.118im.com/im_team/olons-admin:${{ steps.vars.outputs.tag }} .
docker push git.118im.com/im_team/olons-admin:${{ steps.vars.outputs.tag }}
- name: 滚动更新测试集群
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config
chmod 600 ~/.kube/config
kubectl rollout restart deployment/olons-admin -n olons-admin-system
kubectl rollout status deployment/olons-admin -n olons-admin-system --timeout=180s
+36
View File
@@ -0,0 +1,36 @@
FROM node:20-alpine AS web-build
WORKDIR /web
RUN corepack enable && corepack prepare pnpm@10.18.3 --activate
COPY web/package.json web/pnpm-lock.yaml web/pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
COPY web/ ./
RUN pnpm run build
FROM golang:1.24-alpine AS server-build
WORKDIR /src
COPY server/go.mod server/go.sum ./
RUN go mod download
RUN go install github.com/gogf/gf/cmd/gf/v2@v2.10.0
COPY server/ ./
COPY --from=web-build /web/dist/ ./resource/public/admin/
RUN gf pack resource internal/packed/packed.go --keepPath=true \
&& CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/hotgo .
FROM alpine:3.22
RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -S hotgo \
&& adduser -S -G hotgo hotgo
WORKDIR /app
COPY --from=server-build /out/hotgo /app/hotgo
COPY --from=server-build /src/manifest /app/manifest
COPY --from=server-build /src/resource /app/resource
COPY --from=web-build /web/dist/ /app/resource/public/admin/
RUN mkdir -p /app/storage /app/logs \
&& chown -R hotgo:hotgo /app
USER hotgo
EXPOSE 8000
ENTRYPOINT ["/app/hotgo"]
CMD ["all"]
+32
View File
@@ -0,0 +1,32 @@
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
class DeploymentContract(unittest.TestCase):
def test_container_builds_web_and_server_in_one_image(self):
dockerfile = (ROOT / "Dockerfile").read_text()
self.assertIn("pnpm install --frozen-lockfile", dockerfile)
self.assertIn("pnpm run build", dockerfile)
self.assertIn("gf pack resource internal/packed/packed.go", dockerfile)
self.assertIn("go build", dockerfile)
self.assertIn("/app/resource/public/admin", dockerfile)
self.assertIn('ENTRYPOINT ["/app/hotgo"]', dockerfile)
def test_container_excludes_local_and_generated_files(self):
dockerignore = (ROOT / ".dockerignore").read_text().splitlines()
for ignored in (".git", "web/node_modules", "web/dist", "server/temp"):
self.assertIn(ignored, dockerignore)
def test_manual_workflow_builds_and_rolls_out_test_image(self):
workflow = (ROOT / ".gitea/workflows/deploy.yml").read_text()
self.assertIn("workflow_dispatch:", workflow)
self.assertIn("git.118im.com/im_team/olons-admin", workflow)
self.assertIn("deployment/olons-admin", workflow)
self.assertIn("-n olons-admin-system", workflow)
if __name__ == "__main__":
unittest.main()