File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5454 uses : docker/build-push-action@v6
5555 with :
5656 context : .
57- platforms : linux/amd64
57+ platforms : linux/amd64,linux/arm64,linux/arm/v7
5858 push : ${{ github.event_name != 'pull_request' }}
5959 tags : ${{ steps.meta.outputs.tags }}
6060 labels : ${{ steps.meta.outputs.labels }}
Original file line number Diff line number Diff line change 1- FROM golang:1.22-alpine AS builder
1+ ARG BUILDPLATFORM=linux/amd64
2+ FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS builder
3+
4+ ARG TARGETOS
5+ ARG TARGETARCH
6+ ARG TARGETVARIANT
27
38WORKDIR /src
9+ RUN apk add --no-cache ca-certificates tzdata
10+
411COPY go.mod ./
512COPY cmd ./cmd
613COPY internal ./internal
714
8- RUN mkdir -p /out && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o /out/ecs-controller ./cmd/ecs-controller
15+ RUN set -eux; \
16+ target_os="${TARGETOS:-linux}" ; \
17+ target_arch="${TARGETARCH:-amd64}" ; \
18+ if [ "$target_arch" = "arm" ]; then \
19+ export GOARM="${TARGETVARIANT#v}" ; \
20+ if [ -z "$GOARM" ]; then export GOARM=7; fi; \
21+ fi; \
22+ mkdir -p /out; \
23+ CGO_ENABLED=0 GOOS="$target_os" GOARCH="$target_arch" \
24+ go build -trimpath -ldflags="-s -w" -o /out/ecs-controller ./cmd/ecs-controller
925
1026FROM alpine:3.20
1127
12- RUN apk add --no-cache ca-certificates tzdata
1328WORKDIR /app
29+ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
30+ COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
1431COPY --from=builder /out/ecs-controller ./ecs-controller
1532COPY web ./web
1633
Original file line number Diff line number Diff line change @@ -565,6 +565,26 @@ go build -o ecs-controller ./cmd/ecs-controller
565565ghcr.io/sunser/ecs-controller
566566` ` `
567567
568+ 镜像使用 Docker Buildx 构建,当前发布以下架构:
569+
570+ | 平台 | 常见设备 |
571+ | --- | --- |
572+ | `linux/amd64` | 常见 x86_64 云服务器、PC、NAS |
573+ | `linux/arm64` | ARM64 云服务器、Apple Silicon、部分 NAS 和开发板 |
574+ | `linux/arm/v7` | 32 位 ARMv7 设备 |
575+
576+ 使用同一个镜像 tag 即可,Docker 会按当前机器架构自动选择对应镜像。例如:
577+
578+ ` ` ` bash
579+ docker pull ghcr.io/sunser/ecs-controller:latest
580+ ` ` `
581+
582+ 如果需要在本地手工构建多架构镜像,可以使用:
583+
584+ ` ` ` bash
585+ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t ghcr.io/sunser/ecs-controller:local .
586+ ` ` `
587+
568588推送到 `main` 分支后会生成:
569589
570590` ` ` text
You can’t perform that action at this time.
0 commit comments