diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed3d1ab..3a0e326 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,12 @@ jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + arch: + - amd64 + - arm64 + steps: - name: Checkout code uses: actions/checkout@v3 @@ -51,10 +57,11 @@ jobs: with: context: . file: ./Dockerfile - platforms: linux/arm64,linux/amd64 + platforms: linux/${{ matrix.arch }} push: ${{ github.event_name != 'pull_request' }} build-args: | VERSION=${{ env.DATE }} + TARGETARCH=${{ matrix.arch }} tags: | cairry/watchalert:latest cairry/watchalert:${{ env.BRANCH_NAME }}.${{ env.DATE }}.${{ env.SHORT_SHA }} diff --git a/Dockerfile b/Dockerfile index aedab96..7c4d535 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -FROM registry.cn-hangzhou.aliyuncs.com/opsre/golang:1.21.9-alpine3.19 AS build +FROM --platform=$BUILDPLATFORM golang:1.21.9-alpine3.19 AS build ARG VERSION +ARG TARGETARCH ENV GOPROXY=https://goproxy.cn,direct @@ -12,10 +13,10 @@ RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories && apk upgrade && apk add --no-cache --virtual .build-deps \ ca-certificates upx -RUN go build --ldflags="-X main.Version=${VERSION}" -o watchAlert . \ +RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build --ldflags="-X main.Version=${VERSION}" -o watchAlert . \ && upx -9 watchAlert && chmod +x watchAlert -FROM registry.cn-hangzhou.aliyuncs.com/opsre/alpine:3.19 +FROM alpine:3.19 COPY --from=build /root/watchAlert /app/watchAlert