From f4f56f1d9c07768f7c69c4177c3089b342fc647e Mon Sep 17 00:00:00 2001 From: Brett Anspach Date: Fri, 1 Jul 2022 09:13:08 -0500 Subject: [PATCH] INF-2546 Node.js upgrade; add yarn/jest (#1) * EN-17254 - added "TODO" comment to "Dockerfile". * EN-17254 - updated dockerfile: added code that install yarn package manager. * EN-17254 - added "yarn test ..." command before sonar scanner execution to "entrypoint.sh" in order to generate coverage report. * INF-2546 Add step to upgrade Node.js to latest LTS release * INF-2546 Add step to upgrade Node.js to latest LTS release * INF-2546 Add step to upgrade nodejs; add step to execute yarn; bug fix for converting line endings to linux style * INF-2546 Remove debug command * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Fix conditional for running yarn * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Bug fix for https://github.com/nodejs/node/issues/41058 * INF-2546 Add jest dependency * INF-2546 Add jest dependency * INF-2546 Reorganized commands * INF-2546 Bug fix * INF-2546 Bug fix * INF-2546 Add jest dependency * INF-2546 Move all yarn/jest-related functions to entrypoint.sh to improve image build time * INF-2546 Add jest-sonar-reporter dependency * INF-2546 Move yarn back to Dockerfile; rename RUN_YARN to RUN_JEST Co-authored-by: Dmitry Moiseenko Co-authored-by: Brett Anspach --- Dockerfile | 45 +++++++++++++++++++++++++++++++++------------ entrypoint.sh | 6 ++++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 654ed1c..c422aac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,7 @@ +# HACK: Fix for "Error relocating /usr/bin/node: _ZSt28__throw_bad_array_new_lengthv: symbol not found" - https://github.com/nodejs/node/issues/41058#issuecomment-997348999 +FROM alpine:3.16 as libstdc-donor +RUN apk add --update --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/main libstdc++ + FROM sonarsource/sonar-scanner-cli:4.7 LABEL version="1.1.0" \ @@ -9,27 +13,35 @@ LABEL version="1.1.0" \ com.github.actions.icon="check" \ com.github.actions.color="green" -# Add Ingenio certificate to java keystore -COPY wildcard_corp_ingenio_com.pem . -RUN keytool -keystore /etc/ssl/certs/java/cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias sonarqube -file wildcard_corp_ingenio_com.pem - -# Update repository sources -RUN apk update - # Install Python 3 -RUN apk add --no-cache \ +RUN apk add --update --no-cache \ build-base \ python3 \ py3-pip - RUN python3 -m pip install --upgrade pip -# Install Ansible linter +# TODO: Install Ansible linter #RUN pip3 install ansible-lint +# Upgrade Node.js +RUN apk add --update --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/main \ + nodejs \ + npm +RUN apk upgrade --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/main \ + nodejs \ + npm + +# HACK: Fix for "Error relocating /usr/bin/node: _ZSt28__throw_bad_array_new_lengthv: symbol not found" - https://github.com/nodejs/node/issues/41058#issuecomment-997348999 +COPY --from=libstdc-donor /usr/lib/libstdc++.so.6.0.29 /usr/lib/libstdc++.so.6.0.29 +RUN rm /usr/lib/libstdc++.so.6 && ln -s /usr/lib/libstdc++.so.6.0.29 /usr/lib/libstdc++.so.6 + +# Install yarn +RUN apk add --update --no-cache \ + yarn + # Install PowerShell # https://docs.microsoft.com/en-us/powershell/scripting/install/install-alpine?view=powershell-7.2#installation-steps -RUN apk add --no-cache \ +RUN apk add --update --no-cache \ ca-certificates \ less \ ncurses-terminfo-base \ @@ -44,7 +56,7 @@ RUN apk add --no-cache \ icu-libs \ curl -RUN apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache \ +RUN apk add --update --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/main \ lttng-ust RUN wget -O powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v7.2.3/powershell-7.2.3-linux-alpine-x64.tar.gz; \ @@ -57,6 +69,15 @@ RUN wget -O powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/ SHELL ["pwsh", "-Command"] RUN Set-PSRepository PSGallery -InstallationPolicy Trusted -Verbose; Install-Module PSScriptAnalyzer -Repository PSGallery -Scope AllUsers -Verbose +# Add Ingenio certificate to java keystore +COPY wildcard_corp_ingenio_com.pem . +RUN keytool -keystore /etc/ssl/certs/java/cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias sonarqube -file wildcard_corp_ingenio_com.pem + +# Fix line endings for entrypoint.sh +RUN apk add --no-cache \ + dos2unix COPY entrypoint.sh /entrypoint.sh +RUN dos2unix /entrypoint.sh RUN chmod +x /entrypoint.sh + ENTRYPOINT ["/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index f4c1fed..f0725c1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -25,6 +25,12 @@ fi unset JAVA_HOME +if [[ "${RUN_JEST}" == "true" ]]; then + npm install -g jest-cli jest-sonar-reporter + yarn add jest jest-environment-jsdom + yarn test --coverage --coverageDirectory='coverage' +fi + sonar-scanner -Dsonar.projectBaseDir=${INPUT_PROJECTBASEDIR} ${INPUT_ARGS} _tmp_file=$(ls "${INPUT_PROJECTBASEDIR}/" | head -1)