build: support multi-architecture builds in Dockerfile
Add ARG directives for TARGETOS and TARGETARCH to enable multi-architecture support. Modify the build command to use the specified target OS and architecture for more flexible and portable builds. Ensure compatibility with different deployment environments.
This commit is contained in:
+4
-1
@@ -4,6 +4,9 @@ ADD go.* /build
|
|||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
FROM deps as build
|
FROM deps as build
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
ADD . /build
|
ADD . /build
|
||||||
RUN if [ $(go mod tidy -v 2>&1 | grep -c unused) != 0 ]; then echo "Unused modules, please run 'go mod tidy'"; exit 1; fi
|
RUN if [ $(go mod tidy -v 2>&1 | grep -c unused) != 0 ]; then echo "Unused modules, please run 'go mod tidy'"; exit 1; fi
|
||||||
@@ -14,7 +17,7 @@ RUN ["/bin/bash", "-c", "cat coverage.txt.tmp | grep -v -f <(find . -type f | xa
|
|||||||
RUN go tool cover -html=coverage.txt -o coverage.html
|
RUN go tool cover -html=coverage.txt -o coverage.html
|
||||||
RUN go tool cover -func=coverage.txt
|
RUN go tool cover -func=coverage.txt
|
||||||
RUN rm coverage.txt.tmp
|
RUN rm coverage.txt.tmp
|
||||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -mod=readonly -o release/default-request-adder -ldflags '-w -s'
|
RUN iGOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -mod=readonly -o release/default-request-adder -ldflags '-w -s'
|
||||||
|
|
||||||
FROM scratch as export
|
FROM scratch as export
|
||||||
COPY --from=build /build/coverage.txt /
|
COPY --from=build /build/coverage.txt /
|
||||||
|
|||||||
Reference in New Issue
Block a user