41 lines
1.4 KiB
Docker
41 lines
1.4 KiB
Docker
FROM --platform=linux/amd64 golang:1.21 AS build
|
|
|
|
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 ;; \
|
|
*) apt-get install -y gcc ;; \
|
|
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" ;; \
|
|
*) export CC="gcc" PIE=true ;; \
|
|
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" ]
|