Tweaked Dockerfile to optimise build cache.

This commit is contained in:
Victoria Chan 2023-06-14 14:47:00 +01:00
Родитель a1a2c154ad
Коммит cd1a3954bb
5 изменённых файлов: 18 добавлений и 12 удалений

Просмотреть файл

@ -1,20 +1,27 @@
**/*.db.archive
/dockerfiles
/docker-compose*.yml
Dockerfile
.git
.gitignore
docs/
**/__pycache__
*.pyc
.DS_Store
*.swp
/venv/
/tmp/
node_modules/
/npm-debug.log
network-api/networkapi/frontend/
network-api/media/
network-api/staticfiles/
**/node_modules/
**/dist
.coverage
.coverage.*
.cache
# Distribution / packaging
.Python

Просмотреть файл

@ -84,7 +84,9 @@ USER mozilla
RUN python -m venv $VIRTUAL_ENV
COPY --chown=mozilla ./requirements.txt ./dev-requirements.txt ./
RUN pip install -U pip==20.0.2 && pip install pip-tools
RUN pip install -r requirements.txt
# Normally we won't install dev dependencies in production, but we do it here to optimise
# docker build cache for local build
RUN pip install -r requirements.txt -r dev-requirements.txt
# Copy application code.
COPY --chown=mozilla . .
@ -116,10 +118,7 @@ RUN apt-get install -y postgresql-client
# Restore user
USER mozilla
# Install dev dependencies
RUN pip install -r dev-requirements.txt
# Pull in the node modules from the frontend build stage so we don't have to run install again.
# Pull in the node modules from the frontend build stage so we don't have to run npm ci again.
# This is just a copy in the container, and is not visible to the host machine.
COPY --chown=mozilla --from=frontend /app/node_modules ./node_modules

Просмотреть файл

@ -25,11 +25,11 @@ services:
# Using rw (default) for these so linters can format them in the container.
- ./.git:/app/.git
- ./.gitignore:/app/.gitignore
- ./network-api/networkapi:/app/network-api/networkapi
- ./network-api/manage.py:/app/network-api/manage.py
- ./.env:/app/.env
- ./.coveragerc:/app/.coveragerc
- ./copy-db.sh:/app/copy-db.sh
- ./.flake8:/app/.flake8
- ./network-api:/app/network-api
- ./copy-db.js:/app/copy-db.js
- ./test:/app/test
- ./tests:/app/tests
- ./Procfile.dev:/app/Procfile.dev

Просмотреть файл

@ -219,7 +219,7 @@ Within the `backend` container, [Honcho](https://honcho.readthedocs.io/en/latest
#### Starting dev container without rebuilding frontend
There is also a `docker-compose-lean.yml` file which starts the container with just the `backend` service without running the frontend watch process. This is to provide an option for a faster start up, as the frontend watch process can take a while to rebuild the static assets. Note that a side effect of this is that this could be using outdated frontend assets, e.g. stylesheets are not reflecting the latest changes.
There is also a `docker-compose-lean.yml` file which starts the container with just the `backend` service without running the frontend watch process. This is to provide an option for a faster start up, as the frontend watch process can take a while to rebuild the static assets. Note that a side effect of this is that this could be using outdated frontend assets, e.g. stylesheets are not reflecting the latest changes, or the frontend assets can be missing if the container is new.
To start up the dev container normally, use `inv start` or `docker-compose up`. To start it as a lean container without frontend build, use `inv start-lean` or `docker-compose -f docker-compose.yml -f docker-compose-lean.yml up`.

Просмотреть файл

@ -182,7 +182,7 @@ def start_dev(ctx):
def start_lean_dev(ctx):
"""Start the dev server without rebuilding frontend assets for a faster start up."""
print("Starting the dev server without rebuilding frontend assets...")
print("WARNING: this may use outdated frontend assets.")
print("WARNING: Frontend assets may be outdated or missing if they haven't been built yet.")
ctx.run("docker-compose -f docker-compose.yml -f docker-compose-lean.yml up")