From 152eb72ba38b278b73c9a20822eaea712961027b Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 27 Jan 2024 18:01:57 +0200 Subject: [PATCH] Connect to s3-storage-provider shell to multiple networks in multiple steps Multiple `--network` calls lead to: > docker: Error response from daemon: Container cannot be connected to network endpoints: NETWORK_1 NETWORK_2. --- .../ext/s3-storage-provider/bin/migrate.j2 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 b/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 index 6e6aa7698..8d8c4d0d7 100644 --- a/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 +++ b/roles/custom/matrix-synapse/templates/synapse/ext/s3-storage-provider/bin/migrate.j2 @@ -1,14 +1,23 @@ #jinja2: lstrip_blocks: "True" #!/bin/bash +set -euo pipefail -{{ devture_systemd_docker_base_host_command_docker }} run \ +container_id=$(\ + {{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ --env-file={{ matrix_synapse_ext_s3_storage_provider_base_path }}/env \ --mount type=bind,src={{ matrix_synapse_storage_path }},dst=/matrix-media-store-parent,bind-propagation=slave \ --mount type=bind,src={{ matrix_synapse_ext_s3_storage_provider_data_path }},dst=/data \ --workdir=/data \ --network={{ matrix_synapse_container_network }} \ - --network={{ devture_postgres_container_network }} \ --entrypoint=/bin/bash \ {{ matrix_synapse_docker_image_final }} \ - -c 's3_media_upload update-db $UPDATE_DB_DURATION && s3_media_upload --no-progress check-deleted $MEDIA_PATH && s3_media_upload --no-progress upload $MEDIA_PATH $BUCKET --delete --storage-class $STORAGE_CLASS --endpoint-url $ENDPOINT {% if matrix_synapse_ext_synapse_s3_storage_provider_config_sse_customer_enabled %}--sse-customer-algo $SSE_CUSTOMER_ALGO --sse-customer-key $SSE_CUSTOMER_KEY{% endif %}' + -c 's3_media_upload update-db $UPDATE_DB_DURATION && s3_media_upload --no-progress check-deleted $MEDIA_PATH && s3_media_upload --no-progress upload $MEDIA_PATH $BUCKET --delete --storage-class $STORAGE_CLASS --endpoint-url $ENDPOINT {% if matrix_synapse_ext_synapse_s3_storage_provider_config_sse_customer_enabled %}--sse-customer-algo $SSE_CUSTOMER_ALGO --sse-customer-key $SSE_CUSTOMER_KEY{% endif %}' \ +) + +{# We need to connect to the Postgres network, which should be in this list. #} +{% for network in matrix_synapse_container_additional_networks %} +{{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} $container_id +{% endfor %} + +{{ devture_systemd_docker_base_host_command_docker }} start --attach $container_id