Skip to content

Commit

Permalink
Add Python 3.6 Jenkins slaves (#126)
Browse files Browse the repository at this point in the history
* Initial commit of Python slave

* Build Python container like SCL

* Add .rhel7 Dockerfile

* Add prepare-yum-repositories

* ...and make it executable

* stop trying to remove logos if it doesn't work

* Add reference to SCL in readme
  • Loading branch information
jacobsee authored and sherl0cks committed Aug 31, 2018
1 parent 9953374 commit 7761b5a
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
30 changes: 30 additions & 0 deletions jenkins-slaves/jenkins-slave-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM openshift/jenkins-slave-base-centos7

EXPOSE 8080

ENV PYTHON_VERSION=3.6 \
PATH=$HOME/.local/bin/:$PATH \
PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8 \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
PIP_NO_CACHE_DIR=off

RUN INSTALL_PKGS="rh-python36 rh-python36-python-devel rh-python36-python-setuptools rh-python36-python-pip nss_wrapper \
httpd24 httpd24-httpd-devel httpd24-mod_ssl httpd24-mod_auth_kerb httpd24-mod_ldap \
httpd24-mod_session atlas-devel gcc-gfortran libffi-devel libtool-ltdl enchant" && \
yum install -y centos-release-scl && \
yum -y --setopt=tsflags=nodocs install --enablerepo=centosplus $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
# Remove centos-logos (httpd dependency) to keep image size smaller.
rpm -e --nodeps centos-logos && \
yum -y clean all --enablerepo='*' && \
source scl_source enable rh-python36 && \
scl enable rh-python36 bash

ADD scl_enable /usr/share/container-scripts/
ENV BASH_ENV=/usr/share/container-scripts/scl_enable \
ENV=/usr/share/container-scripts/scl_enable \
PROMPT_COMMAND=". /usr/share/container-scripts/scl_enable"

USER 1001
31 changes: 31 additions & 0 deletions jenkins-slaves/jenkins-slave-python/Dockerfile.rhel7
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM openshift3/jenkins-slave-base-rhel7

EXPOSE 8080

ENV PYTHON_VERSION=3.6 \
PATH=$HOME/.local/bin/:$PATH \
PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=UTF-8 \
LC_ALL=en_US.UTF-8 \
LANG=en_US.UTF-8 \
PIP_NO_CACHE_DIR=off

ADD prepare-yum-repositories prepare-yum-repositories

RUN INSTALL_PKGS="rh-python36 rh-python36-python-devel rh-python36-python-setuptools rh-python36-python-pip nss_wrapper \
httpd24 httpd24-httpd-devel httpd24-mod_ssl httpd24-mod_auth_kerb httpd24-mod_ldap \
httpd24-mod_session atlas-devel gcc-gfortran libffi-devel libtool-ltdl enchant" && \
yum install -y yum-utils && \
./prepare-yum-repositories rhel-server-rhscl-7-rpms && \
yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum -y clean all --enablerepo='*' && \
source scl_source enable rh-python36 && \
scl enable rh-python36 bash

ADD scl_enable /usr/share/container-scripts/
ENV BASH_ENV=/usr/share/container-scripts/scl_enable \
ENV=/usr/share/container-scripts/scl_enable \
PROMPT_COMMAND=". /usr/share/container-scripts/scl_enable"

USER 1001
21 changes: 21 additions & 0 deletions jenkins-slaves/jenkins-slave-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# jenkins-slave-python
Provides a docker image of the python runtime for use as a Jenkins slave.

## Build local
`docker build -t jenkins-slave-python .`

## Run local
For local running and experimentation run `docker run -i -t jenkins-slave-python /bin/bash` and have a play once inside the container.

## Build in OpenShift
```bash
oc process -f ../templates/jenkins-slave-generic-template.yml \
-p NAME=jenkins-slave-python \
-p SOURCE_CONTEXT_DIR=jenkins-slaves/jenkins-slave-python \
-p DOCKERFILE_PATH=Dockerfile
| oc create -f -
```
For all params see the list in the `../templates/jenkins-slave-generic-template.yml` or run `oc process --parameters -f ../templates/jenkins-slave-generic-template.yml`.

## Jenkins
Add a new Kubernetes Container template called `jenkins-slave-python` (if you've build and pushed the container image locally) and specify this as the node when running builds. If you're using the template attached; the `role: jenkins-slave` is attached and Jenkins should automatically discover the slave for you. Further instructions can be found [here](https://docs.openshift.com/container-platform/3.7/using_images/other_images/jenkins.html#using-the-jenkins-kubernetes-plug-in-to-run-jobs). Python installation commands are slightly modified from the SCL versions, which can be found [here](https://github.com/sclorg/s2i-python-container/tree/master/3.6).
59 changes: 59 additions & 0 deletions jenkins-slaves/jenkins-slave-python/prepare-yum-repositories
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# This script is used to prepare yum repositories, that are given as arguments.
# It is no-op if user also mounts the repo file(s) into the container during
# image build. This can be done by one of those commands:
#
# docker build -v /some/repo/file:/etc/yum.repos.d/sclorg_custom.repo
# docker build -v /some/repo/directory:/etc/yum.repos.d
# make CUSTOM_REPO=/some/repo/file/or/directory
#
# The last one works for projects where we have Makefile with the
# container-common-scripts support.

set -ex

# DEFAULT_REPOS and SKIP_REPOS_{ENABLE,DISABLE} are intentionally undocumented,
# but might be used if we need to change this behaviour.
# Once we realize there are real use cases for using those variables, we should
# document them properly.
DEFAULT_REPOS=${DEFAULT_REPOS:-"rhel-7-server-rpms rhel-7-server-optional-rpms"}
SKIP_REPOS_ENABLE=${SKIP_REPOS_ENABLE:-false}
SKIP_REPOS_DISABLE=${SKIP_REPOS_DISABLE:-false}

function is_subscribed() {
for f in /run/secrets/etc-pki-entitlement/*.pem ; do
[ -e "$f" ] && return 0
break
done
return 1
}

# DEBUGGING CASE! Mostly for 'make CUSTOM_REPO=/some/file/or/dir'.
test ! -f /etc/yum.repos.d/sclorg_custom.repo && \
! mountpoint /etc/yum.repos.d \
|| exit 0

# install yum-utils for yum-config-manager
yum install -y yum-utils

if [ "$SKIP_REPOS_DISABLE" = false ] && is_subscribed; then
# Disable only repos that might come from subscribed host, because there
# might be other repos provided by user or build system

disable_repos=
# Lines look like: "Repo-id : dist-tag-override/x86_64"
while IFS=' /' read -r _ _ repo_id _; do
case $repo_id in rhel-*)
disable_repos+=" $repo_id" ;;
esac
done <<<"$(yum repolist -v 2>/dev/null | grep Repo-id)"

if test -n "$disable_repos"; then
yum-config-manager --disable $disable_repos &> /dev/null
fi
fi

if [ ${SKIP_REPOS_ENABLE} = false ] && [ -n "${DEFAULT_REPOS}" -o $# -gt 0 ] ; then
yum-config-manager --enable ${DEFAULT_REPOS} "$@"
fi
2 changes: 2 additions & 0 deletions jenkins-slaves/jenkins-slave-python/scl_enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unset BASH_ENV PROMPT_COMMAND ENV
source scl_source enable rh-python36

0 comments on commit 7761b5a

Please sign in to comment.