Skip to content

Commit

Permalink
Update Dockerfile to reduce image size
Browse files Browse the repository at this point in the history
  • Loading branch information
sagnik3788 committed Sep 3, 2024
1 parent 787c7aa commit 770e065
Showing 1 changed file with 46 additions and 31 deletions.
77 changes: 46 additions & 31 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
FROM golang:1.14.2

LABEL maintainer="LitmusChaos"

RUN apt-get update && apt-get install -y git && \
apt-get install -y ssh && \
apt install ssh rsync

ARG KUBECTL_VERSION=1.18.0

#setup go envs
ENV GO111MODULE=off
ENV GOPATH=$HOME/go
ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

#Installing helm
RUN wget https://get.helm.sh/helm-v3.4.0-linux-amd64.tar.gz && \
tar -zxvf helm-v3.4.0-linux-amd64.tar.gz && \
mv linux-amd64/helm /usr/local/bin/helm

#Install kubectl
ADD https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl

#copying binaries
COPY build/_output ./
COPY litmus/helm-install.sh ./
COPY build/experiment_entrypoint.sh ./

#overwrite entrypoint with test binary
ENTRYPOINT ["./all-experiments"]
FROM golang:alpine AS builder

# Set Go environment variables
ENV GO111MODULE=off
ENV GOPATH=/go
ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

# Install dependencies and cleanup
RUN apk update && \
apk add --no-cache \
git \
wget \
tar

# Install Helm
RUN wget https://get.helm.sh/helm-v3.4.0-linux-amd64.tar.gz && \
tar -zxvf helm-v3.4.0-linux-amd64.tar.gz && \
mv linux-amd64/helm /usr/local/bin/helm && \
rm -rf helm-v3.4.0-linux-amd64.tar.gz linux-amd64

# Install kubectl
RUN wget https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl -O /usr/local/bin/kubectl && \
chmod +x /usr/local/bin/kubectl

# Copy and build the binaries
COPY build/_output /app/_output
COPY litmus/helm-install.sh /app/
COPY build/experiment_entrypoint.sh /app/

FROM alpine:latest

# Install runtime dependencies
RUN apk update && \
apk add --no-cache \
openssh-client

# Copy only the necessary files from the build stage
COPY --from=builder /app /app
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm

# Set working directory
WORKDIR /app

# Override entrypoint with test binary
ENTRYPOINT ["./all-experiments"]

0 comments on commit 770e065

Please sign in to comment.