From d580a19fba7a7de65e8d200ed2e2bad431be40cc Mon Sep 17 00:00:00 2001 From: Andrew Ying Date: Mon, 18 Nov 2024 11:15:36 +0000 Subject: [PATCH] Download runner tools to images --- helpers/linux-install-tools | 46 +++++++++++++++++++++++++++++++++ ubuntu-22.04/Dockerfile | 31 ++++++++++++++++++++-- ubuntu-22.04/toolchain.json | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 helpers/linux-install-tools create mode 100644 ubuntu-22.04/toolchain.json diff --git a/helpers/linux-install-tools b/helpers/linux-install-tools new file mode 100644 index 0000000..06d8ec3 --- /dev/null +++ b/helpers/linux-install-tools @@ -0,0 +1,46 @@ +#!/bin/bash + +for tool in $(jq -r '.[]' ./toolchain.json); do + TOOL_NAME=$(echo "$tool" | jq '.name') + [ -z $TOOL_NAME ] && exit 1 + + TOOL_MANIFEST_URL=$(echo "$tool" | jq '.url') + [ -z $TOOL_MANIFEST_URL ] && exit 1 + TOOL_MANIFEST=$(curl -s $TOOL_MANIFEST_URL) + + for version in $(echo "$tool" | jq -r '.versions[]'); do + for check_version in $(echo "$TOOL_MANIFEST" | jq -r '.[]'); do + if [[ $(echo "$check_version" | jq '.version') != $version ]]; then + continue + fi + + for check_file in $(echo "$check_version" | jq -r '.files[]'); do + TOOL_PLATFORM=$(echo "$tool" | jq '.platform') + TOOL_ARCH=$(echo "$tool" | jq '.arch') + TOOL_PLATFORM_VERSION=$(echo "$tool" | jq '.platform_version') + + if [ ! -z $TOOL_PLATFORM ]; then + [ $TOOL_PLATFORM != $(echo "$check_file" | jq '.platform') ] && continue + fi + if [ ! -z $TOOL_ARCH ]; then + [ $TOOL_ARCH != $(echo "$check_file" | jq '.arch') ] && continue + fi + if [ ! -z $TOOL_PLATFORM_VERSION ]; then + [ $TOOL_PLATFORM_VERSION != $(echo "$check_file" | jq '.platform_version') ] && continue + fi + + FILENAME=$(echo "$check_file" | jq '.filename') + DOWNLOAD_URL=$(echo "$check_file" | jq '.download_url') + curl -o /tmp/build/$FILENAME $DOWNLOAD_URL || exit 1 + mkdir -p /tmp/build/$FILENAME-dir + tar -xzf /tmp/build/$FILENAME -C /tmp/build/$FILENAME-dir + rm /tmp/build/$FILENAME + cd /tmp/build/$FILENAME-dir || exit 1 + bash ./setup.sh + cd .. + rm -rf $FILENAME-dir + break + done + done + done +done diff --git a/ubuntu-22.04/Dockerfile b/ubuntu-22.04/Dockerfile index 37ea139..f79bb84 100644 --- a/ubuntu-22.04/Dockerfile +++ b/ubuntu-22.04/Dockerfile @@ -46,15 +46,31 @@ ARG PYTHON_VERSION_SHORT ENV NODEJS_VERSION=22.x ENV NVM_VERSION=0.40.1 +ENV AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache +ENV RUNNER_TOOL_CACHE=/opt/hostedtoolcache ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update -y \ - && apt-get install --no-install-recommends --no-install-suggests -y \ +RUN cat <> /etc/apt/apt.conf.d/10dpkg-options +Dpkg::Options { + "--force-confdef"; + "--force-confold"; +} +EOF +RUN cat <> /etc/apt/apt.conf.d/02autoremove +APT::Get::AutomaticRemove "0"; +APT::Get::HideAutoRemove "1"; +EOF +RUN echo "APT::Acquire::Retries \"10\";" > /etc/apt/apt.conf.d/80retries \ + && echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes + +RUN apt-get update \ + && apt-get install --no-install-recommends --no-install-suggests \ apt-transport-https \ ca-certificates \ curl \ gcc \ gnupg \ + jq \ libbz2-1.0 \ libev4 \ libffi8 \ @@ -139,5 +155,16 @@ RUN echo 'session required pam_limits.so' >> /etc/pam.d/common-session \ && echo '* soft stack 16384' >> /etc/security/limits.conf \ && echo '* hard stack 16384' >> /etc/security/limits.conf +COPY ../helpers/linux-install-tools /tmp/build/ +COPY toolchain.json /tmp/build/ +RUN set -x \ + && mkdir -p ${AGENT_TOOLSDIRECTORY} \ + && mkdir -p ${AGENT_TOOLSDIRECTORY} \ + && chown -R runner:runner ${AGENT_TOOLSDIRECTORY} \ + && chmod -R 0777 ${AGENT_TOOLSDIRECTORY} \ + && cd /tmp/build \ + && chmod +x linux-install-tools \ + && bash ./linux-install-tools + USER runner WORKDIR /workspace diff --git a/ubuntu-22.04/toolchain.json b/ubuntu-22.04/toolchain.json new file mode 100644 index 0000000..0f06bf7 --- /dev/null +++ b/ubuntu-22.04/toolchain.json @@ -0,0 +1,51 @@ +[ + { + "name": "Python", + "url" : "https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json", + "platform" : "linux", + "platform_version": "22.04", + "arch": "x64", + "versions": [ + "3.7.*", + "3.8.*", + "3.9.*", + "3.10.*", + "3.11.*", + "3.12.*" + ] + }, + { + "name": "PyPy", + "arch": "x64", + "platform" : "linux", + "versions": [ + "3.7", + "3.8", + "3.9", + "3.10" + ] + }, + { + "name": "node", + "url" : "https://raw.githubusercontent.com/actions/node-versions/main/versions-manifest.json", + "platform" : "linux", + "arch": "x64", + "versions": [ + "18.*", + "20.*", + "22.*" + ] + }, + { + "name": "go", + "url" : "https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json", + "arch": "x64", + "platform" : "linux", + "versions": [ + "1.21.*", + "1.22.*", + "1.23.*" + ], + "default": "1.23.*" + } +]