mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-21 02:53:56 +01:00
Use buildkit's cache feature to speed up docker builds (#11691)
Having spent much of the last week attempting to run complement tests from somewhere with damp string instead of internet... something had to be done.
This commit is contained in:
parent
338e70c617
commit
d41c4654db
4 changed files with 28 additions and 5 deletions
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
|
@ -366,6 +366,8 @@ jobs:
|
||||||
# Build initial Synapse image
|
# Build initial Synapse image
|
||||||
- run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
|
- run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
|
||||||
working-directory: synapse
|
working-directory: synapse
|
||||||
|
env:
|
||||||
|
DOCKER_BUILDKIT: 1
|
||||||
|
|
||||||
# Build a ready-to-run Synapse image based on the initial image above.
|
# Build a ready-to-run Synapse image based on the initial image above.
|
||||||
# This new image includes a config file, keys for signing and TLS, and
|
# This new image includes a config file, keys for signing and TLS, and
|
||||||
|
|
1
changelog.d/11691.misc
Normal file
1
changelog.d/11691.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Use buildkit's cache feature to speed up docker builds.
|
|
@ -1,14 +1,17 @@
|
||||||
# Dockerfile to build the matrixdotorg/synapse docker images.
|
# Dockerfile to build the matrixdotorg/synapse docker images.
|
||||||
#
|
#
|
||||||
|
# Note that it uses features which are only available in BuildKit - see
|
||||||
|
# https://docs.docker.com/go/buildkit/ for more information.
|
||||||
|
#
|
||||||
# To build the image, run `docker build` command from the root of the
|
# To build the image, run `docker build` command from the root of the
|
||||||
# synapse repository:
|
# synapse repository:
|
||||||
#
|
#
|
||||||
# docker build -f docker/Dockerfile .
|
# DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile .
|
||||||
#
|
#
|
||||||
# There is an optional PYTHON_VERSION build argument which sets the
|
# There is an optional PYTHON_VERSION build argument which sets the
|
||||||
# version of python to build against: for example:
|
# version of python to build against: for example:
|
||||||
#
|
#
|
||||||
# docker build -f docker/Dockerfile --build-arg PYTHON_VERSION=3.6 .
|
# DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile --build-arg PYTHON_VERSION=3.9 .
|
||||||
#
|
#
|
||||||
|
|
||||||
ARG PYTHON_VERSION=3.8
|
ARG PYTHON_VERSION=3.8
|
||||||
|
@ -19,7 +22,16 @@ ARG PYTHON_VERSION=3.8
|
||||||
FROM docker.io/python:${PYTHON_VERSION}-slim as builder
|
FROM docker.io/python:${PYTHON_VERSION}-slim as builder
|
||||||
|
|
||||||
# install the OS build deps
|
# install the OS build deps
|
||||||
RUN apt-get update && apt-get install -y \
|
#
|
||||||
|
# RUN --mount is specific to buildkit and is documented at
|
||||||
|
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#build-mounts-run---mount.
|
||||||
|
# Here we use it to set up a cache for apt, to improve rebuild speeds on
|
||||||
|
# slow connections.
|
||||||
|
#
|
||||||
|
RUN \
|
||||||
|
--mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
|
apt-get update && apt-get install -y \
|
||||||
build-essential \
|
build-essential \
|
||||||
libffi-dev \
|
libffi-dev \
|
||||||
libjpeg-dev \
|
libjpeg-dev \
|
||||||
|
@ -44,7 +56,8 @@ COPY synapse/python_dependencies.py /synapse/synapse/python_dependencies.py
|
||||||
# used while you develop on the source
|
# used while you develop on the source
|
||||||
#
|
#
|
||||||
# This is aiming at installing the `install_requires` and `extras_require` from `setup.py`
|
# This is aiming at installing the `install_requires` and `extras_require` from `setup.py`
|
||||||
RUN pip install --prefix="/install" --no-warn-script-location \
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
|
pip install --prefix="/install" --no-warn-script-location \
|
||||||
/synapse[all]
|
/synapse[all]
|
||||||
|
|
||||||
# Copy over the rest of the project
|
# Copy over the rest of the project
|
||||||
|
@ -66,7 +79,10 @@ LABEL org.opencontainers.image.documentation='https://github.com/matrix-org/syna
|
||||||
LABEL org.opencontainers.image.source='https://github.com/matrix-org/synapse.git'
|
LABEL org.opencontainers.image.source='https://github.com/matrix-org/synapse.git'
|
||||||
LABEL org.opencontainers.image.licenses='Apache-2.0'
|
LABEL org.opencontainers.image.licenses='Apache-2.0'
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN \
|
||||||
|
--mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||||
|
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||||
|
apt-get update && apt-get install -y \
|
||||||
curl \
|
curl \
|
||||||
gosu \
|
gosu \
|
||||||
libjpeg62-turbo \
|
libjpeg62-turbo \
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
# Exit if a line returns a non-zero exit code
|
# Exit if a line returns a non-zero exit code
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# enable buildkit for the docker builds
|
||||||
|
export DOCKER_BUILDKIT=1
|
||||||
|
|
||||||
# Change to the repository root
|
# Change to the repository root
|
||||||
cd "$(dirname $0)/.."
|
cd "$(dirname $0)/.."
|
||||||
|
|
||||||
|
@ -65,4 +68,5 @@ if [[ -n "$1" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the tests!
|
# Run the tests!
|
||||||
|
echo "Images built; running complement"
|
||||||
go test -v -tags synapse_blacklist,msc2403 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests/...
|
go test -v -tags synapse_blacklist,msc2403 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests/...
|
||||||
|
|
Loading…
Reference in a new issue