From dfd758bde4dd09d01756bcd54ad59f04a18a319c Mon Sep 17 00:00:00 2001 From: Akizon77 Date: Mon, 21 Jul 2025 06:36:15 +0000 Subject: [PATCH] =?UTF-8?q?ci:=20Docker=20=E9=95=9C=E5=83=8F=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release-docker.yml | 78 ++++++++++++++++++++++++++++ Dockerfile | 15 ++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/workflows/release-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml new file mode 100644 index 0000000..7959f05 --- /dev/null +++ b/.github/workflows/release-docker.yml @@ -0,0 +1,78 @@ +name: Publish Docker Image + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-multi-arch: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.23" + + - name: Build static binaries for multi-arch + env: + GOOS: linux + CGO_ENABLED: 0 + run: | + VERSION="${{ github.event.release.tag_name }}" + if [ -z "$VERSION" ]; then + VERSION="${{ github.sha }}" + fi + LDFLAGS="-s -w -X github.com/komari-monitor/komari-agent/update.CurrentVersion=${VERSION}" + + echo "Building for linux/amd64..." + GOARCH=amd64 go build -trimpath -ldflags="$LDFLAGS" -o komari-agent-linux-amd64 + + echo "Building for linux/arm64..." + GOARCH=arm64 go build -trimpath -ldflags="$LDFLAGS" -o komari-agent-linux-arm64 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + 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=${{ github.event.release.tag_name }} + type=raw,value=latest + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f4d7d0b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.21 + +WORKDIR /app + +# Docker buildx 会在构建时自动填充这些变量 +ARG TARGETOS +ARG TARGETARCH + +COPY komari-agent-${TARGETOS}-${TARGETARCH} /app/komari-agent + +RUN chmod +x /app/komari-agent + +EXPOSE 27774 + +CMD ["/app/komari-agent"]