Skip to content

Commit

Permalink
Enabled .nvmrc file-based node version selection through make when nv…
Browse files Browse the repository at this point in the history
…m available
  • Loading branch information
mluypaert committed Nov 13, 2024
1 parent 2cafe0f commit 8047866
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 41 deletions.
28 changes: 18 additions & 10 deletions api/aws_infra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -122,23 +130,23 @@ 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
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 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}
18 changes: 13 additions & 5 deletions pipeline/aws_infra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
@:
Expand All @@ -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}
20 changes: 14 additions & 6 deletions shared_aws/aws_infra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}
28 changes: 18 additions & 10 deletions webui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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
@:
Expand All @@ -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
@:
Expand All @@ -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
28 changes: 18 additions & 10 deletions webui/aws_infra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -97,19 +105,19 @@ 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} && \
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
Expand All @@ -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
Expand All @@ -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}

0 comments on commit 8047866

Please sign in to comment.