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

chore(mojaloop/#3446): nodejs upgrade #209

Merged
merged 3 commits into from
Oct 12, 2023
Merged
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
186 changes: 121 additions & 65 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ version: 2.1
# Orbs used in this pipeline
##
orbs:
slack: circleci/slack@4.9.3 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
slack: circleci/slack@4.12.5 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
pr-tools: mojaloop/pr-tools@0.1.10 # Ref: https://github.com/mojaloop/ci-config/
gh: circleci/github-cli@2.1.0
gh: circleci/github-cli@2.2.0
anchore: anchore/anchore-engine@1.9.0
deploy-kube: mojaloop/deployment@0.1.6

Expand All @@ -26,8 +26,8 @@ defaults_Dependencies: &defaults_Dependencies |
apk --no-cache add openssh-client
apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake jq
apk add --no-cache -t openssl ncurses coreutils libgcc linux-headers grep util-linux binutils findutils
npm config set unsafe-perm true
npm install -g node-gyp
apk --no-cache add librdkafka-dev


defaults_awsCliDependencies: &defaults_awsCliDependencies |
apk --no-cache add aws-cli
Expand All @@ -41,7 +41,7 @@ defaults_license_scanner: &defaults_license_scanner
defaults_export_version_from_package: &defaults_export_version_from_package
name: Format the changelog into the github release body and get release tag
command: |
git diff --no-indent-heuristic master~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
git diff --no-indent-heuristic main~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
echo 'export RELEASE_CHANGES=`cat /tmp/changes`' >> $BASH_ENV
echo 'export RELEASE_TAG=`cat package-lock.json | jq -r .version`' >> $BASH_ENV

Expand All @@ -51,18 +51,85 @@ defaults_configure_git: &defaults_configure_git
git config user.email ${GIT_CI_EMAIL}
git config user.name ${GIT_CI_USER}

defaults_configure_nvmrc: &defaults_configure_nvmrc
name: Configure NVMRC
command: |
if [ -z "$NVMRC_VERSION" ]; then
echo "==> Configuring NVMRC_VERSION!"

export ENV_DOT_PROFILE=$HOME/.profile
touch $ENV_DOT_PROFILE

export NVMRC_VERSION=$(cat $CIRCLE_WORKING_DIRECTORY/.nvmrc)
echo "export NVMRC_VERSION=$NVMRC_VERSION" >> $ENV_DOT_PROFILE
fi
echo "NVMRC_VERSION=$NVMRC_VERSION"

defaults_configure_nvm: &defaults_configure_nvm
name: Configure NVM
command: |
touch $HOME/.profile
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
echo "Installing Node version: $(cat .nvmrc)"
nvm install $(cat .nvmrc)
nvm alias default $(cat .nvmrc)
nvm use $(cat .nvmrc)
cd $HOME
export ENV_DOT_PROFILE=$HOME/.profile
touch $ENV_DOT_PROFILE
echo "1. Check/Set NVM_DIR env variable"
if [ -z "$NVM_DIR" ]; then
export NVM_DIR="$HOME/.nvm"
echo "==> NVM_DIR has been exported - $NVM_DIR"
else
echo "==> NVM_DIR already exists - $NVM_DIR"
fi
echo "2. Check/Set NVMRC_VERSION env variable"
if [ -z "$NVMRC_VERSION" ]; then
echo "==> Configuring NVMRC_VERSION!"
export NVMRC_VERSION=$(cat $CIRCLE_WORKING_DIRECTORY/.nvmrc)
echo "export NVMRC_VERSION=$NVMRC_VERSION" >> $ENV_DOT_PROFILE
fi
echo "3. Configure NVM"
## Lets check if an existing NVM_DIR exists, if it does lets skil
if [ -e "$NVM_DIR" ]; then
echo "==> $NVM_DIR exists. Skipping steps 3!"
# echo "5. Executing $NVM_DIR/nvm.sh"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
else
echo "==> $NVM_DIR does not exists. Executing steps 4-5!"
echo "4. Installing NVM"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
echo "5. Executing $NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
## Ref: https://github.com/nvm-sh/nvm/issues/1102#issuecomment-550572252
if [ ! -z "$NVM_ARCH_UNOFFICIAL_OVERRIDE" ]; then
echo "==> Handle NVM_ARCH_UNOFFICIAL_OVERRIDE=$NVM_ARCH_UNOFFICIAL_OVERRIDE!"
echo "nvm_get_arch() { nvm_echo \"${NVM_ARCH_UNOFFICIAL_OVERRIDE}\"; }" >> $ENV_DOT_PROFILE
echo "export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release" >> $ENV_DOT_PROFILE
source $ENV_DOT_PROFILE
fi
echo "6. Setup Node version"
if [ -n "$NVMRC_VERSION" ]; then
echo "==> Installing Node version: $NVMRC_VERSION"
nvm install $NVMRC_VERSION
nvm alias default $NVMRC_VERSION
nvm use $NVMRC_VERSION
cd $CIRCLE_WORKING_DIRECTORY
else
echo "==> ERROR - NVMRC_VERSION has not been set! - NVMRC_VERSION: $NVMRC_VERSION"
exit 1
fi

defaults_display_versions: &defaults_display_versions
name: Display Versions
command: |
echo "What is the active version of Nodejs?"
echo "node: $(node --version)"
echo "yarn: $(yarn --version)"
echo "npm: $(npm --version)"
echo "nvm: $(nvm --version)"

defaults_environment: &defaults_environment
## env var for nx to set main branch
MAIN_BRANCH_NAME: main
## Disable LIBRDKAFKA build since we install it via general dependencies
# BUILD_LIBRDKAFKA: 0
##
# Executors
#
Expand Down Expand Up @@ -94,6 +161,8 @@ jobs:
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- run:
name: Update NPM install
command: npm ci
Expand All @@ -111,6 +180,8 @@ jobs:
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
Expand All @@ -126,6 +197,8 @@ jobs:
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
Expand All @@ -142,6 +215,8 @@ jobs:
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
Expand All @@ -155,7 +230,7 @@ jobs:
command: npm -s run test:xunit > ./test/results/tape.xml
- store_artifacts:
path: ./test/results
prefix: test
destination: test
- store_test_results:
path: ./test/results

Expand All @@ -171,14 +246,16 @@ jobs:
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Execute code coverage check
command: npm -s run test:coverage-check
- store_artifacts:
path: coverage
prefix: test
destination: test
- store_test_results:
path: coverage

Expand All @@ -191,17 +268,19 @@ jobs:
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Create dir for test results
command: mkdir -p ./audit/results
- run:
name: Check for new npm vulnerabilities
command: npm run audit:check --silent -- --json > ./audit/results/auditResults.json
command: npm run audit:check -- -o json > ./audit/results/auditResults.json
- store_artifacts:
path: ./audit/results
prefix: audit
destination: audit

audit-licenses:
executor: default-docker
Expand All @@ -219,41 +298,29 @@ jobs:
command: cd /tmp/license-scanner && pathToRepo=$CIRCLE_WORKING_DIRECTORY make run
- store_artifacts:
path: /tmp/license-scanner/results
prefix: licenses
destination: licenses

build-local:
executor: default-machine
environment:
<<: *defaults_environment
steps:
- checkout
- run:
name: Build Docker local image
command: |
echo "Building Docker image: local"
docker build -t $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local .
- run:
name: Save docker image to workspace
command: docker save -o /tmp/docker-image-local.tar $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local
- persist_to_workspace:
root: /tmp
paths:
- ./docker-image-local.tar

build:
executor: default-machine
steps:
- attach_workspace:
at: /tmp
<<: *defaults_configure_nvmrc
- run:
name: Load the pre-built docker local image from workspace
command: docker load -i /tmp/docker-image-local.tar
<<: *defaults_display_versions
- run:
name: Re-tag the image
name: Build Docker local image
command: |
echo "Re-tagging Docker image: $CIRCLE_TAG"
docker tag $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:local $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
source ~/.profile
export DOCKER_NODE_VERSION="$NVMRC_VERSION-alpine"
echo "export DOCKER_NODE_VERSION=$NVMRC_VERSION-alpine" >> $BASH_ENV
echo "Building Docker image: ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local --build-arg NODE_VERSION=$DOCKER_NODE_VERSION"
docker build -t ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local --build-arg NODE_VERSION=$DOCKER_NODE_VERSION .
- run:
name: Save the new docker image to workspace
command: docker save -o /tmp/docker-image.tar $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
name: Save docker image to workspace
command: docker save -o /tmp/docker-image.tar ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local
- persist_to_workspace:
root: /tmp
paths:
Expand All @@ -274,7 +341,7 @@ jobs:
command: cd /tmp/license-scanner && mode=docker dockerImages=$DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG make run
- store_artifacts:
path: /tmp/license-scanner/results
prefix: licenses
destination: licenses

image-scan:
executor: anchore/anchore_engine
Expand All @@ -290,6 +357,10 @@ jobs:
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
echo "export SLACK_CUSTOM_MSG='Anchore Image Scan failed for: \`${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_TAG}\`'" >> $BASH_ENV
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- run:
name: Install docker dependencies for anchore
command: |
Expand Down Expand Up @@ -381,6 +452,7 @@ jobs:

github-release:
executor: default-machine
shell: "/bin/bash -eo pipefail"
steps:
- run:
name: Install git
Expand Down Expand Up @@ -632,27 +704,11 @@ workflows:
ignore:
- /feature*/
- /bugfix*/
- build:
context: org-global
requires:
- setup
- test-dependencies
- test-lint
- test-unit
- test-coverage
- vulnerability-check
- audit-licenses
- build-local
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot(\.[0-9]+)?)?(\-hotfix(\.[0-9]+)?)?(\-perf(\.[0-9]+)?)?/
branches:
ignore:
- /.*/

- license-scan:
context: org-global
requires:
- build
- build-local
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot(\.[0-9]+)?)?(\-hotfix(\.[0-9]+)?)?(\-perf(\.[0-9]+)?)?/
Expand All @@ -662,14 +718,14 @@ workflows:
- image-scan:
context: org-global
requires:
- build
- build-local
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(\-snapshot(\.[0-9]+)?)?(\-hotfix(\.[0-9]+)?)?(\-perf(\.[0-9]+)?)?/
branches:
ignore:
- /.*/
# New commits to master release automatically
# New commits to main release automatically
- release:
context: org-global
requires:
Expand All @@ -685,7 +741,7 @@ workflows:
filters:
branches:
only:
- master
- main
- /release\/v.*/
- github-release:
context: org-global
Expand All @@ -694,7 +750,7 @@ workflows:
filters:
branches:
only:
- master
- main
- /release\/v.*/
- publish:
context: org-global
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.0
18.17.1
15 changes: 15 additions & 0 deletions .versionrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"types": [
{"type": "feat", "section": "Features"},
{"type": "fix", "section": "Bug Fixes"},
{"type": "docs", "section": "Documentation"},
{"type": "style", "section": "Styling"},
{"type": "refactor", "section": "Refactors"},
{"type": "perf", "section": "Performance"},
{"type": "test", "section": "Tests"},
{"type": "build", "section": "Build System"},
{"type": "ci", "section": "CI"},
{"type": "chore", "section": "Chore"},
{"type": "revert", "section": "Reverts"}
]
}
Loading