From a575fddaa249735214ac42ad841385bbf04de358 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 11 May 2026 02:17:53 +0200 Subject: [PATCH] build(compose): run npm install in container, persist deps in named volumes Replace the host-side `make npm-install` step with a compose-level `command:` override that runs `npm install` inside the container on every start. Back node_modules and static/vendor with named volumes so the bind-mounted source tree no longer shadows the install while state still survives container restarts. Drop the now-redundant npm-install target and its references in up/dev/prod/test-e2e. Co-Authored-By: Claude Opus 4.7 (1M context) --- Makefile | 13 ++++--------- docker-compose.yml | 9 +++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 9aefc94..282c13f 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ build-no-cache: docker build --no-cache -t application-portfolio . .PHONY: up -up: npm-install +up: # Start the application using docker-compose with build. docker-compose up -d --build --force-recreate @@ -58,12 +58,12 @@ logs: docker logs -f portfolio .PHONY: dev -dev: npm-install +dev: # Start the application in development mode using docker-compose. FLASK_ENV=development docker-compose up -d .PHONY: prod -prod: npm-install +prod: # Start the application in production mode using docker-compose (with build). docker-compose up -d --build @@ -92,11 +92,6 @@ install-dev: # Install runtime and developer dependencies from pyproject.toml. $(PYTHON) -m pip install -e ".[dev]" -.PHONY: npm-install -npm-install: - # Install Node.js dependencies for browser tests. - cd app && npm install - .PHONY: lint-actions lint-actions: # Lint GitHub Actions workflows. @@ -145,7 +140,7 @@ security: install-dev test-security $(PYTHON) -m pip_audit -r /tmp/portfolio-runtime-requirements.txt .PHONY: test-e2e -test-e2e: npm-install +test-e2e: # Run Cypress end-to-end tests via act (stop portfolio container to free port first). -docker stop portfolio 2>/dev/null || true $(ACT) workflow_dispatch -W .github/workflows/tests.yml -j e2e diff --git a/docker-compose.yml b/docker-compose.yml index 1559a0c..49ba860 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,4 +12,13 @@ services: - .env volumes: - ./app:/app + - node_modules:/app/node_modules + - vendor:/app/static/vendor + # Run `npm install` on every container start so the named volumes + # reflect the current package.json (postinstall regenerates vendor/). + command: sh -c "npm install --prefix /app --no-audit --no-fund && python app.py" restart: unless-stopped + +volumes: + node_modules: + vendor: