Manuel
2fd8f5d20b
* Add dockerignore and update editorconfig for Dockerfile * Abort docker build if arch is not supported
43 lines
1.6 KiB
Docker
43 lines
1.6 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 ;; \
|
|
"amd64") apt-get install -y gcc ;; \
|
|
*) echo "Arch not supported" && exit 1 ;; \
|
|
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 ;; \
|
|
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" ]
|