From e81e88123c6034a1a75e34757039c56d7fc76f8a Mon Sep 17 00:00:00 2001 From: Victoria Chan Date: Wed, 14 Jun 2023 19:20:51 +0100 Subject: [PATCH] More docker optimisation and also fixed isort error --- .dockerignore | 4 +++- .gitignore | 1 + Dockerfile | 9 +++++++-- docs/local_development.md | 4 +++- pyproject.toml | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 938389c06..543272812 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,9 +2,11 @@ /docker-compose*.yml Dockerfile +.dockerignore .git .gitignore +**/*.md docs/ **/__pycache__ *.pyc @@ -21,7 +23,7 @@ network-api/staticfiles/ .coverage .coverage.* .cache - +tasks.py # Distribution / packaging .Python diff --git a/.gitignore b/.gitignore index bae9db38f..4afacd85a 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ TODO.txt node_modules/ dest/ +dockerpythonvenv/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/Dockerfile b/Dockerfile index 699a80ff3..b32bec411 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,18 +82,20 @@ USER mozilla # Install your app's Python requirements. 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 # Normally we won't install dev dependencies in production, but we do it here to optimise # docker build cache for local build +COPY --chown=mozilla ./requirements.txt ./dev-requirements.txt ./ RUN pip install -r requirements.txt -r dev-requirements.txt # Copy application code. -# Any change in this directory is likely to invalidate build cache, and the lines below. +# Any change in this directory is likely to invalidate build cache for all lines below. # Utilise .dockerignore to minimise cache invalidation. COPY --chown=mozilla . . # Copy compiled assets from the frontend build stage for collectstatic to work. +# This will later be obscured by the `network-api` bind mount in docker-compose.yml, and +# will need to be recreated by `npm run build`. COPY --chown=mozilla --from=frontend /app/network-api/networkapi/frontend ./network-api/networkapi/frontend # Collect static. This command will move static files from application @@ -124,5 +126,8 @@ USER mozilla # 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 +# To avoid isort `fatal: detected dubious ownership in repository at '/app'` error +RUN git config --global --add safe.directory /app + # do nothing forever - exec commands elsewhere CMD tail -f /dev/null diff --git a/docs/local_development.md b/docs/local_development.md index a56cf035d..30df6f249 100644 --- a/docs/local_development.md +++ b/docs/local_development.md @@ -219,7 +219,9 @@ 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, or the frontend assets can be missing if the container is new. +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 and `npm run build` has not been run to create `network-api/networkapi/frontend` yet. 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`. diff --git a/pyproject.toml b/pyproject.toml index 5e5d1e9a4..2e28fd455 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -235,7 +235,7 @@ ignore="H017" [tool.isort] profile = "black" -extend_skip = ["network-api/media", "network-api/staticfiles"] +extend_skip = ["network-api/media", "network-api/staticfiles", "dockerpythonvenv"] skip_gitignore = true known_first_party = ["networkapi"]