From 8047866a0cb12f9b643bac704ab4e66e6720b0ae Mon Sep 17 00:00:00 2001 From: Manuel Luypaert Date: Wed, 13 Nov 2024 11:47:43 +0000 Subject: [PATCH] Enabled .nvmrc file-based node version selection through make when nvm available --- api/aws_infra/Makefile | 28 ++++++++++++++++++---------- pipeline/aws_infra/Makefile | 18 +++++++++++++----- shared_aws/aws_infra/Makefile | 20 ++++++++++++++------ webui/Makefile | 28 ++++++++++++++++++---------- webui/aws_infra/Makefile | 28 ++++++++++++++++++---------- 5 files changed, 81 insertions(+), 41 deletions(-) diff --git a/api/aws_infra/Makefile b/api/aws_infra/Makefile index 462f756b..3e99c026 100644 --- a/api/aws_infra/Makefile +++ b/api/aws_infra/Makefile @@ -13,6 +13,14 @@ EB_APP_CDK_STACK_NAME ?= PaviApiEbApplicationCdkStack ADD_CDK_ARGS ?= EXTRA_PIP_COMPILE_ARGS ?= +ifdef NVM_DIR +NPM_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npm +NPX_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npx +else +NPM_EXEC=npm +NPX_EXEC=npx +endif + .PHONY: deploy-% install-% run-% update-% validate-% .venv/: @@ -29,7 +37,7 @@ tests/requirements.txt: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) tests/requirements.txt package-lock.json: - npm install --package-lock-only + ${NPM_EXEC} install --package-lock-only update-deps-lock: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-deps-lock @@ -44,13 +52,13 @@ update-test-deps-lock-shared-aws-only: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-test-deps-lock-shared-aws-only update-cdk-cli-lock: package-lock.json - npm update --package-lock-only + ${NPM_EXEC} update --package-lock-only update-deps-locks-all: update-deps-lock update-test-deps-lock update-cdk-cli-lock @: install-cdk-cli: package-lock.json - npm install + ${NPM_EXEC} install install-cdk-cli-update-dev: @$(MAKE) --no-print-directory update-cdk-cli-lock @@ -96,18 +104,18 @@ run-style-checks: install-test-deps validate-image-stack: install-deps run-unit-tests install-cdk-cli . .venv/bin/activate && \ - npx cdk diff ${IMAGE_REPO_CDK_STACK_NAME} + ${NPX_EXEC} cdk diff ${IMAGE_REPO_CDK_STACK_NAME} validate-application-stack: install-deps run-unit-tests install-cdk-cli . .venv/bin/activate && \ - npx cdk diff ${EB_APP_CDK_STACK_NAME} + ${NPX_EXEC} cdk diff ${EB_APP_CDK_STACK_NAME} validate-environment-stack: install-deps run-unit-tests install-cdk-cli export PAVI_DEPLOY_VERSION_LABEL=${PAVI_DEPLOY_VERSION_LABEL} && \ export PAVI_IMAGE_TAG=${PAVI_IMAGE_TAG} && \ export PAVI_IMAGE_REGISTRY=${PAVI_IMAGE_REGISTRY} && \ . .venv/bin/activate && \ - npx cdk diff ${VALIDATE_ENV_STACK_NAME} + ${NPX_EXEC} cdk diff ${VALIDATE_ENV_STACK_NAME} validate-environment-stack-dev: VALIDATE_ENV_STACK_NAME := ${EB_ENV_CDK_STACK_NAME} validate-environment-stack-dev: validate-environment-stack @@ -122,11 +130,11 @@ validate-all-dev: validate-all deploy-image-stack: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk deploy ${IMAGE_REPO_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${IMAGE_REPO_CDK_STACK_NAME} ${ADD_CDK_ARGS} deploy-application: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk deploy ${EB_APP_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${EB_APP_CDK_STACK_NAME} ${ADD_CDK_ARGS} .venv/bin/python -m pavi_shared_aws.aws_helpers.deploy_eb_app_version --eb_app_name PAVI-api --version_label ${PAVI_DEPLOY_VERSION_LABEL} deploy-environment: install-deps install-cdk-cli @@ -134,11 +142,11 @@ deploy-environment: install-deps install-cdk-cli export PAVI_IMAGE_TAG=${PAVI_IMAGE_TAG} && \ export PAVI_IMAGE_REGISTRY=${PAVI_IMAGE_REGISTRY} && \ . .venv/bin/activate && \ - npx cdk deploy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} destroy-environment: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk destroy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk destroy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} print-deploy-version-label: @echo ${PAVI_DEPLOY_VERSION_LABEL} diff --git a/pipeline/aws_infra/Makefile b/pipeline/aws_infra/Makefile index 0a515cb6..4c02e8bc 100644 --- a/pipeline/aws_infra/Makefile +++ b/pipeline/aws_infra/Makefile @@ -5,6 +5,14 @@ CDK_STACK_NAME ?= PaviPipelineCdkStack ADD_CDK_ARGS ?= EXTRA_PIP_COMPILE_ARGS ?= +ifdef NVM_DIR +NPM_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npm +NPX_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npx +else +NPM_EXEC=npm +NPX_EXEC=npx +endif + .PHONY: deploy install-% run-% update-% validate validate-% .venv/: @@ -21,7 +29,7 @@ tests/requirements.txt: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) tests/requirements.txt package-lock.json: - npm install --package-lock-only + ${NPM_EXEC} install --package-lock-only update-deps-lock: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-deps-lock @@ -36,13 +44,13 @@ update-test-deps-lock-shared-aws-only: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-test-deps-lock-shared-aws-only update-cdk-cli-lock: package-lock.json - npm update --package-lock-only + ${NPM_EXEC} update --package-lock-only update-deps-locks-all: update-deps-lock update-test-deps-lock update-cdk-cli-lock @: install-cdk-cli: package-lock.json - npm install + ${NPM_EXEC} install install-cdk-cli-update-dev: @$(MAKE) --no-print-directory update-cdk-cli-lock @@ -90,7 +98,7 @@ validate-stack: install-deps install-cdk-cli # Validate production stack code export PAVI_COMPUTE_MIN_VCPU=${PAVI_COMPUTE_MIN_VCPU} && \ . .venv/bin/activate && \ - npx cdk diff ${CDK_STACK_NAME} + ${NPX_EXEC} cdk diff ${CDK_STACK_NAME} validate-all: run-unit-tests validate-stack @: @@ -101,4 +109,4 @@ validate-dev: validate deploy: install-deps install-cdk-cli export PAVI_COMPUTE_MIN_VCPU=${PAVI_COMPUTE_MIN_VCPU} && \ . .venv/bin/activate && \ - npx cdk deploy ${CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${CDK_STACK_NAME} ${ADD_CDK_ARGS} diff --git a/shared_aws/aws_infra/Makefile b/shared_aws/aws_infra/Makefile index c156cf6f..d723d684 100644 --- a/shared_aws/aws_infra/Makefile +++ b/shared_aws/aws_infra/Makefile @@ -8,6 +8,14 @@ VALIDATE_STACK_NAME ?= ${CDK_STACK_NAME} ADD_CDK_ARGS ?= EXTRA_PIP_COMPILE_ARGS ?= +ifdef NVM_DIR +NPM_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npm +NPX_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npx +else +NPM_EXEC=npm +NPX_EXEC=npx +endif + .PHONY: deploy-% install-% run-% update-% validate-% .venv/: @@ -24,7 +32,7 @@ tests/requirements.txt: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) tests/requirements.txt package-lock.json: - npm install --package-lock-only + ${NPM_EXEC} install --package-lock-only update-deps-lock: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-deps-lock @@ -39,13 +47,13 @@ update-test-deps-lock-shared-aws-only: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-test-deps-lock-shared-aws-only update-cdk-cli-lock: package-lock.json - npm update --package-lock-only + ${NPM_EXEC} update --package-lock-only update-deps-locks-all: update-deps-lock update-test-deps-lock update-cdk-cli-lock @: install-cdk-cli: package-lock.json - npm install + ${NPM_EXEC} install install-cdk-cli-update-dev: @$(MAKE) --no-print-directory update-cdk-cli-lock @@ -91,15 +99,15 @@ run-style-checks: install-test-deps validate-stack: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk diff ${VALIDATE_STACK_NAME} + ${NPX_EXEC} cdk diff ${VALIDATE_STACK_NAME} validate-all: run-unit-tests validate-stack @: deploy-stack: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk deploy ${CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${CDK_STACK_NAME} ${ADD_CDK_ARGS} destroy-stack: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk destroy ${CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk destroy ${CDK_STACK_NAME} ${ADD_CDK_ARGS} diff --git a/webui/Makefile b/webui/Makefile index 5caab7f7..7b731ce1 100644 --- a/webui/Makefile +++ b/webui/Makefile @@ -9,6 +9,14 @@ AWS_DEFAULT_REGION := us-east-1 AWS_ACCT_NR=100225593120 REG=${AWS_ACCT_NR}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com +ifdef NVM_DIR +NPM_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npm +NPX_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npx +else +NPM_EXEC=npm +NPX_EXEC=npx +endif + clean: $(eval ADDITIONAL_BUILD_ARGS := --no-cache) @rm -rf .next/ @@ -22,10 +30,10 @@ push-container-image: registry-docker-login docker push ${REG}/${CONTAINER_NAME}:${TAG_NAME} install-deps: package-lock.json - npm install --omit-dev + ${NPM_EXEC} install --omit-dev install-test-deps: package-lock.json - npm install + ${NPM_EXEC} install install-deps-all: install-test-deps @: @@ -34,10 +42,10 @@ install-cypress-deps: sudo apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb package-lock.json: - npm install --package-lock-only + ${NPM_EXEC} install --package-lock-only update-deps-lock: package-lock.json - npm update --package-lock-only + ${NPM_EXEC} update --package-lock-only update-deps-locks-all: update-deps-lock @: @@ -51,24 +59,24 @@ run-container-dev: run-server-dev: install-deps-all @export PAVI_API_BASE_URL=${PAVI_API_BASE_URL} && \ - npm run dev + ${NPM_EXEC} run dev run-style-checks: install-test-deps - npm run lint + ${NPM_EXEC} run lint run-type-checks: install-test-deps - npm run typecheck + ${NPM_EXEC} run typecheck run-unit-tests: install-test-deps - npm run test + ${NPM_EXEC} run test run-e2e-tests: install-test-deps $(MAKE) --no-print-directory run-container-dev - npx cypress run --e2e --env API_BASE_URL=${PAVI_API_BASE_URL} || true + ${NPX_EXEC} cypress run --e2e --env API_BASE_URL=${PAVI_API_BASE_URL} || true $(MAKE) --no-print-directory stop-container-dev run-e2e-tests-dev: install-test-deps - npx cypress open --e2e --env API_BASE_URL=${PAVI_API_BASE_URL} + ${NPX_EXEC} cypress open --e2e --env API_BASE_URL=${PAVI_API_BASE_URL} stop-container-dev: @docker compose -f docker-compose-dev.yml --env-file dev.env down agr.pavi.dev-local.webui diff --git a/webui/aws_infra/Makefile b/webui/aws_infra/Makefile index 05060abf..9c3af524 100644 --- a/webui/aws_infra/Makefile +++ b/webui/aws_infra/Makefile @@ -14,6 +14,14 @@ EB_APP_CDK_STACK_NAME ?= PaviWebUiEbApplicationCdkStack ADD_CDK_ARGS ?= EXTRA_PIP_COMPILE_ARGS ?= +ifdef NVM_DIR +NPM_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npm +NPX_EXEC=. ${NVM_DIR}/nvm.sh && nvm exec npx +else +NPM_EXEC=npm +NPX_EXEC=npx +endif + .PHONY: deploy-% install-% print-% run-% update-% validate-% .venv/: @@ -30,7 +38,7 @@ tests/requirements.txt: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) tests/requirements.txt package-lock.json: - npm install --package-lock-only + ${NPM_EXEC} install --package-lock-only update-deps-lock: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-deps-lock @@ -45,13 +53,13 @@ update-test-deps-lock-shared-aws-only: @$(MAKE) --no-print-directory -f $(mkfile_dir)/../../Makefile -C $(mkfile_dir) update-python-test-deps-lock-shared-aws-only update-cdk-cli-lock: package-lock.json - npm update --package-lock-only + ${NPM_EXEC} update --package-lock-only update-deps-locks-all: update-deps-lock update-test-deps-lock update-cdk-cli-lock @: install-cdk-cli: package-lock.json - npm install + ${NPM_EXEC} install install-cdk-cli-update-dev: @$(MAKE) --no-print-directory update-cdk-cli-lock @@ -97,11 +105,11 @@ run-style-checks: install-test-deps validate-image-stack: install-deps run-unit-tests install-cdk-cli . .venv/bin/activate && \ - npx cdk diff ${IMAGE_REPO_CDK_STACK_NAME} + ${NPX_EXEC} cdk diff ${IMAGE_REPO_CDK_STACK_NAME} validate-application-stack: install-deps run-unit-tests install-cdk-cli . .venv/bin/activate && \ - npx cdk diff ${EB_APP_CDK_STACK_NAME} + ${NPX_EXEC} cdk diff ${EB_APP_CDK_STACK_NAME} validate-environment-stack: install-deps run-unit-tests install-cdk-cli export PAVI_DEPLOY_VERSION_LABEL=${PAVI_DEPLOY_VERSION_LABEL} && \ @@ -109,7 +117,7 @@ validate-environment-stack: install-deps run-unit-tests install-cdk-cli export PAVI_IMAGE_REGISTRY=${PAVI_IMAGE_REGISTRY} && \ export PAVI_API_STACK_NAME=${PAVI_API_STACK_NAME} && \ . .venv/bin/activate && \ - npx cdk diff ${VALIDATE_ENV_STACK_NAME} + ${NPX_EXEC} cdk diff ${VALIDATE_ENV_STACK_NAME} validate-environment-stack-dev: VALIDATE_ENV_STACK_NAME := ${EB_ENV_CDK_STACK_NAME} validate-environment-stack-dev: validate-environment-stack @@ -124,11 +132,11 @@ validate-all-dev: validate-all deploy-image-stack: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk deploy ${IMAGE_REPO_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${IMAGE_REPO_CDK_STACK_NAME} ${ADD_CDK_ARGS} deploy-application: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk deploy ${EB_APP_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${EB_APP_CDK_STACK_NAME} ${ADD_CDK_ARGS} .venv/bin/python -m pavi_shared_aws.aws_helpers.deploy_eb_app_version --eb_app_name PAVI-webui --version_label ${PAVI_DEPLOY_VERSION_LABEL} deploy-environment: install-deps install-cdk-cli @@ -137,11 +145,11 @@ deploy-environment: install-deps install-cdk-cli export PAVI_IMAGE_REGISTRY=${PAVI_IMAGE_REGISTRY} && \ export PAVI_API_STACK_NAME=${PAVI_API_STACK_NAME} && \ . .venv/bin/activate && \ - npx cdk deploy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk deploy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} destroy-environment: install-deps install-cdk-cli . .venv/bin/activate && \ - npx cdk destroy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} + ${NPX_EXEC} cdk destroy ${EB_ENV_CDK_STACK_NAME} ${ADD_CDK_ARGS} print-deploy-version-label: @echo ${PAVI_DEPLOY_VERSION_LABEL}