Skip to content

Commit

Permalink
feat(build-env): added builder for python written components
Browse files Browse the repository at this point in the history
  • Loading branch information
SteBaum committed Jun 14, 2024
1 parent 42f6dec commit 4485a3f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
69 changes: 69 additions & 0 deletions build-env-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions build-env-python/README.md
Original file line number Diff line number Diff line change
@@ -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-manylinux2014
```

## 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.
23 changes: 23 additions & 0 deletions build-env-python/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 4485a3f

Please sign in to comment.