From c69da57f58820242364cd64b670d4af299c95fc0 Mon Sep 17 00:00:00 2001 From: leppeK <26918457+leppeK@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:24:31 +0200 Subject: [PATCH] Build desired target with a buildargument This way we are not diverging in multiple dockerfiles and we can choose between two targets: - cilium-cli-ci The original target based on ubuntu and the default - cilium-cli Only contains the cilium cli based on scratch Fixes: #2755 Signed-off-by: Merijn Keppel --- .github/workflows/images.yaml | 6 +++++- Dockerfile | 38 ++++++++++++++++++++++------------- Dockerfile-cli-only | 16 --------------- 3 files changed, 29 insertions(+), 31 deletions(-) delete mode 100644 Dockerfile-cli-only diff --git a/.github/workflows/images.yaml b/.github/workflows/images.yaml index 23319cfd05..2b45584b4f 100644 --- a/.github/workflows/images.yaml +++ b/.github/workflows/images.yaml @@ -67,7 +67,9 @@ jobs: context: . file: ${{ matrix.dockerfile }} push: true - platforms: linux/amd64 + platforms: ${{ matrix.platforms }} + build-args: | + FINAL_CONTAINER=${{ matrix.name }} tags: | quay.io/${{ github.repository_owner }}/${{ matrix.name }}:latest quay.io/${{ github.repository_owner }}/${{ matrix.name }}:${{ steps.tag.outputs.tag }} @@ -90,6 +92,8 @@ jobs: file: ${{ matrix.dockerfile }} push: true platforms: ${{ matrix.platforms }} + build-args: | + FINAL_CONTAINER=${{ matrix.name }} tags: | quay.io/${{ github.repository_owner }}/${{ matrix.name }}:${{ steps.tag.outputs.tag }} diff --git a/Dockerfile b/Dockerfile index c8d4faaec0..702f977b84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,15 +3,21 @@ # Copyright Authors of Cilium # SPDX-License-Identifier: Apache-2.0 +# FINAL_CONTAINER specifies the source for the output +# cilium-cli-ci (default) is based on ubuntu with cloud CLIs +# cilium-cli is from scratch only including cilium binaries +ARG FINAL_CONTAINER="cilium-cli-ci" + FROM docker.io/library/golang:1.23.1-alpine3.19@sha256:e0ea2a119ae0939a6d449ea18b2b1ba30b44986ec48dbb88f3a93371b4bf8750 AS builder WORKDIR /go/src/github.com/cilium/cilium-cli RUN apk add --no-cache git make ca-certificates COPY . . RUN make -FROM ubuntu:24.04@sha256:56a8952801afd93876eea675cae9ab861bf8d2e6a4f978e4b0237ce94e1c3b49 -LABEL maintainer="maintainer@cilium.io" -WORKDIR /root/app +FROM scratch AS cilium-cli +COPY --from=builder /go/src/github.com/cilium/cilium-cli/cilium /usr/local/bin/cilium + +FROM ubuntu:24.04@sha256:56a8952801afd93876eea675cae9ab861bf8d2e6a4f978e4b0237ce94e1c3b49 AS cilium-cli-ci COPY --from=builder /go/src/github.com/cilium/cilium-cli/cilium /usr/local/bin/cilium # Install cloud CLIs. Based on these instructions: @@ -19,16 +25,20 @@ COPY --from=builder /go/src/github.com/cilium/cilium-cli/cilium /usr/local/bin/c # - https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html # - https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt#install-azure-cli RUN apt-get update -y \ - && apt-get install -y curl gnupg unzip \ - && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg \ - && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \ - && echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \ - && apt-get update -y \ - && apt-get install -y google-cloud-cli google-cloud-sdk-gke-gcloud-auth-plugin kubectl \ - && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ - && unzip awscliv2.zip \ - && ./aws/install \ - && rm -r ./aws awscliv2.zip \ - && curl -sL https://aka.ms/InstallAzureCLIDeb | bash + && apt-get install -y curl gnupg unzip \ + && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg \ + && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \ + && echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list \ + && apt-get update -y \ + && apt-get install -y google-cloud-cli google-cloud-sdk-gke-gcloud-auth-plugin kubectl \ + && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \ + && unzip awscliv2.zip \ + && ./aws/install \ + && rm -r ./aws awscliv2.zip \ + && curl -sL https://aka.ms/InstallAzureCLIDeb | bash +# Select the layer to provide the final container image from +FROM ${FINAL_CONTAINER} +LABEL maintainer="maintainer@cilium.io" +WORKDIR /root/app ENTRYPOINT [] diff --git a/Dockerfile-cli-only b/Dockerfile-cli-only deleted file mode 100644 index f8a46bdc8c..0000000000 --- a/Dockerfile-cli-only +++ /dev/null @@ -1,16 +0,0 @@ -# syntax=docker/dockerfile:1.9@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28 - -# Copyright Authors of Cilium -# SPDX-License-Identifier: Apache-2.0 - -FROM docker.io/library/golang:1.22.6-alpine3.19@sha256:1bad39361dd21f2f881ce10ff810e40e5be3eba89a0b61e762e05ec42f9bbaf2 AS builder -WORKDIR /go/src/github.com/cilium/cilium-cli -RUN apk add --no-cache git make ca-certificates -COPY . . -RUN make - -FROM scratch -LABEL maintainer="maintainer@cilium.io" -COPY --from=builder /go/src/github.com/cilium/cilium-cli/cilium /usr/local/bin/cilium -ENTRYPOINT [] -