More docker optimisation and also fixed isort error

This commit is contained in:
Victoria Chan 2023-06-14 19:20:51 +01:00
Родитель 744df2f6ca
Коммит e81e88123c
5 изменённых файлов: 15 добавлений и 5 удалений

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

@ -2,9 +2,11 @@
/docker-compose*.yml /docker-compose*.yml
Dockerfile Dockerfile
.dockerignore
.git .git
.gitignore .gitignore
**/*.md
docs/ docs/
**/__pycache__ **/__pycache__
*.pyc *.pyc
@ -21,7 +23,7 @@ network-api/staticfiles/
.coverage .coverage
.coverage.* .coverage.*
.cache .cache
tasks.py
# Distribution / packaging # Distribution / packaging
.Python .Python

1
.gitignore поставляемый
Просмотреть файл

@ -3,6 +3,7 @@
TODO.txt TODO.txt
node_modules/ node_modules/
dest/ dest/
dockerpythonvenv/
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/

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

@ -82,18 +82,20 @@ USER mozilla
# Install your app's Python requirements. # Install your app's Python requirements.
RUN python -m venv $VIRTUAL_ENV 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 -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 # Normally we won't install dev dependencies in production, but we do it here to optimise
# docker build cache for local build # docker build cache for local build
COPY --chown=mozilla ./requirements.txt ./dev-requirements.txt ./
RUN pip install -r requirements.txt -r dev-requirements.txt RUN pip install -r requirements.txt -r dev-requirements.txt
# Copy application code. # 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. # Utilise .dockerignore to minimise cache invalidation.
COPY --chown=mozilla . . COPY --chown=mozilla . .
# Copy compiled assets from the frontend build stage for collectstatic to work. # 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 COPY --chown=mozilla --from=frontend /app/network-api/networkapi/frontend ./network-api/networkapi/frontend
# Collect static. This command will move static files from application # 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. # 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 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 # do nothing forever - exec commands elsewhere
CMD tail -f /dev/null CMD tail -f /dev/null

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

@ -219,7 +219,9 @@ Within the `backend` container, [Honcho](https://honcho.readthedocs.io/en/latest
#### Starting dev container without rebuilding frontend #### 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`. 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`.

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

@ -235,7 +235,7 @@ ignore="H017"
[tool.isort] [tool.isort]
profile = "black" profile = "black"
extend_skip = ["network-api/media", "network-api/staticfiles"] extend_skip = ["network-api/media", "network-api/staticfiles", "dockerpythonvenv"]
skip_gitignore = true skip_gitignore = true
known_first_party = ["networkapi"] known_first_party = ["networkapi"]