forked from silogen/cluster-forge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
59 lines (49 loc) · 2.16 KB
/
Copy pathdockerfile
File metadata and controls
59 lines (49 loc) · 2.16 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
# syntax=docker/dockerfile:1
FROM golang:1.23 AS gobuilder
WORKDIR /src
COPY . /src
# Download dependencies
RUN go mod download
# Build the project
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-extldflags "-static"' -o /forge /src/main.go
# Use a base Alpine image
FROM alpine:latest AS builder
# Install necessary tools (curl, git, bash)
RUN apk add --no-cache --no-check-certificate curl git bash
# Install kubectl
RUN set -e; \
# Fetch the latest stable version tag from kubernetes
KUBECTL_VERSION=$(curl -k -L -s https://dl.k8s.io/release/stable.txt); \
echo "Latest kubectl version: ${KUBECTL_VERSION}"; \
# Download kubectl binary from the correct URL
curl -kLO "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"; \
# Check if kubectl is not empty or corrupted
if [ ! -s kubectl ]; then \
echo "Download failed: kubectl binary is empty or corrupted."; exit 1; \
fi; \
# Make it executable and move it to a system path
chmod +x kubectl; \
mv kubectl /usr/local/bin/kubectl;
RUN set -e; \
# Fetch the latest stable version tag from Helm
HELM_VERSION=$(curl -s https://api.github.com/repos/helm/helm/releases/latest | grep tag_name | cut -d '"' -f 4); \
echo "Latest Helm version: ${HELM_VERSION}"; \
# Download Helm binary from the correct URL
curl -kLO "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz"; \
# Extract the Helm binary
tar -zxvf helm-${HELM_VERSION}-linux-amd64.tar.gz; \
# Move the Helm binary to a system path
mv linux-amd64/helm /usr/local/bin/helm; \
# Clean up
rm -rf helm-${HELM_VERSION}-linux-amd64.tar.gz linux-amd64;
# Copy the built binary from the gobuilder stage
FROM alpine:latest
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm
COPY --from=gobuilder /forge /usr/local/bin/forge
# Copy the entry script
COPY entry.sh /entry.sh
# Ensure the entry script and binaries are executable
RUN chmod +x /entry.sh /usr/local/bin/forge /usr/local/bin/kubectl /usr/local/bin/helm
# Set ENTRYPOINT to the entry script
ENTRYPOINT ["/entry.sh"]