From bc7d8611d60e2d92f8e3b2f463140c5337c5c756 Mon Sep 17 00:00:00 2001 From: starry <115192496+sky22333@users.noreply.github.com> Date: Tue, 17 Mar 2026 13:47:57 +0000 Subject: [PATCH] add docker --- .github/workflows/docker-ghcr.yml | 60 +++++++++++++++++++++++++++++++ Dockerfile | 20 +++++++++++ README.md | 2 +- docker-compose.yml | 14 ++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-ghcr.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.github/workflows/docker-ghcr.yml b/.github/workflows/docker-ghcr.yml new file mode 100644 index 0000000..706f423 --- /dev/null +++ b/.github/workflows/docker-ghcr.yml @@ -0,0 +1,60 @@ +name: ghcr镜像构建 +on: + workflow_dispatch: + inputs: + version: + description: '版本号 (例如: v1.0.0)' + required: true + default: 'v1.0.0' + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to GitHub Docker Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set version from input + run: | + VERSION=${{ github.event.inputs.version }} + if [[ $VERSION == v* ]]; then + VERSION=${VERSION:1} + fi + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Convert repository name to lowercase + run: | + # 将 github.repository 整体转换为小写 + REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') + echo "REPO_LOWER=$REPO_LOWER" >> $GITHUB_ENV + + - name: Build and push Docker image + run: | + docker buildx build --push \ + --platform linux/amd64,linux/arm64 \ + --tag ghcr.io/${{ env.REPO_LOWER }}:${{ env.VERSION }} \ + --tag ghcr.io/${{ env.REPO_LOWER }}:latest \ + -f Dockerfile . + env: + GHCR_PUBLIC: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e95a2b4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.26-alpine AS builder + +ARG TARGETARCH + +WORKDIR /app +COPY go.mod go.sum . +RUN go mod download && apk add upx --no-cache + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-s -w" -trimpath -o qqbot . && upx -9 qqbot + +FROM alpine + +WORKDIR /root/ + +COPY --from=builder /app/qqbot . +COPY --from=builder /app/configs/config.toml . + +CMD ["./qqbot", "-config", "config.toml"] \ No newline at end of file diff --git a/README.md b/README.md index c49ba87..87807f5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # qqbot -轻量级 QQ 通知机器人(单账户),支持 HTTP 服务与 Go SDK 两种使用方式。 +轻量级 QQ 通知机器人,支持 HTTP 服务与 Go SDK 两种使用方式。 ## 1. 快速开始 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a1bad70 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + qqbot: + image: ghcr.io/sky22333/qqbot + container_name: qqbot + restart: always + ports: + - "8080:8080" + volumes: + - ./configs/config.toml:/root/config.toml + logging: + driver: json-file + options: + max-size: "1g" + max-file: "2" \ No newline at end of file