Skip to content

Commit 5c81e40

Browse files
committed
fix: update Dockerfile and workflow for improved multi-architecture support
1 parent 0d5318b commit 5c81e40

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

.github/workflows/docker-image.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ jobs:
6262
uses: docker/build-push-action@v3
6363
with:
6464
context: .
65-
# platforms: linux/amd64,linux/arm64
6665
platforms: ${{ contains(github.ref, 'alpha') && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
6766
push: true
6867
tags: ${{ steps.meta.outputs.tags }}
69-
labels: ${{ steps.meta.outputs.labels }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
build-args: |
70+
TARGETARCH=${{ startsWith(matrix.platform, 'linux/arm64') && 'arm64' || 'amd64' }}

Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run buil
1414
DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ./VERSION) npm run build --prefix /web/air & \
1515
wait
1616

17-
FROM golang AS builder2
17+
FROM golang:alpine AS builder2
1818

19-
RUN apt-get update && apt-get install -y --no-install-recommends \
20-
build-essential \
21-
sqlite3 libsqlite3-dev \
22-
&& rm -rf /var/lib/apt/lists/*
19+
RUN apk add --no-cache \
20+
gcc \
21+
musl-dev \
22+
sqlite-dev \
23+
build-base
2324

2425
ENV GO111MODULE=on \
2526
CGO_ENABLED=1 \
2627
GOOS=linux \
27-
CGO_CFLAGS="-I/usr/include" \
28-
CGO_LDFLAGS="-L/usr/lib"
28+
GOARCH=$TARGETARCH
2929

3030
WORKDIR /build
3131

@@ -35,14 +35,11 @@ RUN go mod download
3535
COPY . .
3636
COPY --from=builder /web/build ./web/build
3737

38-
RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/common.Version=$(cat VERSION)'" -o one-api
38+
RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/common.Version=$(cat VERSION)' -linkmode external -extldflags '-static'" -o one-api
3939

40-
# Final runtime image
41-
FROM ubuntu:22.04
40+
FROM alpine:latest
4241

43-
RUN apt-get update && apt-get install -y --no-install-recommends \
44-
ca-certificates tzdata bash \
45-
&& rm -rf /var/lib/apt/lists/*
42+
RUN apk add --no-cache ca-certificates tzdata
4643

4744
COPY --from=builder2 /build/one-api /
4845

0 commit comments

Comments
 (0)