-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (57 loc) · 1.72 KB
/
Dockerfile
File metadata and controls
73 lines (57 loc) · 1.72 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
# Prebuilt jq.
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl AS libjq
# Go builder stage
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.25.5-alpine3.23 AS builder
ARG appVersion=latest
# Install build dependencies
RUN apk --no-cache add \
git \
ca-certificates \
gcc \
musl-dev \
libc-dev \
binutils-gold
# Set working directory
WORKDIR /app
# Cache-friendly dependency download
ADD go.mod go.sum ./
RUN go mod download
# Add source code (changes here invalidate cache less frequently)
ADD . /app
# Build the application
RUN GOOS=linux \
go build \
-ldflags="-s -w -X 'github.com/flant/shell-operator/pkg/app.Version=${appVersion}'" \
-o shell-operator \
./cmd/shell-operator
# Final runtime image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.23
ARG TARGETPLATFORM
ARG kubectlVersion=v1.33.8
# Install runtime dependencies
RUN apk --no-cache add \
ca-certificates \
bash \
sed \
tini \
curl
# Determine kubectl architecture and download
RUN kubectlArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\/v7//') && \
echo "Downloading kubectl version ${kubectlVersion} for ${kubectlArch}" && \
wget https://dl.k8s.io/release/${kubectlVersion}/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
chmod +x /bin/kubectl
# Create hooks directory
RUN mkdir /hooks
# Copy necessary files
ADD frameworks/shell /frameworks/shell
ADD shell_lib.sh /
COPY --from=libjq /bin/jq /usr/bin
COPY --from=builder /app/shell-operator /
# Set working directory
WORKDIR /
# Set environment variables
ENV SHELL_OPERATOR_HOOKS_DIR=/hooks
ENV LOG_TYPE=json
# Set entrypoint and default command
ENTRYPOINT ["/sbin/tini", "--", "/shell-operator"]
CMD ["start"]