From a6b18abc8a8f3ac29dd66d0604900173e9051ffc Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Fri, 26 Aug 2022 14:34:37 +0200 Subject: [PATCH] Dockerfile: Rework generation of kas images While kas and kas-isar surely have a common ground like the kas tool itself, kas-isar does not need all the toolchain packages that are essential Yocto dependencies. Splitting up the images earlier allows to shrink kas-isar by almost 400 MB. Use this chance to model both images as different build stages of the same Dockerfile. That is simpler than creating a temporary "kas-base" image via a separate Dockerfile. Signed-off-by: Jan Kiszka --- .github/workflows/master.yml | 2 +- .github/workflows/next.yml | 6 ++--- .github/workflows/release.yml | 2 +- Dockerfile | 46 ++++++++++++++++++++++++++--------- Dockerfile.isar | 21 ---------------- 5 files changed, 38 insertions(+), 39 deletions(-) delete mode 100644 Dockerfile.isar diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 67d3b8e..c119dc5 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -41,7 +41,7 @@ jobs: - name: Build kas-isar image uses: docker/build-push-action@v2 with: - file: Dockerfile.isar + target: kas-isar platforms: linux/amd64,linux/arm64 push: ${{ env.PUSH_MASTER }} tags: ghcr.io/siemens/kas/kas-isar diff --git a/.github/workflows/next.yml b/.github/workflows/next.yml index b4cf9cd..53ddc0f 100644 --- a/.github/workflows/next.yml +++ b/.github/workflows/next.yml @@ -96,9 +96,8 @@ jobs: - name: Build kas-isar image uses: docker/build-push-action@v2 with: - file: Dockerfile.isar + target: kas-isar load: true - build-args: KAS_TAG=next tags: ghcr.io/siemens/kas/kas-isar:next - name: Test kas-isar image run: | @@ -107,8 +106,7 @@ jobs: - name: Complete build and deploy kas-isar image uses: docker/build-push-action@v2 with: - file: Dockerfile.isar + target: kas-isar platforms: linux/amd64,linux/arm64 - build-args: KAS_TAG=next tags: ghcr.io/siemens/kas/kas-isar:next push: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b82ce4c..ba3afca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,7 @@ jobs: - name: Build kas-isar image uses: docker/build-push-action@v2 with: - file: Dockerfile.isar + target: kas-isar platforms: linux/amd64,linux/arm64 push: true tags: | diff --git a/Dockerfile b/Dockerfile index 11dcba9..4a93ace 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # This image builds Yocto jobs using the kas tool -FROM debian:bullseye-slim +FROM debian:bullseye-slim as kas-base ARG TARGETPLATFORM ARG DEBIAN_FRONTEND=noninteractive @@ -9,17 +9,10 @@ RUN apt-get update && \ apt-get install -y locales && \ localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && \ apt-get install --no-install-recommends -y \ - gawk wget git diffstat unzip texinfo \ - gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect \ - xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \ - pylint3 xterm python3-subunit mesa-common-dev zstd liblz4-tool \ - python3-setuptools python3-wheel python3-yaml python3-distro python3-jsonschema python3-newt \ - gosu lsb-release file vim less procps tree tar bzip2 zstd pigz tmux libncurses-dev \ - dosfstools mtools parted lz4 \ - git-lfs mercurial iproute2 ssh-client telnet curl rsync gnupg awscli sudo && \ - if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ - apt-get install --no-install-recommends -y gcc-multilib g++-multilib syslinux; \ - fi && \ + python3-pip python3-setuptools python3-wheel python3-yaml python3-distro python3-jsonschema python3-newt \ + gosu lsb-release file vim less procps tree tar bzip2 zstd pigz lz4 tmux libncurses-dev \ + git-lfs mercurial iproute2 ssh-client telnet curl rsync gnupg awscli sudo \ + socat bash-completion && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -40,3 +33,32 @@ RUN echo "Defaults env_keep += \"ftp_proxy http_proxy https_proxy no_proxy\"" \ > /etc/sudoers.d/env_keep && chmod 660 /etc/sudoers.d/env_keep ENTRYPOINT ["/kas/container-entrypoint"] + +FROM kas-base as kas-isar + +ENV LC_ALL=en_US.UTF-8 +RUN apt-get update && \ + apt-get install -y -f --no-install-recommends \ + binfmt-support debootstrap dosfstools dpkg-dev gettext-base git \ + mtools parted python3 quilt qemu-user-static reprepro sudo \ + git-buildpackage pristine-tar sbuild schroot \ + umoci skopeo && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN sed -i 's|\tGOSU="gosu builder"|\0\n\tsbuild-adduser builder >/dev/null 2>\&1|' /kas/container-entrypoint +RUN sed -i 's|#!/bin/bash|\0\n\nupdate-binfmts --enable \&\& [ -f /proc/sys/fs/binfmt_misc/status ]|' /kas/container-entrypoint + +FROM kas-base as kas + +RUN apt-get update && \ + apt-get install --no-install-recommends -y \ + gawk wget git diffstat unzip texinfo \ + gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect \ + xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev \ + pylint3 xterm python3-subunit mesa-common-dev zstd liblz4-tool && \ + if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + apt-get install --no-install-recommends -y gcc-multilib g++-multilib; \ + fi && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/Dockerfile.isar b/Dockerfile.isar deleted file mode 100644 index 6f57a19..0000000 --- a/Dockerfile.isar +++ /dev/null @@ -1,21 +0,0 @@ -# This image builds Isar jobs using the kas tool - -ARG KAS_TAG=latest - -FROM ghcr.io/siemens/kas/kas:$KAS_TAG - -ARG DEBIAN_FRONTEND=noninteractive - -ENV LC_ALL=en_US.UTF-8 -RUN apt-get update && \ - apt-get install -y -f --no-install-recommends \ - gdisk bash-completion \ - reprepro python3 binfmt-support \ - umoci skopeo \ - git-buildpackage pristine-tar schroot sbuild \ - qemu-user-static debootstrap quilt && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - -RUN sed -i 's|\tGOSU="gosu builder"|\0\n\tsbuild-adduser builder >/dev/null 2>\&1|' /kas/container-entrypoint -RUN sed -i 's|#!/bin/bash|\0\n\nupdate-binfmts --enable \&\& [ -f /proc/sys/fs/binfmt_misc/status ]|' /kas/container-entrypoint