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 all 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
21 changes: 19 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,21 @@ 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 --chmod=755 build-files/install-python.sh /tmp
COPY --chmod=755 build-files/install-ruby.sh /tmp

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

RUN if [ "${BTOOLS}" -eq 1 ]; then \
dnf install -y -q dotnet-sdk-[6-7-8]*; \
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 --chmod=755 build-files/install-python.sh /tmp
COPY --chmod=755 build-files/install-ruby.sh /tmp
COPY --chmod=755 build-files/install-dotnet.sh /tmp

RUN if [ "${BTOOLS}" -eq 1 ]; then \
apt-get -qq -y install openjdk-11-jdk libssl-dev ruby perl; \
/tmp/install-python.sh; \
/tmp/install-ruby.sh; \
/tmp/install-dotnet.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 /tmp/install-dotnet.sh

USER ubuntu

Expand Down
43 changes: 41 additions & 2 deletions build-files/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ update_fresh_container() {
}

setup_dotnet_sdk() {
if [[ "${ARCH}" = "ppc64le" && ${SDK} -eq 6 ]]; then
echo "DOTNET ${SDK} is not supported on architecture ${ARCH}" >&2
return 1
fi

MIRROR="https://mirror.lchs.network/pub/almalinux/9.3/AppStream/${ARCH}/os/Packages"
case "${SDK}" in
7)
Expand Down Expand Up @@ -124,9 +129,33 @@ 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 $?
}

install_dotnet() {
echo "Installing DOTNET"
chmod +x /home/ubuntu/install-dotnet.sh
sudo /home/ubuntu/install-dotnet.sh
return $?
}

cleanup() {
rm -rf /home/ubuntu/build-image.sh /home/ubuntu/runner-${ARCH}.patch \
/tmp/runner /tmp/preseed-yaml
/tmp/runner /tmp/preseed-yaml \
/home/ubuntu/install-python.sh /home/ubuntu/install-ruby.sh /home/ubuntu/install-dotnet.sh
}

run() {
Expand All @@ -142,6 +171,12 @@ run() {
if [ ${RC} -eq 0 ]; then
install_runner
RC=$?
if [ ${BTOOLS} -eq 1 ]; then
install_python
install_ruby
install_dotnet
RC=$?
fi
fi
fi
fi
Expand All @@ -153,7 +188,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 +198,9 @@ do
s)
SDK=${OPTARG}
;;
t)
BTOOLS=${OPTARG}
;;
*)
exit 4
;;
Expand Down
75 changes: 75 additions & 0 deletions build-files/install-dotnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

retrieve_dotnet_pkgs() {
echo "Retrieving dotnet packages"
pushd /tmp >/dev/null
for pkg in ${PKGS}
do
RPM="${pkg}.${ARCH}.rpm"
wget -q ${MIRROR}/${RPM}
if [ ${ID} == "ubuntu" ]; then
echo -n "Converting ${RPM}... "
alien -d ${RPM} |& grep -v ^warning
if [ $? -ne 0 ]; then
exit 2
fi
rm -f ${RPM}
fi
done

echo "Installing dotnet packages"
dpkg --install /tmp/*.deb
rm -rf /tmp/*.deb
}

. /etc/os-release
DOTNET_VERSIONS="6 7 8"
ARCH=`uname -m`
MIRROR="https://mirror.lchs.network/pub/almalinux/9.3/AppStream/${ARCH}/os/Packages"

if [ "${ARCH}" == "ppc64le" ]; then
DOTNET_VERSIONS="8"
elif [ "${ARCH}" == "s390x" ]; then
DOTNET_VERSIONS="7 8"
else
DOTNET_VERSIONS="6 7 8"
fi

for dotnetver in ${DOTNET_VERSIONS}
do
case "${dotnetver}" in
8)
PKGS="dotnet-apphost-pack-8.0-8.0.1-1.el9_3 dotnet-host-8.0.1-1.el9_3"
PKGS="${PKGS} dotnet-hostfxr-8.0-8.0.1-1.el9_3 dotnet-targeting-pack-8.0-8.0.1-1.el9_3"
PKGS="${PKGS} dotnet-templates-8.0-8.0.101-1.el9_3 dotnet-runtime-8.0-8.0.1-1.el9_3"
PKGS="${PKGS} dotnet-sdk-8.0-8.0.101-1.el9_3 aspnetcore-runtime-8.0-8.0.1-1.el9_3"
PKGS="${PKGS} aspnetcore-targeting-pack-8.0-8.0.1-1.el9_3 netstandard-targeting-pack-2.1-8.0.101-1.el9_3"
retrieve_dotnet_pkgs
;;
7)
PKGS="dotnet-apphost-pack-7.0-7.0.15-1.el9_3 dotnet-host-8.0.1-1.el9_3"
PKGS="${PKGS} dotnet-hostfxr-7.0-7.0.15-1.el9_3 dotnet-targeting-pack-7.0-7.0.15-1.el9_3"
PKGS="${PKGS} dotnet-templates-7.0-7.0.115-1.el9_3 dotnet-runtime-7.0-7.0.15-1.el9_3"
PKGS="${PKGS} dotnet-sdk-7.0-7.0.115-1.el9_3 aspnetcore-runtime-7.0-7.0.15-1.el9_3"
PKGS="${PKGS} aspnetcore-targeting-pack-7.0-7.0.15-1.el9_3 netstandard-targeting-pack-2.1-8.0.101-1.el9_3"
retrieve_dotnet_pkgs
;;
6)
PKGS="dotnet-host-8.0.1-1.el9_3 dotnet-apphost-pack-6.0-6.0.26-1.el9_3"
PKGS="${PKGS} dotnet-hostfxr-6.0-6.0.26-1.el9_3 dotnet-targeting-pack-6.0-6.0.26-1.el9_3"
PKGS="${PKGS} dotnet-templates-6.0-6.0.126-1.el9_3 dotnet-runtime-6.0-6.0.26-1.el9_3"
PKGS="${PKGS} dotnet-sdk-6.0-6.0.126-1.el9_3 aspnetcore-runtime-6.0-6.0.26-1.el9_3"
PKGS="${PKGS} aspnetcore-targeting-pack-6.0-6.0.26-1.el9_3 netstandard-targeting-pack-2.1-8.0.101-1.el9_3"
retrieve_dotnet_pkgs
;;
*)
echo "Unsupported DOTNET version ${dotnetver}" >&2
exit 1
;;
esac
done

echo "List all installed .NET SDKs - `dotnet --list-sdks`"

exit 0

38 changes: 38 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,38 @@
#!/bin/bash

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

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 gcc-c++ make libtool zlib-devel libffi-devel libyaml-devel libxml2-devel libxslt-devel openssl-devel sqlite-devel;;
ubuntu)
sudo apt-get install -y wget gcc g++ make libtool zlib1g-dev libffi-dev libyaml-dev libxml2-dev libxslt1-dev libssl-dev libsqlite3-dev;;
*)
echo "This OS is not supported."
exit 1;;
esac
else
echo "Unknown OS distribution."
exit 1
fi

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 --enable-loadable-sqlite-extensions 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
sudo ln -s /opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH}/bin/pip${PYTHON_MAJOR} /opt/runner/_work/_tool/Python/${PYTHON_VERSION}/${M_ARCH}/bin/pip
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
20 changes: 17 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,17 @@ 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 "Copy the install-dotnet script into gha-builder"
lxc file push --mode 0755 "${BUILD_PREREQS_PATH}/install-dotnet.sh" "${BUILD_CONTAINER}${BUILD_HOME}/install-dotnet.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 +123,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 +140,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 +152,11 @@ do
h)
usage
;;
t)
BTOOLS="${OPTARG}"
;;
s)
SDK="-s ${OPTARG}"
SDK="${OPTARG}"
;;
*)
usage
Expand Down
Loading