forked from dokemon-ng/dokemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.agent
More file actions
86 lines (73 loc) · 2.65 KB
/
Dockerfile.agent
File metadata and controls
86 lines (73 loc) · 2.65 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# syntax=docker/dockerfile:1
# Build the Go application
FROM --platform=$BUILDPLATFORM golang:latest AS build-stage
# Set default TARGETARCH if not provided (fallback to build platform)
ARG TARGETARCH
ARG TARGETOS=linux
# Install Docker CLI
RUN set -eux; \
if [ -z "${TARGETARCH}" ]; then \
case "$(uname -m)" in \
x86_64) export TARGETARCH=amd64 ;; \
aarch64) export TARGETARCH=arm64 ;; \
armv7l) export TARGETARCH=arm ;; \
*) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; \
esac; \
fi; \
case "${TARGETARCH}" in \
amd64|x86_64) \
curl -fsSLO "https://download.docker.com/linux/static/stable/x86_64/docker-28.1.1.tgz" \
;; \
arm64|aarch64) \
curl -fsSLO "https://download.docker.com/linux/static/stable/aarch64/docker-28.1.1.tgz" \
;; \
arm) \
curl -fsSLO "https://download.docker.com/linux/static/stable/armhf/docker-28.1.1.tgz" \
;; \
*) \
echo "Unsupported architecture: ${TARGETARCH}"; \
exit 1 \
;; \
esac; \
tar xzvf "docker-28.1.1.tgz" --strip-components=1 -C /bin docker/docker; \
rm "docker-28.1.1.tgz"
# Install Docker Compose
RUN set -eux; \
if [ -z "${TARGETARCH}" ]; then \
case "$(uname -m)" in \
x86_64) export TARGETARCH=amd64 ;; \
aarch64) export TARGETARCH=arm64 ;; \
armv7l) export TARGETARCH=arm ;; \
*) echo "Unsupported architecture: $(uname -m)"; exit 1 ;; \
esac; \
fi; \
case "${TARGETARCH}" in \
amd64|x86_64) \
curl -fsSL "https://github.com/docker/compose/releases/download/v2.36.0/docker-compose-linux-x86_64" -o /bin/docker-compose \
;; \
arm64|aarch64) \
curl -fsSL "https://github.com/docker/compose/releases/download/v2.36.0/docker-compose-linux-aarch64" -o /bin/docker-compose \
;; \
arm) \
curl -fsSL "https://github.com/docker/compose/releases/download/v2.36.0/docker-compose-linux-armv7" -o /bin/docker-compose \
;; \
esac; \
chmod +x /bin/docker-compose
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./
# Special handling for ARMv7 Go build
RUN if [ "${TARGETARCH}" = "arm" ]; then \
export GOARCH=arm GOARM=7; \
fi && \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /dokemon-agent ./cmd/agent
RUN mkdir -p /data
# Final image
FROM gcr.io/distroless/base-debian11
WORKDIR /
COPY --from=build-stage /dokemon-agent /dokemon-agent
COPY --from=build-stage /data /data
COPY --from=build-stage /bin/docker /bin/docker
COPY --from=build-stage /bin/docker-compose /bin/docker-compose
ENTRYPOINT ["/dokemon-agent"]