From 76918b1ef3718e11f32bac5941ceec2134bb383a Mon Sep 17 00:00:00 2001 From: superjcvd Date: Wed, 4 Sep 2024 09:47:16 +0200 Subject: [PATCH] chore: gives the possibility not to install git in the docker image (#4333) * chore: create a variable for golang version * chore: gives the possibility not to install git cli * chore: update debian packages to latest security versions * fix: remove apt-get upgrade feature * Update Dockerfile * Update Dockerfile --------- Co-authored-by: @gael.soude Co-authored-by: Ruben Fiszel --- Dockerfile | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30464f87d2..99e49828a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,17 +88,24 @@ ARG POWERSHELL_VERSION=7.3.5 ARG POWERSHELL_DEB_VERSION=7.3.5-1 ARG KUBECTL_VERSION=1.28.7 ARG HELM_VERSION=3.14.3 +ARG GO_VERSION=1.22.5 ARG APP=/usr/src/app ARG WITH_POWERSHELL=true ARG WITH_KUBECTL=true ARG WITH_HELM=true - +ARG WITH_GIT=true RUN apt-get update \ - && apt-get install -y ca-certificates wget curl git jq unzip build-essential unixodbc xmlsec1 software-properties-common \ + && apt-get install -y ca-certificates wget curl jq unzip build-essential unixodbc xmlsec1 software-properties-common \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +RUN if [ "$WITH_GIT" = "true" ]; then \ + apt-get update -y \ + && apt-get install -y git \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/*; \ + else echo 'Building the image without git'; fi; RUN if [ "$WITH_POWERSHELL" = "true" ]; then \ if [ "$TARGETPLATFORM" = "linux/amd64" ]; then apt-get update -y && apt install libicu-dev -y && wget -O 'pwsh.deb' "https://github.com/PowerShell/PowerShell/releases/download/v${POWERSHELL_VERSION}/powershell_${POWERSHELL_DEB_VERSION}.deb_amd64.deb" && apt-get clean \ @@ -133,14 +140,14 @@ RUN if [ "$WITH_KUBECTL" = "true" ]; then \ RUN set -eux; \ arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \ case "$arch" in \ - 'amd64') \ - targz='go1.22.5.linux-amd64.tar.gz'; \ + "amd64") \ + targz="go${GO_VERSION}.linux-amd64.tar.gz"; \ ;; \ - 'arm64') \ - targz='go1.22.5.linux-arm64.tar.gz'; \ + "arm64") \ + targz="go${GO_VERSION}.linux-arm64.tar.gz"; \ ;; \ - 'armhf') \ - targz='go1.22.5.linux-armv6l.tar.gz'; \ + "armhf") \ + targz="go${GO_VERSION}.linux-armv6l.tar.gz"; \ ;; \ *) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \ esac; \ @@ -151,7 +158,7 @@ ENV GO_PATH=/usr/local/go/bin/go RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - RUN apt-get -y update && apt-get install -y curl nodejs awscli && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* # go build is slower the first time it is ran, so we prewarm it in the build RUN mkdir -p /tmp/gobuildwarm && cd /tmp/gobuildwarm && go mod init gobuildwarm && printf "package foo\nimport (\"fmt\")\nfunc main() { fmt.Println(42) }" > warm.go && go mod tidy && go build -x && rm -rf /tmp/gobuildwarm