From 5c81e40612fc5061bb392dba6c059e8dd63d49dc Mon Sep 17 00:00:00 2001 From: JustSong Date: Fri, 7 Feb 2025 01:35:53 +0800 Subject: [PATCH] fix: update Dockerfile and workflow for improved multi-architecture support --- .github/workflows/docker-image.yml | 5 +++-- Dockerfile | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d1e18361..01c58947 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -62,8 +62,9 @@ jobs: uses: docker/build-push-action@v3 with: context: . - # platforms: linux/amd64,linux/arm64 platforms: ${{ contains(github.ref, 'alpha') && 'linux/amd64' || 'linux/amd64,linux/arm64' }} push: true tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + build-args: | + TARGETARCH=${{ startsWith(matrix.platform, 'linux/arm64') && 'arm64' || 'amd64' }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d6e7ee3c..fc43cde2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,18 +14,18 @@ RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run buil DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/air & \ wait -FROM golang AS builder2 +FROM golang:alpine AS builder2 -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential \ - sqlite3 libsqlite3-dev \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache \ + gcc \ + musl-dev \ + sqlite-dev \ + build-base ENV GO111MODULE=on \ CGO_ENABLED=1 \ GOOS=linux \ - CGO_CFLAGS="-I/usr/include" \ - CGO_LDFLAGS="-L/usr/lib" + GOARCH=$TARGETARCH WORKDIR /build @@ -35,14 +35,11 @@ RUN go mod download COPY . . COPY --from=builder /web/build ./web/build -RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/common.Version=$(cat VERSION)'" -o one-api +RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/common.Version=$(cat VERSION)' -linkmode external -extldflags '-static'" -o one-api -# Final runtime image -FROM ubuntu:22.04 +FROM alpine:latest -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates tzdata bash \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates tzdata COPY --from=builder2 /build/one-api /