Skip to content

Commit 0b59548

Browse files
committed
fix(build): Enable architecture-aware backend builds for multi-platform support
Signed-off-by: Nimbus318 <136771156+Nimbus318@users.noreply.github.com>
1 parent 6b9e831 commit 0b59548

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

server/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ FROM golang:1.23.1 AS builder
22

33
WORKDIR /src
44

5+
ARG TARGETARCH
6+
57
COPY . .
68

79
RUN 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

1113
FROM debian:stable-slim
1214

server/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CMD_PATH ?= ./cmd/
33
BUILD_PATH ?= ./build/
44
VERSION ?= $(shell git describe --tags --always)
55
DIRS = $(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
3940
build-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

0 commit comments

Comments
 (0)