|
| 1 | +# Copyright OpenSearch Contributors |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# The OpenSearch Contributors require contributions made to |
| 5 | +# this file be licensed under the Apache-2.0 license or a |
| 6 | +# compatible open source license. |
| 7 | + |
| 8 | +# This is a docker image specifically for building docker images with single/multi-arch support |
| 9 | +# It has binfmt_support package installed to run non-native arch binary, as well as |
| 10 | +# qemu-user-static package to enable execution of different multi-arch containers |
| 11 | + |
| 12 | +# This can only be used on Ubuntu 2004 X64 version, as QEMU 5.0 is required to get buildx work properly without segfault |
| 13 | +# https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1928075 |
| 14 | + |
| 15 | +# This image can be used with these arguments: -u root -v /var/run/docker.sock:/var/run/docker.sock |
| 16 | + |
| 17 | +FROM ubuntu:24.04 |
| 18 | + |
| 19 | +ARG DEBIAN_FRONTEND=noninteractive |
| 20 | +ARG CONTAINER_USER=ci-runner |
| 21 | +ARG CONTAINER_USER_HOME=/home/ci-runner |
| 22 | + |
| 23 | +# Remove ubuntu user which occupies the 1000 userid and groupid since 23.04 |
| 24 | +# https://bugs.launchpad.net/cloud-images/+bug/2005129 |
| 25 | +USER 0 |
| 26 | +RUN touch /var/mail/ubuntu && chown ubuntu /var/mail/ubuntu && userdel -r ubuntu |
| 27 | + |
| 28 | +# Import necessary repository |
| 29 | +RUN apt-get update -y && apt-get install -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa -y |
| 30 | + |
| 31 | +# Install necessary packages to build multi-arch docker images |
| 32 | +RUN apt-get update -y && apt-get upgrade -y && apt-get install -y binfmt-support qemu-system qemu-system-common qemu-user qemu-user-static docker.io=24.0.7* curl && \ |
| 33 | + apt-get install -y debmake debhelper-compat |
| 34 | + |
| 35 | +# Install python, update awscli to v2 due to lib conflicts on urllib3 v1 vs v2 |
| 36 | +RUN apt-get install -y python3.9-full && \ |
| 37 | + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 100 && \ |
| 38 | + update-alternatives --install /usr/bin/python python /usr/bin/python3.9 100 && \ |
| 39 | + update-alternatives --set python3 /usr/bin/python3.9 && \ |
| 40 | + update-alternatives --set python /usr/bin/python3.9 && \ |
| 41 | + curl -SL https://bootstrap.pypa.io/get-pip.py | python3 - && \ |
| 42 | + pip3 install awscliv2==2.3.1 |
| 43 | + |
| 44 | +# Install trivy to scan the docker images |
| 45 | +RUN apt-get install -y apt-transport-https gnupg lsb-release && \ |
| 46 | + curl -o- https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | tee /usr/share/keyrings/trivy.gpg > /dev/null && \ |
| 47 | + echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/trivy.list && \ |
| 48 | + apt-get update -y && apt-get install -y trivy && apt-get clean && trivy --version |
| 49 | + |
| 50 | +# Install JDK |
| 51 | +RUN curl -SL https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.15%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.15_10.tar.gz -o /opt/jdk11.tar.gz && \ |
| 52 | + mkdir -p /opt/java/openjdk-11 && \ |
| 53 | + tar -xzf /opt/jdk11.tar.gz --strip-components 1 -C /opt/java/openjdk-11/ && \ |
| 54 | + rm /opt/jdk11.tar.gz |
| 55 | + |
| 56 | +# Create user group |
| 57 | +RUN groupadd -g 1000 $CONTAINER_USER && \ |
| 58 | + useradd -u 1000 -g 1000 -s /bin/bash -d $CONTAINER_USER_HOME -m $CONTAINER_USER && \ |
| 59 | + mkdir -p $CONTAINER_USER_HOME && \ |
| 60 | + chown -R 1000:1000 $CONTAINER_USER_HOME |
| 61 | + |
| 62 | +# ENV JDK |
| 63 | +ENV JAVA_HOME=/opt/java/openjdk-11 |
| 64 | +ENV PATH=$PATH:$JAVA_HOME/bin |
| 65 | + |
| 66 | +# Install docker buildx |
| 67 | +# 2023-06-20 Upgrade from 0.6.3 to 0.9.1 due to binary translation speedup in emulation mode during multi-arch image generation |
| 68 | +# https://github.com/docker/buildx/releases/tag/v0.9.1 |
| 69 | +# Avoid upgrading to 0.10.0+ due to this change: |
| 70 | +# Buildx v0.10 enables support for a minimal SLSA Provenance attestation, which requires support for OCI-compliant multi-platform images. |
| 71 | +# This may introduce issues with registry and runtime support (e.g. Google Cloud Run and Lambda). |
| 72 | +# You can optionally disable the default provenance attestation functionality using --provenance=false. |
| 73 | +RUN mkdir -p ~/.docker/cli-plugins && \ |
| 74 | + curl -SL https://github.com/docker/buildx/releases/download/v0.9.1/buildx-v0.9.1.linux-amd64 -o ~/.docker/cli-plugins/docker-buildx && \ |
| 75 | + chmod 775 ~/.docker/cli-plugins/docker-buildx && \ |
| 76 | + docker buildx version |
| 77 | + |
| 78 | +# Install gcrane |
| 79 | +# Stays on 0.15.2 due to --all-tags was introduced in 0.15.1 and several bugs are fixed in 0.15.2: https://github.com/google/go-containerregistry/pull/1682 |
| 80 | +RUN curl -SL https://github.com/google/go-containerregistry/releases/download/v0.15.2/go-containerregistry_Linux_x86_64.tar.gz -o go-containerregistry.tar.gz && \ |
| 81 | + tar -zxvf go-containerregistry.tar.gz && \ |
| 82 | + chmod +x gcrane crane krane && \ |
| 83 | + mv -v gcrane crane krane /usr/local/bin/ && \ |
| 84 | + rm -v go-containerregistry.tar.gz && \ |
| 85 | + gcrane version && crane version && krane version |
| 86 | + |
| 87 | +# Install packer |
| 88 | +# Stays on 1.8.7 version due to 1.8.7 fixed the JSON regression: https://github.com/hashicorp/packer/issues/12281 |
| 89 | +# As well as 1.9.0+ includes major changes. A lot of plugins are removed since 1.9.0: https://github.com/hashicorp/packer/releases/tag/v1.9.0 |
| 90 | +RUN curl -SL -o- https://apt.releases.hashicorp.com/gpg | gpg --dearmor > /usr/share/keyrings/hashicorp-archive-keyring.gpg && \ |
| 91 | + echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list && \ |
| 92 | + apt-get update && \ |
| 93 | + apt-get install packer=1.8.7* && \ |
| 94 | + packer --version && \ |
| 95 | + apt-get clean |
| 96 | + |
| 97 | +# Tools setup |
| 98 | +COPY --chown=0:0 config/yq-setup.sh config/gh-setup.sh /tmp/ |
| 99 | +RUN apt-get install -y golang-1.22 && /tmp/yq-setup.sh && /tmp/gh-setup.sh && apt-get clean && apt-get autoremove -y |
0 commit comments