-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDockerfile
46 lines (31 loc) · 1.4 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# syntax=docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.4.0@sha256:0cd3f05c72d6c9b038eb135f91376ee1169ef3a330d34e418e65e2a5c2e9c0d4 AS xx
FROM --platform=$BUILDPLATFORM golang:1.24.1-bullseye@sha256:aa106963247f64275bd459b6b713978f1633160da53f58115922964ab0b9eae7 AS builder
COPY --link --from=xx / /
ARG TARGETPLATFORM
RUN --mount=type=cache,id=${TARGETPLATFORM}-apt,target=/var/cache/apt,sharing=locked \
apt-get update \
&& xx-apt-get install -y --no-install-recommends \
gcc \
libc6-dev
WORKDIR /build/cli
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=.,target=/build,ro \
xx-go mod download -x
ARG BUILD_OPTS
ARG EXTRA_LDFLAGS
ENV CGO_ENABLED=1
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=.,target=/build,ro \
xx-go build ${BUILD_OPTS} -ldflags="-s -w -extldflags -static ${EXTRA_LDFLAGS}" \
-o /bin/dirctl ./cli.go
RUN xx-verify /bin/dirctl
FROM alpine:3.20@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
RUN apk add --update --no-cache \
ca-certificates \
libc6-compat
COPY --from=builder ["/bin/dirctl", "/bin/dirctl"]
ENTRYPOINT ["/bin/dirctl"]