Slavi Pantaleev e1a2d427c6 Use multi-stage Dockerfile for building customized Synape
This also reverts e5574a405e43a51ab152e0e4cf760a3cc021adbe because:
- it was causing issues on some servers (not clear why)
- such workarounds are no longer necessary when doing multi-stage building.
2025-03-29 08:01:27 +02:00

60 lines
3.2 KiB
Django/Jinja

#jinja2: lstrip_blocks: "True"
{% if matrix_synapse_container_image_customizations_templates_enabled %}
FROM {{ matrix_synapse_docker_image }} AS templates-builder
{#
This ugly script below does quite a lot:
- installs git and other dependencies temporarily, just so we could do a shallow-clone
- prepare the SSH config: keyscanning (if enabled), private key (if enabled)
- performs a git shallow clone with just the branch we need
- makes sure the files are owned by the user that will actually run the container later
#}
{% set dependencies = ['git', 'ssh', 'openssh-client'] %}
{% if matrix_synapse_container_image_customizations_templates_git_repository_ssh_private_key %}
RUN echo '{{ matrix_synapse_container_image_customizations_templates_git_repository_ssh_private_key | b64encode }}' | base64 -d > /custom-templates-private-key
RUN chmod 400 /custom-templates-private-key
{% endif %}
RUN apt-get update && apt-get install --no-install-recommends -y {{ dependencies | join(' ') }}
{% if matrix_synapse_container_image_customizations_templates_git_repository_keyscan_enabled %}
RUN mkdir ~/.ssh
RUN chmod 700 ~/.ssh
RUN ssh-keyscan -t rsa {{ matrix_synapse_container_image_customizations_templates_git_repository_keyscan_hostname }} >> ~/.ssh/known_hosts
{% endif %}
RUN {% if matrix_synapse_container_image_customizations_templates_git_repository_ssh_private_key %}GIT_SSH_COMMAND='ssh -i /custom-templates-private-key'{% endif %} git \
clone \
--branch={{ matrix_synapse_container_image_customizations_templates_git_repository_branch }} \
--depth=1 \
--single-branch \
--no-tags \
{{ matrix_synapse_container_image_customizations_templates_git_repository_url }} \
{{ matrix_synapse_container_image_customizations_templates_in_container_base_path }}
RUN /bin/sh -c 'cd {{ matrix_synapse_container_image_customizations_templates_in_container_base_path }} && git rev-parse HEAD > git-revision.txt'
RUN rm -rf {{ matrix_synapse_container_image_customizations_templates_in_container_base_path }}/.git
RUN chown -R {{ matrix_synapse_uid }}:{{ matrix_synapse_gid }} {{ matrix_synapse_container_image_customizations_templates_in_container_base_path }}
{% endif %}
FROM {{ matrix_synapse_docker_image }}
{% if matrix_synapse_container_image_customizations_auto_accept_invite_installation_enabled %}
RUN pip install synapse-auto-accept-invite=={{ matrix_synapse_ext_synapse_auto_accept_invite_version }}
{% endif %}
{% if matrix_synapse_container_image_customizations_s3_storage_provider_installation_enabled %}
{% if matrix_synapse_container_image_customizations_s3_storage_provider_installation_old_boto_workaround_enabled %}
RUN pip install 'boto3<1.36.0' 'botocore<1.36.0' synapse-s3-storage-provider=={{ matrix_synapse_ext_synapse_s3_storage_provider_version }}
{% else %}
RUN pip install synapse-s3-storage-provider=={{ matrix_synapse_ext_synapse_s3_storage_provider_version }}
{% endif %}
{% endif %}
{% if matrix_synapse_container_image_customizations_templates_enabled %}
COPY --from=templates-builder {{ matrix_synapse_container_image_customizations_templates_in_container_base_path }} {{ matrix_synapse_container_image_customizations_templates_in_container_base_path }}
{% endif %}
{{ matrix_synapse_container_image_customizations_dockerfile_body_custom }}