File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ FROM golang:1.23.1 AS builder
22
33WORKDIR /src
44
5+ ARG TARGETARCH
6+
57COPY . .
68
79RUN apt-get update && apt-get install -y --no-install-recommends protobuf-compiler
810
9- RUN make build
11+ RUN make build TARGET_ARCH=${TARGETARCH}
1012
1113FROM debian:stable-slim
1214
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ CMD_PATH ?= ./cmd/
33BUILD_PATH ?= ./build/
44VERSION ?= $(shell git describe --tags --always)
55DIRS = $(shell ls $(CMD_PATH ) )
6+ TARGET_ARCH ?= amd64
67
78# 1. Install Go dependencies
89.PHONY : install-deps
@@ -37,10 +38,11 @@ tidy-mod:
3738# 4. Build-related commands
3839.PHONY : build-linux
3940build-linux :
40- @ for dir in $( DIRS) ; \
41+ @echo " Building for GOOS=linux GOARCH=$( TARGET_ARCH) " # TARGET_ARCH 会从 make 命令传入
42+ @for dir in $(DIRS ) ; \
4143 do \
42- GO_ENABLED =0 GOOS=linux GOARCH=amd64 go build -o $(BUILD_PATH ) $$ dir ${CMD_PATH} $$ dir; \
43- echo " Built $$ dir for Linux" ; \
44+ CGO_ENABLED =0 GOOS=linux GOARCH=$( TARGET_ARCH ) go build -o $(BUILD_PATH ) $$ dir ${CMD_PATH} $$ dir; \
45+ echo " Built $$ dir for Linux/ $( TARGET_ARCH ) " ; \
4446 done
4547
4648.PHONY : build-local
You can’t perform that action at this time.
0 commit comments