From e9357a243d84346644a62c327787081d0e45ce5c Mon Sep 17 00:00:00 2001 From: SteBaum Date: Wed, 12 Jun 2024 16:38:43 +0200 Subject: [PATCH] feat(build-env): added builder for python written components --- build-env-python/Dockerfile | 69 +++++++++++++++++++++++++++ build-env-python/README.md | 19 ++++++++ build-env-python/docker-entrypoint.sh | 23 +++++++++ 3 files changed, 111 insertions(+) create mode 100644 build-env-python/Dockerfile create mode 100644 build-env-python/README.md create mode 100755 build-env-python/docker-entrypoint.sh diff --git a/build-env-python/Dockerfile b/build-env-python/Dockerfile new file mode 100644 index 0000000..1ec4768 --- /dev/null +++ b/build-env-python/Dockerfile @@ -0,0 +1,69 @@ +FROM quay.io/pypa/manylinux2014_x86_64 + +# Group paquets and repos +RUN yum groups mark install "Development Tools" +RUN yum groups mark convert "Development Tools" +RUN yum group install -y "Development Tools" +RUN yum install -y epel-release + +# Base packets + specific (Rust, Kerberos, DB, etc.) +RUN yum update -y && yum install -y \ + cmake \ + curl \ + cyrus-sasl-devel \ + cyrus-sasl-gssapi \ + gcc \ + git \ + gmp-devel \ + krb5-devel \ + libffi-devel \ + libtidy-devel \ + libxml2-devel \ + libxslt-devel \ + mariadb-devel \ + maven \ + openldap-devel \ + openssl-devel \ + postgresql-devel \ + rsync \ + rust \ + rust-toolset-7 \ + sqlite-devel \ + sudo \ + swig \ + wget \ + zlib-devel + +# Diverse configurations +RUN ln -s /usr/local/bin/python3.6 /usr/local/bin/python3 +RUN mkdir /usr/local/share/jupyter && chmod 777 /usr/local/share/jupyter +RUN mkdir /opt/_internal/cpython-3.6.15/etc && chmod 777 /opt/_internal/cpython-3.6.15/etc +RUN mkdir -p /hue/build + +# Pip update +RUN /usr/local/bin/python3.6 -m pip install --upgrade pip +RUN /usr/local/bin/python3.6 -m pip install --upgrade wheel +RUN /usr/local/bin/python3.6 -m pip install --upgrade setuptools + +# NVM & NodeJS +RUN mkdir /usr/local/nvm +WORKDIR /usr/local/nvm +RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh --output install.sh && chmod u+x install.sh +RUN export NVM_DIR=/usr/local/nvm && ./install.sh +RUN source /usr/local/nvm/nvm.sh && source /usr/local/nvm/bash_completion && nvm install lts/gallium + +# GoSu +ENV GOSU_VERSION=1.11 +RUN gpg --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \ + && curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64" \ + && curl -o /usr/local/bin/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64.asc" \ + && gpg --verify /usr/local/bin/gosu.asc \ + && rm /usr/local/bin/gosu.asc \ + && rm -r /root/.gnupg/ \ + && chmod +x /usr/local/bin/gosu \ + # Verify that the binary works + && gosu nobody true + +# Create the user builder +COPY docker-entrypoint.sh /usr/local/bin/ +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/build-env-python/README.md b/build-env-python/README.md new file mode 100644 index 0000000..7c6152f --- /dev/null +++ b/build-env-python/README.md @@ -0,0 +1,19 @@ +# Build Environment + +Building components written in Python has different requirements than the ones written in Java. They are so to speak not really compiled, however they are still packaged in a Python wheel or a tar.gz file. + +The image being used is a manylinux2014 image originally based on CentOS 7 and compatible with many Linux OSs. It moreover has several different Python versions pre-installed on it. + +## Build the image + +The image can be built and tagged with: + +```bash +docker build . -t tdp_builder_python +``` + +## Start the container + +Contrary to the `tdp-builder` container where components are compiled with maven putting the jar files in the `.m2` cache it is not the case here and therefore volumes, working directories and even users are different for each component. + +Check the documentation of the concerned component for the command to start the container. diff --git a/build-env-python/docker-entrypoint.sh b/build-env-python/docker-entrypoint.sh new file mode 100755 index 0000000..664dc22 --- /dev/null +++ b/build-env-python/docker-entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -eo pipefail + +if [[ -n "$USER_UID" ]] && [[ -n "$USER_GID" ]]; then + # Create group and user only if they don't exist + [[ ! $(getent group builder) ]] && groupadd -r --gid "$USER_GID" builder + if [[ ! $(getent passwd builder) ]]; then + useradd --create-home --home-dir /home/builder --uid "$USER_UID" --gid "$USER_GID" --system --shell /bin/bash builder + usermod -aG wheel builder + mkdir -p /home/builder + chown builder:builder /home/builder + gosu builder cp -r /etc/skel/. /home/builder + fi + # Avoid changing dir if a work dir is specified + [[ "$PWD" == "/root" ]] && cd /home/builder + if [[ -z "$@" ]]; then + exec gosu builder /bin/bash + else + exec gosu builder "$@" + fi +fi + +exec "$@"