diff --git a/server/Dockerfile b/server/Dockerfile index 9165b2b..bea55a3 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -2,11 +2,13 @@ FROM golang:1.23.1 AS builder WORKDIR /src +ARG TARGETARCH + COPY . . RUN apt-get update && apt-get install -y --no-install-recommends protobuf-compiler -RUN make build +RUN make build TARGET_ARCH=${TARGETARCH} FROM debian:stable-slim diff --git a/server/Makefile b/server/Makefile index 7dbe891..fee817d 100644 --- a/server/Makefile +++ b/server/Makefile @@ -3,6 +3,7 @@ CMD_PATH ?= ./cmd/ BUILD_PATH ?= ./build/ VERSION ?= $(shell git describe --tags --always) DIRS = $(shell ls $(CMD_PATH)) +TARGET_ARCH ?= amd64 # 1. Install Go dependencies .PHONY: install-deps @@ -37,10 +38,11 @@ tidy-mod: # 4. Build-related commands .PHONY: build-linux build-linux: - @ for dir in $(DIRS); \ + @echo "Building for GOOS=linux GOARCH=$(TARGET_ARCH)" # TARGET_ARCH 会从 make 命令传入 + @for dir in $(DIRS); \ do \ - GO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BUILD_PATH)$$dir ${CMD_PATH}$$dir; \ - echo "Built $$dir for Linux"; \ + CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGET_ARCH) go build -o $(BUILD_PATH)$$dir ${CMD_PATH}$$dir; \ + echo "Built $$dir for Linux/$(TARGET_ARCH)"; \ done .PHONY: build-local