diff --git a/.dockerignore b/.dockerignore index a0c82d379..2e5d636f6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,6 +12,10 @@ !geoportal/geomapfish_geoportal/static !geoportal/geomapfish_geoportal/locale geoportal/geomapfish_geoportal/locale/*.pot +!geoportal/geomapfish_geoportal/authentication.py +!geoportal/geomapfish_geoportal/multi_tenant.py +!geoportal/geomapfish_geoportal/dev.py + !webcomponents !package.json !package-lock.json diff --git a/CONST_create_template/.dockerignore b/CONST_create_template/.dockerignore index 589f696dc..e0bfe2ca9 100644 --- a/CONST_create_template/.dockerignore +++ b/CONST_create_template/.dockerignore @@ -12,3 +12,6 @@ !geoportal/geomapfish_geoportal/static !geoportal/geomapfish_geoportal/locale geoportal/geomapfish_geoportal/locale/*.pot +!geoportal/geomapfish_geoportal/authentication.py +!geoportal/geomapfish_geoportal/multi_tenant.py +!geoportal/geomapfish_geoportal/dev.py diff --git a/CONST_create_template/Dockerfile b/CONST_create_template/Dockerfile index e2538a0e7..12d908181 100644 --- a/CONST_create_template/Dockerfile +++ b/CONST_create_template/Dockerfile @@ -28,6 +28,7 @@ ENV PGSCHEMA=$PGSCHEMA RUN \ cd /tmp/config/geoportal/ \ + && [ "${SIMPLE}" == "TRUE" ] || rm -f geomapfish_geoportal/*.py \ && c2c-template --vars ${VARS_FILE} \ --get-config geomapfish_geoportal/config.yaml \ ${CONFIG_VARS} \ diff --git a/CONST_create_template/Makefile b/CONST_create_template/Makefile index 557b16392..29140aae2 100644 --- a/CONST_create_template/Makefile +++ b/CONST_create_template/Makefile @@ -1,4 +1,4 @@ -PROJECT_PUBLIC_URL=https://example.camptocamp.com/ +PROJECT_PUBLIC_URL?=https://example.camptocamp.com/ DUMP_FILE=dump.backup PACKAGE=geomapfish LANGUAGES=en fr de it @@ -13,10 +13,10 @@ help: ## Display this help message .PHONY: update-po-from-url update-po-from-url: ## Update the po files from the URL provide by PROJECT_PUBLIC_URL - curl --fail --retry 5 --retry-delay 1 \ + curl ${CURL_ARGS} --fail --retry 5 --retry-delay 1 \ $(PROJECT_PUBLIC_URL)locale.pot > geoportal/${PACKAGE}_geoportal/locale/${PACKAGE}_geoportal-client${SUFFIX}.pot sed -i '/^"POT-Creation-Date: /d' geoportal/${PACKAGE}_geoportal/locale/${PACKAGE}_geoportal-client${SUFFIX}.pot - docker compose run --rm -T tools update-po-only `id --user` `id --group` $(LANGUAGES) + docker compose run --rm -T --env=SUFFIX=${SUFFIX} tools update-po-only `id --user` `id --group` $(LANGUAGES) .PHONY: update-po update-po: ## Update the po files from the running composition diff --git a/CONST_create_template/docker-compose-lib.yaml b/CONST_create_template/docker-compose-lib.yaml index 2be4401c5..d33386faf 100644 --- a/CONST_create_template/docker-compose-lib.yaml +++ b/CONST_create_template/docker-compose-lib.yaml @@ -344,6 +344,8 @@ services: - C2CWSGIUTILS_LOG_LEVEL - LOG_TYPE - C2CGEOPORTAL_THEME_TIMEOUT=300 + # For multi tenant + - DEFAULT_PREFIX geoportal-advance: image: ${DOCKER_BASE}-geoportal:${DOCKER_TAG} diff --git a/CONST_create_template/env.default b/CONST_create_template/env.default index 0c4dc3c6e..f5aa9a4f7 100644 --- a/CONST_create_template/env.default +++ b/CONST_create_template/env.default @@ -1,5 +1,5 @@ # Default values for c2cgeoportal -GEOMAPFISH_VERSION=2.9.rc.47 +GEOMAPFISH_VERSION=2.9.rc.48 GEOMAPFISH_MAIN_VERSION=2.9 GEOMAPFISH_MAIN_MINOR_VERSION=2.9.0 COMPOSE_PROJECT_NAME=geomapfish diff --git a/CONST_create_template/env.project b/CONST_create_template/env.project index 5f55fe3c6..35a6783df 100644 --- a/CONST_create_template/env.project +++ b/CONST_create_template/env.project @@ -67,3 +67,6 @@ C2C_AUTH_GITHUB_SCOPE=repo #C2C_AUTH_GITHUB_SECRET= #C2C_AUTH_GITHUB_PROXY_URL=https://geoservicies.camptocamp.com/redirect C2C_USE_SESSION=true + +# For multi-tenant +DEFAULT_PREFIX=unknown diff --git a/CONST_create_template/geoportal/geomapfish_geoportal/multi_tenant.py b/CONST_create_template/geoportal/geomapfish_geoportal/multi_tenant.py new file mode 100644 index 000000000..8144d5d35 --- /dev/null +++ b/CONST_create_template/geoportal/geomapfish_geoportal/multi_tenant.py @@ -0,0 +1,7 @@ +from pyramid.config import Configurator + + +def includeme(config: Configurator) -> None: + """Initialize the multi-tenant.""" + + del config # Unused diff --git a/CONST_create_template/scripts/multi-tenant-update-po b/CONST_create_template/scripts/multi-tenant-update-po new file mode 100755 index 000000000..34d6a2f49 --- /dev/null +++ b/CONST_create_template/scripts/multi-tenant-update-po @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import argparse +import os +import subprocess + +import yaml + + +def _main() -> None: + parser = argparse.ArgumentParser( + description="\n".join( + [ + "Update the po files in multi tenants mode", + "", + "Using the information available in the tenants.yaml file.", + ] + ), + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.parse_args() + + with open("tenants.yaml") as tenants_file: + tenants = yaml.safe_load(tenants_file.read()) + + for name, tenant in tenants.get("tenants", {}).items(): + print(f"Update localization for tenant {name}.") + subprocess.run( + [ + "make", + "update-po-from-url", + ], + check=True, + env={ + **os.environ, + "PROJECT_PUBLIC_URL": tenant["public_url"], + "SUFFIX": tenant["suffix"], + "CURL_ARGS": tenant.get("curl_args", ""), + }, + ) + + +if __name__ == "__main__": + _main() diff --git a/Dockerfile b/Dockerfile index 45aac0490..d4a78995f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,7 @@ ENV PGSCHEMA=$PGSCHEMA RUN \ cd /tmp/config/geoportal/ \ + && [ "${SIMPLE}" == "TRUE" ] || rm -f geomapfish_geoportal/*.py \ && c2c-template --vars ${VARS_FILE} \ --get-config geomapfish_geoportal/config.yaml \ ${CONFIG_VARS} \ diff --git a/Makefile b/Makefile index 01528b407..f34332e88 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PROJECT_PUBLIC_URL=https://geomapfish-demo-2-9.camptocamp.com/ +PROJECT_PUBLIC_URL?=https://geomapfish-demo-2-9.camptocamp.com/ DUMP_FILE=data/prod-2-7.dump PACKAGE=geomapfish LANGUAGES=en fr de it @@ -13,10 +13,10 @@ help: ## Display this help message .PHONY: update-po-from-url update-po-from-url: ## Update the po files from the URL provide by PROJECT_PUBLIC_URL - curl --fail --retry 5 --retry-delay 1 \ + curl ${CURL_ARGS} --fail --retry 5 --retry-delay 1 \ $(PROJECT_PUBLIC_URL)locale.pot > geoportal/${PACKAGE}_geoportal/locale/${PACKAGE}_geoportal-client${SUFFIX}.pot sed -i '/^"POT-Creation-Date: /d' geoportal/${PACKAGE}_geoportal/locale/${PACKAGE}_geoportal-client${SUFFIX}.pot - docker compose run --rm -T tools update-po-only `id --user` `id --group` $(LANGUAGES) + docker compose run --rm -T --env=SUFFIX=${SUFFIX} tools update-po-only `id --user` `id --group` $(LANGUAGES) .PHONY: update-po update-po: ## Update the po files from the running composition diff --git a/docker-compose-lib.yaml b/docker-compose-lib.yaml index 2be4401c5..d33386faf 100644 --- a/docker-compose-lib.yaml +++ b/docker-compose-lib.yaml @@ -344,6 +344,8 @@ services: - C2CWSGIUTILS_LOG_LEVEL - LOG_TYPE - C2CGEOPORTAL_THEME_TIMEOUT=300 + # For multi tenant + - DEFAULT_PREFIX geoportal-advance: image: ${DOCKER_BASE}-geoportal:${DOCKER_TAG} diff --git a/env.default b/env.default index 0c4dc3c6e..f5aa9a4f7 100644 --- a/env.default +++ b/env.default @@ -1,5 +1,5 @@ # Default values for c2cgeoportal -GEOMAPFISH_VERSION=2.9.rc.47 +GEOMAPFISH_VERSION=2.9.rc.48 GEOMAPFISH_MAIN_VERSION=2.9 GEOMAPFISH_MAIN_MINOR_VERSION=2.9.0 COMPOSE_PROJECT_NAME=geomapfish diff --git a/env.project b/env.project index dfbeb4151..708a9e246 100644 --- a/env.project +++ b/env.project @@ -62,6 +62,9 @@ OPENID_CONNECT_ENABLED=True AWS_DEFAULT_REGION=ch-dk-2 AWS_S3_ENDPOINT=sos-ch-dk-2.exo.io +# For multi-tenant +DEFAULT_PREFIX=unknown + # Set a strong password here for authentication on technical interfaces behind path /c2c C2C_SECRET=1234 # Or use connection via GitHub, see: https://camptocamp.github.io/c2cgeoportal/2.8/integrator/c2cwsgiutils.html#authentication diff --git a/scripts/multi-tenant-update-po b/scripts/multi-tenant-update-po new file mode 100755 index 000000000..34d6a2f49 --- /dev/null +++ b/scripts/multi-tenant-update-po @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import argparse +import os +import subprocess + +import yaml + + +def _main() -> None: + parser = argparse.ArgumentParser( + description="\n".join( + [ + "Update the po files in multi tenants mode", + "", + "Using the information available in the tenants.yaml file.", + ] + ), + formatter_class=argparse.RawDescriptionHelpFormatter, + ) + parser.parse_args() + + with open("tenants.yaml") as tenants_file: + tenants = yaml.safe_load(tenants_file.read()) + + for name, tenant in tenants.get("tenants", {}).items(): + print(f"Update localization for tenant {name}.") + subprocess.run( + [ + "make", + "update-po-from-url", + ], + check=True, + env={ + **os.environ, + "PROJECT_PUBLIC_URL": tenant["public_url"], + "SUFFIX": tenant["suffix"], + "CURL_ARGS": tenant.get("curl_args", ""), + }, + ) + + +if __name__ == "__main__": + _main()