From 2dcd947ae1c165571784a4a4a838631d7eb3e16c Mon Sep 17 00:00:00 2001 From: Victoria Chan Date: Tue, 13 Jun 2023 14:27:18 +0100 Subject: [PATCH] Add a inv start-lean option to start docker without rebuilding frontend. Also updated documentation and streamline local dev more. --- .dockerignore | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 2 +- Procfile.dev | 5 ++++- Procfile.dev-lean | 3 +++ docker-compose-lean.yml | 6 ++++++ docker-compose.yml | 4 ++-- docs/local_development.md | 2 -- package.json | 2 +- tasks.py | 8 +++++++- 9 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 Procfile.dev-lean create mode 100644 docker-compose-lean.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8ec3ad0d1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +**/*.db.archive + +/dockerfiles +/docker-compose*.yml + +.git +**/__pycache__ +*.pyc +.DS_Store +*.swp +/venv/ +/tmp/ +node_modules/ +/npm-debug.log +network-api/networkapi/frontend/ + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg diff --git a/Dockerfile b/Dockerfile index 8321bd3a0..45c392ebc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -124,4 +124,4 @@ RUN pip install -r dev-requirements.txt COPY --chown=mozilla --from=frontend /app/node_modules ./node_modules # do nothing forever - exec commands elsewhere -# CMD tail -f /dev/null +CMD tail -f /dev/null diff --git a/Procfile.dev b/Procfile.dev index bd772bed3..ea497a5c6 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,2 +1,5 @@ -web: /app/dockerpythonvenv/bin/python network-api/manage.py runserver 0.0.0.0:8000 +# This starts up 2 processes, one for webserver and one for frontend that +# watches frontend files and compiles them when they change. + frontend-watch: npm run watch +web: /app/dockerpythonvenv/bin/python network-api/manage.py runserver 0.0.0.0:8000 diff --git a/Procfile.dev-lean b/Procfile.dev-lean new file mode 100644 index 000000000..42a783271 --- /dev/null +++ b/Procfile.dev-lean @@ -0,0 +1,3 @@ +# This starts the webserver for dev and skips frontend watching to shorten start up time. + +web: /app/dockerpythonvenv/bin/python network-api/manage.py runserver 0.0.0.0:8000 diff --git a/docker-compose-lean.yml b/docker-compose-lean.yml new file mode 100644 index 000000000..f0a88d0fe --- /dev/null +++ b/docker-compose-lean.yml @@ -0,0 +1,6 @@ +version: '3' + +services: + backend: + # This will start the web server and skip the frontend build step. + command: honcho -f Procfile.dev-lean start diff --git a/docker-compose.yml b/docker-compose.yml index 454aa2bab..b3989c400 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,8 +14,7 @@ services: - CHOKIDAR_INTERVAL=2000 env_file: - ".env" - # The honcho command is defined in the Procfile.dev file - # This command starts the Django server and the frontend build process + # This command starts the Django server and the frontend build. command: honcho -f Procfile.dev start ports: - "8000:8000" @@ -29,6 +28,7 @@ services: - ./.env:/app/.env:rw - ./tests:/app/tests:rw - ./Procfile.dev:/app/Procfile.dev:rw + - ./Procfile.dev-lean:/app/Procfile.dev-lean:rw - ./pyproject.toml:/app/pyproject.toml:rw - ./requirements.txt:/app/requirements.txt:rw - ./requirements.in:/app/requirements.in:rw diff --git a/docs/local_development.md b/docs/local_development.md index 5ecfa5710..20be836df 100644 --- a/docs/local_development.md +++ b/docs/local_development.md @@ -100,8 +100,6 @@ When it's done, run `inv pip-sync`. #### JS -Dependencies live on your filesystem: you don't need to rebuild the `watch-static-files` image when installing or updating dependencies. - **Install packages:** Use `invoke npm "install [PACKAGE]"`. diff --git a/package.json b/package.json index bbd046d17..27dc1bf5f 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "tailwind": "run-p tailwind:watch sync", "tailwind:watch": "npm run build:tailwind -- -w", "test": "npm run lint", - "watch": "wait-on http://backend:8000/cms && run-s build:clean && run-p build:js:dev build:common watch:**", + "watch": "run-s build:clean && run-p build:js:dev build:common watch:**", "watch:images": "chokidar \"source/images/**/*\" -c \"npm run build:images\"", "watch:sass": "chokidar \"source/**/*.scss\" \"network-api/**/*.html\" -c \"npm run build:sass\"" }, diff --git a/tasks.py b/tasks.py index 7ac551a43..9d52d3faf 100644 --- a/tasks.py +++ b/tasks.py @@ -168,7 +168,7 @@ def setup(ctx): print("* Building Docker images") ctx.run("docker-compose build") initialize_database(ctx) - print("\n* Start your dev server with:\n inv start or docker-compose up") + print("\n* Start your dev server with:\n inv start or docker-compose up.") @task(aliases=["start", "docker-start"]) @@ -178,6 +178,12 @@ def start_dev(ctx): ctx.run("docker-compose up") +@task(aliases=["start-lean", "docker-start-lean"]) +def start_lean_dev(ctx): + """Start the dev server without rebuilding frontend assets for a faster start up. \nWarning: this may use outdated frontend assets.""" + ctx.run("docker-compose -f docker-compose.yml -f docker-compose-lean.yml up") + + # Javascript shorthands @task(aliases=["docker-npm"]) def npm(ctx, command):