-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (49 loc) · 2.3 KB
/
Dockerfile
File metadata and controls
64 lines (49 loc) · 2.3 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
# Prebuilt libjq.
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl as libjq
# Go builder.
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.26.1-alpine3.23 AS builder
ARG appVersion=latest
RUN apk --no-cache add git ca-certificates gcc musl-dev libc-dev binutils-gold
# Cache-friendly download of go dependencies.
ADD go.mod go.sum /app/
WORKDIR /app
RUN go mod download
COPY --from=libjq /libjq /libjq
ADD . /app
# Clone shell-operator to get frameworks
RUN git clone https://github.com/flant/shell-operator shell-operator-clone && \
cd shell-operator-clone && \
git checkout v1.13.1
RUN shellOpVer=$(go list -m all | grep shell-operator | cut -d' ' -f 2-) \
GOOS=linux \
go build -ldflags="-linkmode external -extldflags '-static' -s -w -X 'github.com/flant/shell-operator/pkg/app.Version=$shellOpVer' -X 'github.com/flant/addon-operator/pkg/app.Version=$appVersion'" \
-o addon-operator \
./cmd/addon-operator
# Build helm post-renderer binary (required if helm3 binary is in use)
RUN GOOS=linux \
go build -o post-renderer ./cmd/post-renderer
# Final image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.23
ARG TARGETPLATFORM
ARG kubectlVersion=v1.33.8
# kubectl url has no variant (v7)
# helm url has dashes and no variant (v7)
RUN apk --no-cache add ca-certificates bash sed tini && \
kubectlArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\/v7//') && \
echo "Download kubectl version ${kubectlVersion} for ${kubectlArch}" && \
wget https://dl.k8s.io/release/${kubectlVersion}/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
chmod +x /bin/kubectl && \
helmArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\//-/g;s/-v7//') && \
wget https://get.helm.sh/helm-v3.15.4-${helmArch}.tar.gz -O /helm.tgz && \
tar -z -x -C /bin -f /helm.tgz --strip-components=1 ${helmArch}/helm && \
rm -f /helm.tgz
COPY --from=libjq /bin/jq /usr/bin
COPY --from=builder /app/addon-operator /
COPY --from=builder /app/post-renderer /
COPY --from=builder /app/shell-operator-clone/frameworks/shell/ /framework/shell/
COPY --from=builder /app/shell-operator-clone/shell_lib.sh /
WORKDIR /
RUN mkdir /global-hooks /modules
ENV MODULES_DIR /modules
ENV GLOBAL_HOOKS_DIR /global-hooks
ENTRYPOINT ["/sbin/tini", "--", "/addon-operator"]