From 99e28e601c1482c36ba97f046a52fe2e38f89d65 Mon Sep 17 00:00:00 2001 From: brais <26645694+braisvq1996@users.noreply.github.com> Date: Mon, 27 Nov 2023 09:26:57 +0100 Subject: [PATCH] Add Nodejs 20 agent (#970) --- .../continuous-integration-workflow.yml | 16 +++++ CHANGELOG.md | 1 + Makefile | 14 +++- .../nodejs20/docker/Dockerfile.ubi8 | 61 +++++++++++++++++ .../docker/contrib/bin/configure-agent | 63 ++++++++++++++++++ .../nodejs20/docker/contrib/bin/scl_enable | 3 + .../nodejs20/docker/yum.repos.d/centos8.repo | 13 ++++ .../docker/yum.repos.d/google-chrome.repo | 6 ++ .../nodejs20/ocp-config/Tailorfile | 5 ++ .../jenkins-agents/nodejs20/ocp-config/bc.yml | 66 +++++++++++++++++++ .../jenkins-agents/nodejs20/ocp-config/is.yml | 14 ++++ 11 files changed, 259 insertions(+), 3 deletions(-) create mode 100644 common/jenkins-agents/nodejs20/docker/Dockerfile.ubi8 create mode 100644 common/jenkins-agents/nodejs20/docker/contrib/bin/configure-agent create mode 100644 common/jenkins-agents/nodejs20/docker/contrib/bin/scl_enable create mode 100644 common/jenkins-agents/nodejs20/docker/yum.repos.d/centos8.repo create mode 100644 common/jenkins-agents/nodejs20/docker/yum.repos.d/google-chrome.repo create mode 100644 common/jenkins-agents/nodejs20/ocp-config/Tailorfile create mode 100644 common/jenkins-agents/nodejs20/ocp-config/bc.yml create mode 100644 common/jenkins-agents/nodejs20/ocp-config/is.yml diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index af639c37e..078ff7761 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -82,6 +82,22 @@ jobs: --build-arg nexusAuth=developer:s3cr3t \ . + jenkins-agent-nodejs20-ubi8: + name: Jenkins agent NodeJS 20 (UBI8) + runs-on: ubuntu-22.04 + steps: + - + name: Checkout repository + uses: actions/checkout@v4.1.1 + - + name: Build docker image + working-directory: common/jenkins-agents/nodejs20/docker + run: | + docker build --tag agent-nodejs20-test-ubi8 --file Dockerfile.ubi8 \ + --build-arg nexusUrl=https://nexus.example.com \ + --build-arg nexusAuth=developer:s3cr3t \ + . + jenkins-agent-python-ubi8: name: Jenkins agent Python (UBI8) runs-on: ubuntu-22.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index ce6b665fb..9c5ab4c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Added - Added secret scanning in docker plain ([#963](https://github.com/opendevstack/ods-quickstarters/pull/963)) +- Added Nodejs20 agent ([#962](https://github.com/opendevstack/ods-quickstarters/issues/962)) ### Modified diff --git a/Makefile b/Makefile index 8b4304fde..f8cc8d4b4 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,11 @@ install-jenkins-agent: install-jenkins-agent-golang install-jenkins-agent-jdk in .PHONY: install-jenkins-agent ## Update OpenShift resources related Jenkins agent resources. -apply-jenkins-agent-build: apply-jenkins-agent-golang-build apply-jenkins-agent-jdk-build apply-jenkins-agent-nodejs12-build apply-jenkins-agent-nodejs16-build apply-jenkins-agent-nodejs18-build apply-jenkins-agent-python-build apply-jenkins-agent-scala-build apply-jenkins-agent-terraform-build +apply-jenkins-agent-build: apply-jenkins-agent-golang-build apply-jenkins-agent-jdk-build apply-jenkins-agent-nodejs12-build apply-jenkins-agent-nodejs16-build apply-jenkins-agent-nodejs18-build apply-jenkins-agent-nodejs20-build apply-jenkins-agent-python-build apply-jenkins-agent-scala-build apply-jenkins-agent-terraform-build .PHONY: apply-jenkins-agent-build ## Start builds of Jenkins agents. -start-jenkins-agent-build: start-jenkins-agent-golang-build start-jenkins-agent-jdk-build start-jenkins-agent-nodejs12-build start-jenkins-agent-nodejs16-build start-jenkins-agent-nodejs18-build start-jenkins-agent-python-build start-jenkins-agent-scala-build start-jenkins-agent-terraform-build +start-jenkins-agent-build: start-jenkins-agent-golang-build start-jenkins-agent-jdk-build start-jenkins-agent-nodejs12-build start-jenkins-agent-nodejs16-build start-jenkins-agent-nodejs18-build start-jenkins-agent-nodejs20-build start-jenkins-agent-python-build start-jenkins-agent-scala-build start-jenkins-agent-terraform-build .PHONY: start-jenkins-agent-build @@ -54,7 +54,7 @@ start-jenkins-agent-jdk-build: # JENKINS AGENT NODEJS ## Install or update Jenkins Node agent resources. -install-jenkins-agent-nodejs: apply-jenkins-agent-nodejs12-build apply-jenkins-agent-nodejs16-build apply-jenkins-agent-nodejs18-build start-jenkins-agent-nodejs12-build start-jenkins-agent-nodejs16-build start-jenkins-agent-nodejs18-build +install-jenkins-agent-nodejs: apply-jenkins-agent-nodejs12-build apply-jenkins-agent-nodejs16-build apply-jenkins-agent-nodejs18-build apply-jenkins-agent-nodejs20-build start-jenkins-agent-nodejs12-build start-jenkins-agent-nodejs16-build start-jenkins-agent-nodejs18-build start-jenkins-agent-nodejs20-build .PHONY: install-jenkins-agent-nodejs ## Update OpenShift resources related to Jenkins Node agent image. @@ -70,6 +70,10 @@ apply-jenkins-agent-nodejs18-build: cd common/jenkins-agents/nodejs18/ocp-config && tailor apply --namespace $(ODS_NAMESPACE) .PHONY: apply-jenkins-agent-nodejs18-build +apply-jenkins-agent-nodejs20-build: + cd common/jenkins-agents/nodejs20/ocp-config && tailor apply --namespace $(ODS_NAMESPACE) +.PHONY: apply-jenkins-agent-nodejs20-build + ## Start build of BuildConfig "jenkins-agent-nodejs*". start-jenkins-agent-nodejs12-build: oc -n $(ODS_NAMESPACE) start-build jenkins-agent-nodejs12 --follow @@ -83,6 +87,10 @@ start-jenkins-agent-nodejs18-build: oc -n $(ODS_NAMESPACE) start-build jenkins-agent-nodejs18 --follow .PHONY: start-jenkins-agent-nodejs18-build +start-jenkins-agent-nodejs20-build: + oc -n $(ODS_NAMESPACE) start-build jenkins-agent-nodejs20 --follow +.PHONY: start-jenkins-agent-nodejs20-build + # JENKINS AGENT PYTHON ## Install or update Jenkins Python agent resources. install-jenkins-agent-python: apply-jenkins-agent-python-build start-jenkins-agent-python-build diff --git a/common/jenkins-agents/nodejs20/docker/Dockerfile.ubi8 b/common/jenkins-agents/nodejs20/docker/Dockerfile.ubi8 new file mode 100644 index 000000000..689dd8a04 --- /dev/null +++ b/common/jenkins-agents/nodejs20/docker/Dockerfile.ubi8 @@ -0,0 +1,61 @@ +FROM opendevstackorg/ods-jenkins-agent-base-ubi8:latest + +# Labels consumed by Red Hat build service +LABEL com.redhat.component="jenkins-agent-nodejs-20-rhel7-container" \ + name="openshift4/jenkins-agent-nodejs-20-rhel7" \ + architecture="x86_64" \ + io.k8s.display-name="Jenkins Agent Nodejs" \ + io.k8s.description="The jenkins agent nodejs image has the nodejs tools on top of the jenkins agent base image." \ + io.openshift.tags="openshift,jenkins,agent,nodejs" \ + maintainer="openshift-dev-services+jenkins@redhat.com" + +ARG nexusUrl +ARG nexusAuth + +ENV NODEJS_VERSION=20 \ + YARN_VERSION=1.22.19 \ + NPM_CONFIG_PREFIX=$HOME/.npm-global \ + PATH=$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ + LANG=en_US.UTF-8 \ + LC_ALL=en_US.UTF-8 + +COPY contrib/bin/configure-agent /usr/local/bin/configure-agent + +# Generate machine ID +RUN dbus-uuidgen > /etc/machine-id + +# Install NodeJS (https://rpm.nodesource.com/setup_${NODEJS_VERSION}.x does NOT work) +RUN INSTALL_PKGS="nodejs nodejs-nodemon make gcc-c++" && \ + yum module enable -y nodejs:${NODEJS_VERSION} && \ + yum install -y --setopt=tsflags=nodocs --disableplugin=subscription-manager $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + yum clean all -y + +# Install Yarn +# https://classic.yarnpkg.com/en/docs/install +RUN curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version $YARN_VERSION + +# Install Cypress dependencies +# https://docs.cypress.io/guides/getting-started/installing-cypress.html#System-requirements +COPY yum.repos.d/google-chrome.repo /etc/yum.repos.d/google-chrome.repo +COPY yum.repos.d/centos8.repo /etc/yum.repos.d/centos8.repo +RUN yum repolist \ + && yum install -y xorg-x11-server-Xvfb gtk2-devel gtk3-devel libnotify-devel GConf2 nss libXScrnSaver alsa-lib \ + && yum install -y --enablerepo google-chrome google-chrome-stable \ + && yum clean all -y + +RUN npm config set registry=$nexusUrl/repository/npmjs/ && \ + npm config set //$nexusUrl/repository/npmjs/:_auth=$(echo -n $nexusAuth | base64) && \ + npm config set email=no-reply@opendevstack.org && \ + npm config set ca=null && \ + npm config set strict-ssl=false && \ + yarn config set registry $nexusUrl/repository/npmjs/ -g && \ + echo node version: $(node --version) && \ + echo npm version: $(npm --version) && \ + echo npx version: $(npx --version) && \ + echo yarn version: $(yarn --version) + +RUN chown -R 1001:0 $HOME && \ + chmod -R g+rw $HOME + +USER 1001 diff --git a/common/jenkins-agents/nodejs20/docker/contrib/bin/configure-agent b/common/jenkins-agents/nodejs20/docker/contrib/bin/configure-agent new file mode 100644 index 000000000..02ab20288 --- /dev/null +++ b/common/jenkins-agents/nodejs20/docker/contrib/bin/configure-agent @@ -0,0 +1,63 @@ +#!/bin/bash + +# extract the different element of an url into a JSON structure +parse_url() { + # extract the protocol + proto="$(echo $1 | cut -f1 -d: )" + if [[ ! -z $proto ]] ; then + # remove the protocol + url="$(echo ${1/"$proto://"/})" + # extract the user (if any) + login="$(echo $url | grep @ | cut -d@ -f1)" + username="$(echo $login | cut -d: -f1)" + password="$(echo $login | cut -d: -f2)" + # extract the host + host_port="$(echo ${url/$login@/} | cut -d/ -f1) " + host="$(echo $host_port | cut -f1 -d:) " + + # by request - try to extract the port + port="$(echo $host_port | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" + # extract the uri (if any) + resource="/$(echo $url | grep / | cut -d/ -f2-)" + fi + echo -n "{ \"uri\": \"$1\" , \"url\": \"$url\" , \"proto\": \"$proto\" , \"login\": \"$login\" ," + echo " \"username\": \"$username\" , \"password\": \"$password\" , \"host\": \"$host\" , \"port\": \"$port\" }" +} + +get_npm_proxy_config(){ + local proto json + proto=$1 + json=$2 + username=$( echo $json | jq -r .username) + password=$( echo $json | jq -r .password) + host=$( echo $json | jq -r .host) + port=$( echo $json | jq -r .port) + proxy_url="$host:$port" + + if [ -n "$username" -a -n "$password" ]; then + proxy_url="$proto://$username:$password@$proxy_url" + fi + + echo $proxy_url +} + + +if [ -n "$http_proxy" ]; then + json=$( parse_url $http_proxy ) + proxy=$(get_npm_proxy_config http "$json") + npm -g config set proxy $proxy +fi + +if [ -n "$https_proxy" ]; then + json=$( parse_url $https_proxy ) + proxy=$(get_npm_proxy_config https "$json") + npm -g config set https_proxy $proxy +fi + +if [ -n "$no_proxy" ]; then + npm -g config set noproxy $no_proxy +fi + +if [ -n "$NPM_MIRROR_URL" ]; then + npm -g config set registry "$NPM_MIRROR_URL" +fi diff --git a/common/jenkins-agents/nodejs20/docker/contrib/bin/scl_enable b/common/jenkins-agents/nodejs20/docker/contrib/bin/scl_enable new file mode 100644 index 000000000..8f58103c1 --- /dev/null +++ b/common/jenkins-agents/nodejs20/docker/contrib/bin/scl_enable @@ -0,0 +1,3 @@ +# This will make scl collection binaries work out of box. +unset BASH_ENV PROMPT_COMMAND ENV +source scl_source enable rh-nodejs20 diff --git a/common/jenkins-agents/nodejs20/docker/yum.repos.d/centos8.repo b/common/jenkins-agents/nodejs20/docker/yum.repos.d/centos8.repo new file mode 100644 index 000000000..c4d61f43b --- /dev/null +++ b/common/jenkins-agents/nodejs20/docker/yum.repos.d/centos8.repo @@ -0,0 +1,13 @@ +[centos-baseos] +name=CentOS-8-BaseOS +baseurl=http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/ +enabled=1 +gpgcheck=1 +gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official + +[centos-appstream] +name=CentOS-8-AppStream +baseurl=http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/ +enabled=1 +gpgcheck=1 +gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official diff --git a/common/jenkins-agents/nodejs20/docker/yum.repos.d/google-chrome.repo b/common/jenkins-agents/nodejs20/docker/yum.repos.d/google-chrome.repo new file mode 100644 index 000000000..96e7eece3 --- /dev/null +++ b/common/jenkins-agents/nodejs20/docker/yum.repos.d/google-chrome.repo @@ -0,0 +1,6 @@ +[google-chrome] +name=google-chrome +baseurl=https://dl.google.com/linux/chrome/rpm/stable/$basearch +enabled=0 +gpgcheck=1 +gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub diff --git a/common/jenkins-agents/nodejs20/ocp-config/Tailorfile b/common/jenkins-agents/nodejs20/ocp-config/Tailorfile new file mode 100644 index 000000000..a406c7ad9 --- /dev/null +++ b/common/jenkins-agents/nodejs20/ocp-config/Tailorfile @@ -0,0 +1,5 @@ +namespace ods +selector app=jenkins-agent-nodejs20 +param-file ../../../../../ods-configuration/ods-core.env +ignore-unknown-parameters true +bc,is diff --git a/common/jenkins-agents/nodejs20/ocp-config/bc.yml b/common/jenkins-agents/nodejs20/ocp-config/bc.yml new file mode 100644 index 000000000..a87e1f160 --- /dev/null +++ b/common/jenkins-agents/nodejs20/ocp-config/bc.yml @@ -0,0 +1,66 @@ +apiVersion: template.openshift.io/v1 +kind: Template +metadata: + name: jenkins-agent-nodejs20 +parameters: +- name: ODS_BITBUCKET_PROJECT + description: Bitbucket project name. + value: opendevstack +- name: NEXUS_URL + required: true +- name: NEXUS_AUTH + required: true +- name: REPO_BASE + required: true +- name: ODS_IMAGE_TAG + required: true + value: latest +- name: ODS_GIT_REF + required: true +- name: JENKINS_AGENT_DOCKERFILE_PATH + value: Dockerfile.ubi8 + description: Dockerfile variant to use +objects: +- apiVersion: v1 + kind: BuildConfig + metadata: + name: jenkins-agent-nodejs20 + labels: + app: jenkins-agent-nodejs20 + spec: + failedBuildsHistoryLimit: 5 + nodeSelector: null + output: + to: + kind: ImageStreamTag + name: jenkins-agent-nodejs20:${ODS_IMAGE_TAG} + postCommit: {} + resources: + limits: + cpu: "1" + memory: "2Gi" + requests: + cpu: "200m" + memory: "1Gi" + runPolicy: Serial + source: + contextDir: common/jenkins-agents/nodejs20/docker + git: + ref: ${ODS_GIT_REF} + uri: ${REPO_BASE}/${ODS_BITBUCKET_PROJECT}/ods-quickstarters.git + sourceSecret: + name: cd-user-token + type: Git + strategy: + dockerStrategy: + buildArgs: + - name: nexusUrl + value: ${NEXUS_URL} + - name: nexusAuth + value: ${NEXUS_AUTH} + dockerfilePath: ${JENKINS_AGENT_DOCKERFILE_PATH} + from: + kind: ImageStreamTag + name: jenkins-agent-base:${ODS_IMAGE_TAG} + type: Docker + successfulBuildsHistoryLimit: 5 diff --git a/common/jenkins-agents/nodejs20/ocp-config/is.yml b/common/jenkins-agents/nodejs20/ocp-config/is.yml new file mode 100644 index 000000000..44403a7e2 --- /dev/null +++ b/common/jenkins-agents/nodejs20/ocp-config/is.yml @@ -0,0 +1,14 @@ +apiVersion: template.openshift.io/v1 +kind: Template +metadata: + name: jenkins-agent-nodejs20 +objects: +- apiVersion: v1 + kind: ImageStream + metadata: + name: jenkins-agent-nodejs20 + labels: + app: jenkins-agent-nodejs20 + spec: + lookupPolicy: + local: false