-
Notifications
You must be signed in to change notification settings - Fork 215
/
Dockerfile
44 lines (38 loc) · 1.45 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
# Prebuilt libjq.
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl as libjq
# Go builder.
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.22-alpine3.19 AS builder
ARG appVersion=latest
RUN apk --no-cache add git ca-certificates gcc musl-dev libc-dev
# 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
RUN CGO_ENABLED=1 \
CGO_CFLAGS="-I/libjq/include" \
CGO_LDFLAGS="-L/libjq/lib" \
GOOS=linux \
go build -ldflags="-linkmode external -extldflags '-static' -s -w -X 'github.com/flant/shell-operator/pkg/app.Version=$appVersion'" \
-tags use_libjq \
-o shell-operator \
./cmd/shell-operator
# Final image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.21
ARG TARGETPLATFORM
RUN apk --no-cache add ca-certificates bash sed tini && \
kubectlArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\/v7//') && \
echo "Download kubectl for ${kubectlArch}" && \
wget https://storage.googleapis.com/kubernetes-release/release/v1.27.13/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
chmod +x /bin/kubectl && \
mkdir /hooks
ADD frameworks/shell /frameworks/shell
ADD shell_lib.sh /
COPY --from=libjq /bin/jq /usr/bin
COPY --from=builder /app/shell-operator /
WORKDIR /
ENV SHELL_OPERATOR_HOOKS_DIR /hooks
ENV LOG_TYPE json
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
CMD ["start"]