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

ansible: arm cross compiler updates for Node.js 18 #2912

Merged
merged 6 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 17 additions & 8 deletions ansible/roles/docker/files/cc-selector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,36 @@
# cross-compiler-ubuntu1604-armv7-gcc-6
# cross-compiler-ubuntu1804-armv7-gcc-6
# cross-compiler-ubuntu1804-armv7-gcc-8
# cross-compiler-rhel8-armv7-gcc-8-glibc-2.28

rpi_newer_tools_base="/opt/raspberrypi/rpi-newer-crosstools/"
base_4_9_4="${rpi_newer_tools_base}x64-gcc-4.9.4-binutils-2.28/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-"
base_6="${rpi_newer_tools_base}x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-"
base_8="${rpi_newer_tools_base}x64-gcc-8.3.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-"
base_8_glibc_2_28="${rpi_newer_tools_base}x64-gcc-8.3.0-glibc-2.28/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-"

flags_armv6="-march=armv6zk"
flags_armv7="-march=armv7-a"

function run {
local label="$1"

export arm_type=$(echo $label | sed -E 's/^cross-compiler-ubuntu1[68]04-(armv[67])-gcc-.*$/\1/')
export gcc_version=$(echo $label | sed -E 's/^cross-compiler-ubuntu1[68]04-armv[67]-gcc-(4\.9\.4|6|8)/\1/')
export arm_type=$(echo $label | sed -E 's/^cross-compiler-(ubuntu1[68]04|rhel8)-(armv[67])-gcc-.*$/\2/')
export gcc_version=$(echo $label | sed -E 's/^cross-compiler-(ubuntu1[68]04|rhel8)-armv[67]-gcc-(4\.9\.4|6|8)/\2/')
export git_branch="cc-${arm_type}"
export host_os=$(echo $label | sed -E 's/^cross-compiler-(ubuntu1[68]04|rhel8)-(armv[67])-gcc-.*$/\1/')

if [[ ! "$arm_type" =~ ^armv[67]$ ]]; then
echo "Could not determine ARM type from '$label'"
exit 1
fi
if [[ ! "$gcc_version" =~ ^(4\.9\.4|6|8)$ ]]; then
if [[ ! "$gcc_version" =~ ^(4\.9\.4|6|8|8-glibc-2.28)$ ]]; then
echo "Could not determine ARM type from '$label'"
exit 1
fi

gcc_version_safe="$(echo $gcc_version | sed -E 's/\./_/g')"
gcc_host_version="$(echo $gcc_version | sed -E 's/\.4//g')" # 4.9.4 -> 4.9

gcc_version_safe="$(echo $gcc_version | sed -E 's/[\.-]/_/g')"
gcc_host_version="$(echo $gcc_version | sed -E 's/([^-]+).*$/\1/g' | sed -E 's/\.4//g')" # 4.9.4 -> 4.9
base_varname="base_${gcc_version_safe}"
flags_varname="flags_${arm_type}"

Expand All @@ -44,10 +47,16 @@ function run {

export ARCH="${arm_type}l"
export DESTCPU=arm
export CC_host="ccache gcc-${gcc_host_version} -m32"
export CXX_host="ccache g++-${gcc_host_version} -m32"
if [ "$host_os" = "rhel8" ]; then
export CC_host="ccache gcc -m32"
Copy link
Member

Choose a reason for hiding this comment

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

you're sure this is going to be OK? do we not have the option to version this? IIRC we added the host version because it was picking the wrong version because it happened to be the default on the machine, so we went with the version specifier. But maybe that's not an option with rhel in this setup?

Copy link
Member Author

Choose a reason for hiding this comment

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

The RHEL 8 option would be GCC toolsets (the equivalent of devtoolsets in CentOS/RHEL 7). In those cases it's the path to the toolset that changes, not the name of the binary. I could add a check if the gcc version is not 8 (the default in RHEL 8) and attempt to load a GCC toolset, although the container hasn't installed any extra ones.

Refs: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/developing_c_and_cpp_applications_in_rhel_8/additional-toolsets-for-development_developing-applications

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated this to attempt to load a gcc-toolset if the host gcc version doesn't match.

export CXX_host="ccache g++ -m32"
else
export CC_host="ccache gcc-${gcc_host_version} -m32"
export CXX_host="ccache g++-${gcc_host_version} -m32"
fi
export CC="ccache ${!base_varname}gcc ${!flags_varname}"
export CXX="ccache ${!base_varname}g++ ${!flags_varname}"
env | grep ccache
}

run $1
65 changes: 65 additions & 0 deletions ansible/roles/docker/templates/rhel8_arm_cross.Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
FROM registry.access.redhat.com/ubi8:latest

ENV LC_ALL C
ENV USER {{ server_user }}
ENV JOBS {{ server_jobs | default(ansible_processor_vcpus) }}
ENV SHELL /bin/bash
ENV PATH /usr/lib64/ccache:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV NODE_COMMON_PIPE /home/{{ server_user }}/test.pipe
ENV NODE_TEST_DIR /home/{{ server_user }}/tmp
ENV OSTYPE linux-gnu
ENV OSVARIANT docker
ENV DESTCPU {{ arch }}
ENV ARCH {{ arch }}

# ccache is not in the default repositories so get it from EPEL 8.
RUN dnf install --disableplugin=subscription-manager -y \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
&& dnf update --disableplugin=subscription-manager -y \
&& dnf install --disableplugin=subscription-manager -y \
ccache \
gcc-c++ \
git \
glibc-devel.i686 \
java-17-openjdk-headless \
make \
libatomic.i686 \
libstdc++-devel \
libstdc++-devel.i686 \
python3 \
procps-ng \
xz \
&& dnf --disableplugin=subscription-manager clean all

RUN groupadd -r -g {{ server_user_gid.stdout_lines[0] }} {{ server_user }} \
&& adduser -r -m -d /home/{{ server_user }}/ \
-g {{ server_user_gid.stdout_lines[0] }} \
-u {{ server_user_uid.stdout_lines[0] }} {{ server_user }}

# Relax crypto policies to allow Node.js tests to pass
RUN update-crypto-policies --set LEGACY

VOLUME /home/{{ server_user }}/ /home/{{ server_user }}/.ccache

ENV PYTHON /usr/bin/python3

RUN pip3 install tap2junit

RUN git clone https://github.com/rvagg/rpi-newer-crosstools.git /opt/raspberrypi/rpi-newer-crosstools

COPY cc-selector.sh /opt/raspberrypi/cc-selector.sh

RUN chmod 755 /opt/raspberrypi/cc-selector.sh

USER {{ server_user }}:{{ server_user }}

ENV CCACHE_TEMPDIR /home/{{ server_user }}/.ccache/{{ item.name }}

WORKDIR /home/{{ server_user }}

CMD cd /home/{{ server_user }} \
&& curl https://ci.nodejs.org/jnlpJars/slave.jar -O \
&& java -Xmx{{ server_ram|default('128m') }} \
-jar /home/{{ server_user }}/slave.jar \
-jnlpUrl {{ jenkins_url }}/computer/{{ item.name }}/slave-agent.jnlp \
-secret {{ item.secret }}
64 changes: 64 additions & 0 deletions ansible/roles/jenkins-worker/templates/rpi_buster.Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM balenalib/rpi-raspbian:buster

ENV LC_ALL=C \
USER={{ server_user }} \
JOBS={{ jobs_env }} \
SHELL=/bin/bash \
HOME=/home/{{ server_user }} \
PATH=/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
NODE_COMMON_PIPE=/home/{{ server_user }}/test.pipe \
NODE_TEST_DIR=/home/{{ server_user }}/tmp \
OSTYPE=linux-gnu \
OSVARIANT=docker \
DESTCPU=arm \
ARCH={{ arch }} \
CCACHE_TEMPDIR=/home/{{ server_user }}/.ccache/{{ inventory_hostname }} \
DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y \
g++-8 \
gcc-8 \
git \
make \
ccache \
python2.7 \
python \
openssh-client \
gzip \
xz-utils \
curl \
libffi-dev \
zlib1g-dev && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*

RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 50 && \
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-8 50 && \
update-alternatives --install /usr/bin/cpp cpp /usr/bin/gcc-8 50 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 50 && \
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-8 50

RUN mkdir /python && \
cd /python && \
curl https://github.com/python/cpython/archive/refs/tags/v3.9.4.tar.gz -L --output v3.9.4.tar.gz && \
tar xf v3.9.4.tar.gz && \
cd cpython-3.9.4 && \
./configure && \
make install && \
rm -rf /python

RUN addgroup \
--gid {{ server_user_gid.stdout_lines[0] }} \
{{ server_user }} && \
adduser \
--gid {{ server_user_gid.stdout_lines[0] }} \
--uid {{ server_user_uid.stdout_lines[0] }} \
--disabled-password \
--gecos {{ server_user }} \
{{ server_user }}

VOLUME /home/{{ server_user }}/

USER iojs:iojs

ENTRYPOINT [ "tail", "-f", "/dev/null" ]
6 changes: 4 additions & 2 deletions ansible/roles/jenkins-worker/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ raspberry_pi: {
{ name: 'jessie', template: 'rpi_jessie.Dockerfile.j2' }
],
armv7l: [
{ name: 'stretch', template: 'rpi_stretch.Dockerfile.j2' }
{ name: 'stretch', template: 'rpi_stretch.Dockerfile.j2' },
{ name: 'buster', template: 'rpi_buster.Dockerfile.j2' }
],
arm64: [
{ name: 'stretch', template: 'rpi_stretch.Dockerfile.j2' }
{ name: 'stretch', template: 'rpi_stretch.Dockerfile.j2' },
{ name: 'buster', template: 'rpi_buster.Dockerfile.j2' }
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions jenkins/scripts/VersionSelectorScript.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def buildExclusions = [
[ /^cross-compiler-ubuntu1804-armv7-gcc-6/, anyType, lt(14) ],
[ /^cross-compiler-ubuntu1804-armv7-gcc-6/, anyType, gte(16) ],
[ /^cross-compiler-ubuntu1804-armv7-gcc-8/, anyType, lt(16) ],
[ /^cross-compiler-ubuntu1804-armv7-gcc-8/, anyType, gte(18) ],
[ /^cross-compiler-rhel8-armv7-gcc-8-glibc-2.28/,anyType, lt(18) ],
[ /^ubuntu1604-arm64/, anyType, gte(14) ],

// Windows -----------------------------------------------
Expand Down