Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python/Ruby/Dotnet support to GHA runner image #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Dockerfile.almalinux
shahidhs-ibm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM almalinux:9

ARG RUNNERREPO="https://github.com/actions/runner" RUNNERPATCH SDK ARCH
ARG RUNNERREPO="https://github.com/actions/runner" RUNNERPATCH SDK ARCH BTOOLS

RUN dnf update -y -q && \
dnf install -y -q wget git which langpacks-en glibc-all-langpacks sudo

RUN dnf install -y -q dnf-plugins-core && \
dnf config-manager --set-enabled crb

RUN dnf install -y -q dotnet-sdk-${SDK}.0 && \
echo "Using SDK - `dotnet --version`"
Expand Down Expand Up @@ -41,7 +44,19 @@ RUN mkdir -p /opt/runner && \

RUN dnf install -y -q cmake make automake autoconf m4 gcc gcc-c++ libtool epel-release

RUN rm -rf /tmp/runner /var/cache/dnf/* /tmp/runner.patch && \
COPY build-files/install-python.sh /tmp
COPY build-files/install-ruby.sh /tmp

RUN if [ "${BTOOLS}" -eq 1 ]; then \
dnf install -y -q java-11-openjdk openssl-devel ruby perl; \
chmod +x /tmp/install-python.sh; \
/tmp/install-python.sh; \
chmod +x /tmp/install-ruby.sh; \
/tmp/install-ruby.sh; \
chown -R almalinux:almalinux /opt/runner; \
fi

RUN rm -rf /tmp/runner /var/cache/dnf/* /tmp/runner.patch /tmp/install-python.sh /tmp/install-ruby.sh && \
dnf clean all

USER almalinux
Expand Down
16 changes: 14 additions & 2 deletions Dockerfile.ubuntu
shahidhs-ibm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:22.04

ARG RUNNERREPO="https://github.com/actions/runner" RUNNERPATCH SDK ARCH
ARG RUNNERREPO="https://github.com/actions/runner" RUNNERPATCH SDK ARCH BTOOLS

ENV DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -49,7 +49,19 @@ RUN mkdir -p /opt/runner && \

RUN apt-get -qq -y install cmake make automake autoconf m4 gcc-12-base libtool

RUN rm -rf /tmp/runner /tmp/runner.patch /tmp/convert-rpm.sh
COPY build-files/install-python.sh /tmp
COPY build-files/install-ruby.sh /tmp

RUN if [ "${BTOOLS}" -eq 1 ]; then \
apt-get -qq -y install openjdk-11-jdk libssl-dev ruby perl; \
chmod +x /tmp/install-python.sh; \
/tmp/install-python.sh; \
chmod +x /tmp/install-ruby.sh; \
/tmp/install-ruby.sh; \
chown -R ubuntu:ubuntu /opt/runner; \
fi

RUN rm -rf /tmp/runner /tmp/runner.patch /tmp/convert-rpm.sh /tmp/install-python.sh /tmp/install-ruby.sh

USER ubuntu

Expand Down
27 changes: 26 additions & 1 deletion build-files/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ install_runner() {
return $?
}

install_python() {
echo "Installing Python"
chmod +x /home/ubuntu/install-python.sh
sudo /home/ubuntu/install-python.sh
sudo chown ubuntu:ubuntu -R /opt/runner
return $?
}

install_ruby() {
echo "Installing Ruby"
chmod +x /home/ubuntu/install-ruby.sh
sudo /home/ubuntu/install-ruby.sh
sudo chown ubuntu:ubuntu -R /opt/runner
return $?
}

cleanup() {
rm -rf /home/ubuntu/build-image.sh /home/ubuntu/runner-${ARCH}.patch \
/tmp/runner /tmp/preseed-yaml
Expand All @@ -142,6 +158,11 @@ run() {
if [ ${RC} -eq 0 ]; then
install_runner
RC=$?
if [ ${BTOOLS} -eq 1 ]; then
install_python
install_ruby
RC=$?
fi
fi
fi
fi
Expand All @@ -153,7 +174,8 @@ export HOME=/home/ubuntu
ARCH=`uname -m`
SDK=""
RUNNERREPO="https://github.com/actions/runner"
while getopts "a:s:" opt
BTOOLS="0"
while getopts "a:s:t:" opt
do
case ${opt} in
a)
Expand All @@ -162,6 +184,9 @@ do
s)
SDK=${OPTARG}
;;
t)
BTOOLS=${OPTARG}
;;
*)
exit 4
;;
Expand Down
34 changes: 34 additions & 0 deletions build-files/install-python.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also cater for opensuse? We have in the rest of the system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a talk with Anup and he said we are not planning to support opensuse for ppc64le at least for the initial release. I have asked him to remove opensuse support as the present code is giving wrong impression to user.
@anup-kodlekere Please create a PR for removing opensuse from the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a single PR so that we can revisit and revert that to re-instate the opensuse code.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

if [ -f /etc/os-release ]; then
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
case $ID in
almalinux|centos|rhel)
sudo dnf install -y -q wget make gcc-c++ libtool zlib-devel libffi-devel libyaml-devel;;
ubuntu)
sudo apt-get install -y wget gcc g++ make libtool zlib1g-dev libffi-dev libyaml-dev;;
*) exit 1;;
esac
else
echo "Unknown OS distribution"
exit 1
fi

PYTHON_VERSIONS="3.8.18 3.10.13 3.12.1"
M_ARCH=$(uname -m)

for pyver in ${PYTHON_VERSIONS}
do
export PYTHON_VERSION=${pyver}
export PYTHON_MAJOR=${PYTHON_VERSION%.*.*}
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz
tar -xzf Python-${PYTHON_VERSION}.tgz
cd Python-${PYTHON_VERSION}
./configure --prefix=/opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH} --enable-shared --enable-optimizations --enable-ipv6 LDFLAGS=-Wl,-rpath=/opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH}/lib,--disable-new-dtags
make -j$(nproc)
sudo make install
sudo touch /opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH}.complete
sudo ln -s /opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH}/bin/python${PYTHON_MAJOR} /opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH}/bin/python
cd ..
rm -rf Python-${PYTHON_VERSION} Python-${PYTHON_VERSION}.tgz
done
35 changes: 35 additions & 0 deletions build-files/install-ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

if [ -f /etc/os-release ]; then
ID=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
case $ID in
almalinux|centos|rhel)
sudo dnf install -y -q wget make gcc-c++ libtool zlib-devel libffi-devel libyaml-devel openssl-devel java-11-openjdk ruby rubygem-rake perl;;
ubuntu)
sudo apt-get install -y wget gcc g++ make libtool zlib1g-dev libffi-dev libyaml-dev libssl-dev openjdk-11-jdk ruby;;
*) exit 0;;
esac
else
echo "Unknown OS distribution"
exit 0
fi

M_ARCH=$(uname -m)
if [ "${M_ARCH}" = "ppc64le" ]; then
M_ARCH=ppc64
fi

wget -O /tmp/ruby-build-v20240119.tar.gz https://github.com/rbenv/ruby-build/archive/refs/tags/v20240119.tar.gz
cd /tmp
tar -xzf ruby-build-*.tar.gz
sudo PREFIX=/usr/local ./ruby-build-*/install.sh

ruby-build --list| while IFS= read -r line; do
if [[ "$line" != *"picoruby"* ]] && [[ "$line" != *"truffleruby"* ]]; then
ruby-build $line /opt/runner/_work/_tool/Ruby/$line/${M_ARCH}
touch /opt/runner/_work/_tool/Ruby/$line/${M_ARCH}.complete
echo "Installed $line";
fi
done

rm -rf /tmp/ruby-build-v20240119.tar.gz ./ruby-build-*
9 changes: 7 additions & 2 deletions build-selfhosted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ usage() {
echo "Where flags:"
echo "-b [docker|podman] Image build tool to use - defaults to which it finds first"
echo "-s <sdk> SDK to use (6 or 7 ...). Default 6 for s390x and 7 for ppc64le"
echo "-t [1|0] Include tools/compilers - defaults to 0"
echo "-h Display this usage information"
echo
echo "If no distribution is specified then images for both are built"
Expand All @@ -14,14 +15,15 @@ usage() {
ARCH=`uname -m`
DISTROS=""
BUILDER=`which podman 2>/dev/null`
BTOOLS="0"
if [ -z ${BUILDER} ]; then
BUILDER=`which docker 2>/dev/null`
fi
if [ -z ${BUILDER} ]; then
echo "Need podman or docker installed" >&2
exit 1
fi
while getopts "b:hs:" opt
while getopts "b:ht:s:" opt
do
case "${opt}" in
b)
Expand All @@ -30,6 +32,9 @@ do
h)
usage
;;
t)
BTOOLS="${OPTARG}"
;;
s)
SDK="${OPTARG}"
;;
Expand Down Expand Up @@ -57,6 +62,6 @@ do
echo "${dist} not supported" >&2
else
${BUILDER} build -f Dockerfile.${dist} --build-arg RUNNERPATCH=build-files/runner-${ARCH}.patch \
--build-arg SDK=${SDK} --build-arg ARCH=${ARCH} --tag runner:${dist} .
--build-arg SDK=${SDK} --build-arg ARCH=${ARCH} --build-arg BTOOLS=${BTOOLS} --tag runner:${dist} .
fi
done
17 changes: 14 additions & 3 deletions setup-build-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ usage() {
echo "-s <SDK level> .NET SDK level"
echo " - Defaults to value in build script for ppc64le"
echo " - Ignored for s390x which uses an RPM"
echo "-t <1|0> - Include build tools/compilers in image. Defaults to 0."
echo "-h Display this usage information"
exit
}
Expand Down Expand Up @@ -75,8 +76,14 @@ build_image_in_container() {
echo "Copy the gha-service unit file into gha-builder"
lxc file push ${BUILD_PREREQS_PATH}/gha-runner.service "${BUILD_CONTAINER}/etc/systemd/system/gha-runner.service"

echo "Copy the install-python script into gha-builder"
lxc file push --mode 0755 "${BUILD_PREREQS_PATH}/install-python.sh" "${BUILD_CONTAINER}${BUILD_HOME}/install-python.sh"

echo "Copy the install-ruby script into gha-builder"
lxc file push --mode 0755 "${BUILD_PREREQS_PATH}/install-ruby.sh" "${BUILD_CONTAINER}${BUILD_HOME}/install-ruby.sh"

echo "Running build-image.sh"
lxc exec "${BUILD_CONTAINER}" --user 1000 --group 1000 -- ${BUILD_HOME}/build-image.sh -a ${ACTION_RUNNER} ${SDK}
lxc exec "${BUILD_CONTAINER}" --user 1000 --group 1000 -- ${BUILD_HOME}/build-image.sh -a ${ACTION_RUNNER} -s ${SDK} -t ${BTOOLS}
RC=$?

if [ ${RC} -eq 0 ]; then
Expand Down Expand Up @@ -113,6 +120,7 @@ prolog() {
export ACTION_RUNNER="https://github.com/actions/runner"
export EXPORT="distro/lxc-runner"
export SDK=""
export BTOOLS="0"

export OS_NAME="${OS_NAME:-ubuntu}"
export OS_VERSION="${OS_VERSION:-22.04}"
Expand All @@ -129,7 +137,7 @@ prolog() {
}

prolog
while getopts "a:o:hs:" opt
while getopts "a:o:ht:s:" opt
do
case "${opt}" in
a)
Expand All @@ -141,8 +149,11 @@ do
h)
usage
;;
t)
BTOOLS="${OPTARG}"
;;
s)
SDK="-s ${OPTARG}"
SDK="${OPTARG}"
;;
*)
usage
Expand Down
Loading