discord-tweeter/Dockerfile.multiarch

44 lines
1.6 KiB
Docker
Raw Normal View History

FROM --platform=linux/amd64 golang:1.22 AS build
2023-08-29 18:00:00 +02:00
ARG TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS $TARGETOS
ENV GOARCH $TARGETARCH
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
case "$TARGETARCH$TARGETVARIANT" in \
"arm64") apt-get install -y gcc-aarch64-linux-gnu ;; \
"armv7") apt-get install -y gcc-arm-linux-gnueabihf ;; \
"riscv64") apt-get install -y gcc-riscv64-linux-gnu ;; \
"amd64") apt-get install -y gcc ;; \
*) echo "Arch not supported" && exit 1 ;; \
2023-08-29 18:00:00 +02:00
esac
WORKDIR /tmp/app
COPY . .
RUN go mod download && \
case "$TARGETARCH$TARGETVARIANT" in \
"arm64") export CC="aarch64-linux-gnu-gcc" PIE=true ;; \
"armv7") export CC="arm-linux-gnueabihf-gcc" GOARM="7" ;; \
"riscv64") export CC="riscv64-linux-gnu-gcc" ;; \
"amd64") export CC="gcc" PIE=true ;; \
*) echo "Arch not supported" && exit 1 ;; \
2023-08-29 18:00:00 +02:00
esac && \
export CGO_ENABLED=1 && \
if [ $PIE = true ]; then \
go build -a -buildmode=pie -trimpath -ldflags "-s -w -linkmode 'external' -extldflags '-static-pie' -X main.prefix=" -o discord-tweeter; \
else \
go build -a -trimpath -ldflags "-s -w -linkmode 'external' -extldflags '-static' -X main.prefix=" -o discord-tweeter; \
fi
FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /app
COPY --from=build /tmp/app/discord-tweeter .
#COPY ./config.example.toml ./config.toml
ENTRYPOINT [ "./discord-tweeter" ]
# CMD [ "./config.toml" ]