diff --git a/.UPGRADE_INSTRUCTIONS b/.UPGRADE_INSTRUCTIONS new file mode 100644 index 000000000..81e52e87b --- /dev/null +++ b/.UPGRADE_INSTRUCTIONS @@ -0,0 +1,6 @@ +The `create.diff` file is a recommendation of the changes that you should apply to your project. +You should apply the changes shown in the diff file on `CONST_create_template/` on your project's ``. +Some advice to be more efficient: if the changes on a file concern a file that you never customize, you can simply copy the new file from `CONST_create_template` (`cp CONST_create_template/ `).You can furthermore add this file to the `unmanaged_files` section of the `project.yaml` file, to avoid its contents appearing in the diff file for the next upgrade. +Note that you can also apply them using: git apply --3way create.diff +To continue, type: +./upgrade 2.9 11 diff --git a/.upgrade.yaml b/.upgrade.yaml new file mode 100644 index 000000000..2620cdf4d --- /dev/null +++ b/.upgrade.yaml @@ -0,0 +1,67 @@ +--- +# The list (by include, exclude) of default files that will not be overwritten by the upgrade. +# That that can be extended with managed_files or reduced with unmanaged_files from the +# project.yaml file in the project root directory. +default_project_file: + include: + - geoportal/setup\.py + - geoportal/vars\.yaml + - geoportal/Makefile + - geoportal/geomapfish_geoportal/__init__\.py + - geoportal/geomapfish_geoportal/templates/.* + - geoportal/geomapfish_geoportal/locale/.* + - geoportal/geomapfish_geoportal/static/.* + - geoportal/geomapfish_geoportal/static-ngeo/.* + - print/print-apps/.* + - mapserver/.* + - tilegeneration/config\.yaml\.tmpl + - project\.yaml + - docker-compose\.yaml + - env\.project + - README\.rst + - \.github/workflows/main\.yaml + - \.github/workflows/rebuild\.yaml + exclude: + - mapserver/demo\.map\.tmpl + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/image/favicon\.ico + +# Files ignored when creating the diff files => will just be left untouched. +no_diff: + - .*\.po + - CONST_.+ + - .*/CONST_.+ + +# Files that will be present in the CONST_create_template but will not be considered in the upgrade. +# Used to provide the alt applications => does not disturb the user during upgrade. +extra: + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt\.html\.ejs + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit\.html\.ejs + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/Controllermobile_alt\.js + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/Controlleroeedit\.js + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/sass/mobile_alt\.scss + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/sass/vars_mobile_alt\.scss + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/sass/oeedit\.scss + - geoportal/geomapfish_geoportal/static-ngeo/js/apps/sass/vars_oeedit\.scss + - geoportal/interfaces/desktop_alt\.html\.mako + - geoportal/geomapfish_geoportal/static/images/background-layer-button\.png + - tests/test_testapp.py + +# Automated file system operations: +# Remove some files or directories: +# - action: remove +# paths: +# - +# Move a file: +# - action: move +# from: +# to: +upgrade_files: + - action: remove + paths: + - geoportal/tools/extract-messages.js + - action: move + from: geoportal/lingua-server.cfg + to: geoportal/lingva-server.cfg + - action: move + from: geoportal/lingua-client.cfg + to: geoportal/lingva-client.cfg diff --git a/CONST_CHANGELOG.txt b/CONST_CHANGELOG.txt index 73738dc99..357ffc928 100644 --- a/CONST_CHANGELOG.txt +++ b/CONST_CHANGELOG.txt @@ -9,6 +9,22 @@ Information to know before starting the upgrade 1. The build command will use Docker Compose version 2 (with the `docker compose` command). +2. RFC 001 - simplification of Ngeo buildtools and custom frontends for GeoMapfish + https://github.com/camptocamp/GeoMapFish/blob/6f8bffaa1e472cdd8ed3de52c8250b5da62d69de/rfcs/rfc_001.md + + Important points: + - The `@ngInject` annotation is no more used, you should pass an array in the function or use the `$inject` property, + see related pull request: https://github.com/camptocamp/ngeo/pull/9453 + - The build will not anymore inline the svg, If you use that you should do it manually, + see related commit: https://github.com/camptocamp/ngeo/pull/9454/commits/fb3ccfb0bdc8273975cdebfd7dbda401416674c3. + - Remove the custom SASS plugin to load the SCSS files. + You should have one SCSS file per interface, the component will not anymore integrate the related style. + See the related pull request: https://github.com/camptocamp/ngeo/pull/9455. + - Update Webpack to version 5 and remove Babel transpilation to ES05, + See the related pull request: https://github.com/camptocamp/ngeo/pull/9463. + - Update FontAwesome to version 6, + See the related pull request: https://github.com/camptocamp/ngeo/pull/9470 + Information =========== diff --git a/CONST_create_template/Dockerfile b/CONST_create_template/Dockerfile index 53ec97d06..e2538a0e7 100644 --- a/CONST_create_template/Dockerfile +++ b/CONST_create_template/Dockerfile @@ -14,7 +14,7 @@ ENV CONFIG_VARS sqlalchemy.url sqlalchemy.pool_recycle sqlalchemy.pool_size sqla dbsessions urllogin host_forward_host headers_whitelist headers_blacklist \ smtp c2c.base_path welcome_email \ lingva_extractor interfaces_config interfaces devserver_url api authentication intranet metrics pdfreport \ - vector_tiles i18next main_ogc_server + vector_tiles i18next main_ogc_server static_files COPY . /tmp/config/ diff --git a/CONST_create_template/docker-compose.override.sample.yaml b/CONST_create_template/docker-compose.override.sample.yaml index c70e4d5ed..52ac887ac 100644 --- a/CONST_create_template/docker-compose.override.sample.yaml +++ b/CONST_create_template/docker-compose.override.sample.yaml @@ -12,7 +12,7 @@ services: # - ./../c2cgeoportal/geoportal/c2cgeoportal_geoportal:/opt/c2cgeoportal/geoportal/c2cgeoportal_geoportal # - ./../c2cgeoportal/admin/c2cgeoportal_admin:/opt/c2cgeoportal/admin/c2cgeoportal_admin command: - - /usr/local/bin/pserve + - /venv/bin/pserve - --reload - c2c:///app/development.ini environment: diff --git a/CONST_create_template/geoportal/Dockerfile b/CONST_create_template/geoportal/Dockerfile index 756233f8c..2706c3b20 100644 --- a/CONST_create_template/geoportal/Dockerfile +++ b/CONST_create_template/geoportal/Dockerfile @@ -41,7 +41,7 @@ RUN chmod go+w /etc/static-ngeo/ RUN --mount=type=cache,target=/root/.cache \ python3 -m pip install --disable-pip-version-check --editable=/app/ \ - && python3 -m compileall -q /usr/local/lib/python3.* \ + && python3 -m compileall -q /venv/lib/python3.* \ -x '/(ptvsd|.*pydev.*|networkx|scaffolds|yaml_include)/' \ && python3 -m compileall -q /app/geomapfish_geoportal -x /app/geomapfish_geoportal/static.* \ && pip freeze > /requirements.txt diff --git a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs index 1f5be1a1f..0a040db94 100644 --- a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs +++ b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs @@ -349,7 +349,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs index 024a8cfd2..8658bbaa9 100644 --- a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs +++ b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs @@ -76,7 +76,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs index fcbb955df..4a773945d 100644 --- a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs +++ b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs @@ -207,7 +207,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs index 80108b61b..d9bf9c403 100644 --- a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs +++ b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs @@ -192,7 +192,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs index 410cfcf86..c8d081589 100644 --- a/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs +++ b/CONST_create_template/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs @@ -160,7 +160,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/CONST_create_template/geoportal/webpack.commons.js b/CONST_create_template/geoportal/webpack.commons.js index 8b0c42c6d..686c84e42 100644 --- a/CONST_create_template/geoportal/webpack.commons.js +++ b/CONST_create_template/geoportal/webpack.commons.js @@ -5,6 +5,7 @@ const config = commons({ context: '/usr/lib/', }, noTs: true, + nodll: true, }); module.exports = () => config; diff --git a/CONST_create_template/tests/test_app.py b/CONST_create_template/tests/test_app.py index f4f246ba6..c60a3ed45 100644 --- a/CONST_create_template/tests/test_app.py +++ b/CONST_create_template/tests/test_app.py @@ -1,3 +1,5 @@ +import time + import pytest import requests @@ -25,7 +27,12 @@ ) def test_url(url: str, params: dict[str, str], timeout: int) -> None: """Tests that some URL didn't return an error.""" - response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec + for _ in range(6): + response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec + if response.status_code == 503: + time.sleep(1) + continue + break assert response.status_code == 200, response.text diff --git a/create.diff b/create.diff new file mode 100644 index 000000000..dfca7bfe1 --- /dev/null +++ b/create.diff @@ -0,0 +1,63 @@ +diff --git a/Dockerfile b/Dockerfile +index 53ec97d..e2538a0 100644 +--- a/Dockerfile ++++ b/Dockerfile +@@ -14,7 +14,7 @@ ENV CONFIG_VARS sqlalchemy.url sqlalchemy.pool_recycle sqlalchemy.pool_size sqla + dbsessions urllogin host_forward_host headers_whitelist headers_blacklist \ + smtp c2c.base_path welcome_email \ + lingva_extractor interfaces_config interfaces devserver_url api authentication intranet metrics pdfreport \ +- vector_tiles i18next main_ogc_server ++ vector_tiles i18next main_ogc_server static_files + + COPY . /tmp/config/ + +diff --git a/docker-compose.override.sample.yaml b/docker-compose.override.sample.yaml +index c70e4d5..52ac887 100644 +--- a/docker-compose.override.sample.yaml ++++ b/docker-compose.override.sample.yaml +@@ -12,7 +12,7 @@ services: + # - ./../c2cgeoportal/geoportal/c2cgeoportal_geoportal:/opt/c2cgeoportal/geoportal/c2cgeoportal_geoportal + # - ./../c2cgeoportal/admin/c2cgeoportal_admin:/opt/c2cgeoportal/admin/c2cgeoportal_admin + command: +- - /usr/local/bin/pserve ++ - /venv/bin/pserve + - --reload + - c2c:///app/development.ini + environment: +diff --git a/geoportal/Dockerfile b/geoportal/Dockerfile +index 756233f..2706c3b 100644 +--- a/geoportal/Dockerfile ++++ b/geoportal/Dockerfile +@@ -41,7 +41,7 @@ RUN chmod go+w /etc/static-ngeo/ + + RUN --mount=type=cache,target=/root/.cache \ + python3 -m pip install --disable-pip-version-check --editable=/app/ \ +- && python3 -m compileall -q /usr/local/lib/python3.* \ ++ && python3 -m compileall -q /venv/lib/python3.* \ + -x '/(ptvsd|.*pydev.*|networkx|scaffolds|yaml_include)/' \ + && python3 -m compileall -q /app/geomapfish_geoportal -x /app/geomapfish_geoportal/static.* \ + && pip freeze > /requirements.txt +diff --git a/tests/test_app.py b/tests/test_app.py +index f4f246b..c60a3ed 100644 +--- a/tests/test_app.py ++++ b/tests/test_app.py +@@ -1,3 +1,5 @@ ++import time ++ + import pytest + import requests + +@@ -25,7 +27,12 @@ import requests + ) + def test_url(url: str, params: dict[str, str], timeout: int) -> None: + """Tests that some URL didn't return an error.""" +- response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec ++ for _ in range(6): ++ response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec ++ if response.status_code == 503: ++ time.sleep(1) ++ continue ++ break + assert response.status_code == 200, response.text + + diff --git a/geoportal/CONST_config-schema.yaml b/geoportal/CONST_config-schema.yaml index 8763f55a1..df925e8ff 100644 --- a/geoportal/CONST_config-schema.yaml +++ b/geoportal/CONST_config-schema.yaml @@ -121,6 +121,8 @@ mapping: layout: type: str default: ngeo + html_filename: + type: str interfaces_config: required: True type: map @@ -205,6 +207,12 @@ mapping: oauth2_token_expire_minutes: type: scalar required: false + oauth2: + type: map + required: false + mapping: + enabled: + type: bool allowed_hosts: type: seq sequence: @@ -214,8 +222,8 @@ mapping: required: false mapping: enabled: - type: bool - default: false + type: scalar + # default: false url: type: str required: false @@ -239,6 +247,22 @@ mapping: query_user_info: type: bool default: false + create_user: + type: bool + default: false + match_field: + type: str + enum: + - username + - email + update_fields: + type: seq + sequence: + - type: str + enum: + - username + - display_name + - email user_info_fields: type: map mapping: diff --git a/geoportal/CONST_vars.yaml b/geoportal/CONST_vars.yaml index e9145897b..67a9d6bf1 100644 --- a/geoportal/CONST_vars.yaml +++ b/geoportal/CONST_vars.yaml @@ -43,6 +43,8 @@ vars: oauth2_token_expire_minutes: 60 oauth2_authorization_expire_minutes: 10 max_consecutive_failures: 10 + openid_connect: + enabled: '{OPENID_CONNECT_ENABLED}' intranet: networks: [] @@ -1389,6 +1391,8 @@ runtime_environment: default: '' - name: SENTRY_CLIENT_ENVIRONMENT default: '' + - name: OPENID_CONNECT_ENABLED + default: 'false' runtime_postprocess: - expression: int({}) @@ -1469,6 +1473,7 @@ runtime_postprocess: - expression: str({}).lower() in ("true", "yes", "1") vars: - authentication.two_factor + - authentication.openid_connect.enabled - getitfixed.enabled - layers.geometry_validation - smtp.ssl diff --git a/geoportal/Dockerfile b/geoportal/Dockerfile index bb2766072..0ad2ba361 100644 --- a/geoportal/Dockerfile +++ b/geoportal/Dockerfile @@ -44,7 +44,7 @@ RUN chmod go+w /etc/static-ngeo/ RUN --mount=type=cache,target=/root/.cache \ python3 -m pip install --disable-pip-version-check --editable=/app/ \ - && python3 -m compileall -q /usr/local/lib/python3.* \ + && python3 -m compileall -q /venv/lib/python3.* \ -x '/(ptvsd|.*pydev.*|networkx|scaffolds|yaml_include)/' \ && python3 -m compileall -q /app/geomapfish_geoportal -x /app/geomapfish_geoportal/static.* diff --git a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs index 1f5be1a1f..0a040db94 100644 --- a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs +++ b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/desktop.html.ejs @@ -349,7 +349,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs index 024a8cfd2..8658bbaa9 100644 --- a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs +++ b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/iframe_api.html.ejs @@ -76,7 +76,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs index fcbb955df..4a773945d 100644 --- a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs +++ b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile.html.ejs @@ -207,7 +207,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs index 80108b61b..d9bf9c403 100644 --- a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs +++ b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/mobile_alt.html.ejs @@ -192,7 +192,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs index 410cfcf86..c8d081589 100644 --- a/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs +++ b/geoportal/geomapfish_geoportal/static-ngeo/js/apps/oeedit.html.ejs @@ -160,7 +160,7 @@ 'Ihr Browser wird nicht unterstützt, bitte verwenden Sie eine aktuelle Version von Firefox, Chrome oder Edge.' ); - + <% for (var js in htmlWebpackPlugin.files.js) { %> <% } %> diff --git a/tests/test_app.py b/tests/test_app.py index fa124e97f..5f146b493 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -30,11 +30,23 @@ ) def test_url(url: str, params: dict[str, str], timeout: int) -> None: """Tests that some URL didn't return an error.""" +<<<<<<< ours response = None +======= +>>>>>>> theirs for _ in range(6): response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec if response.status_code == 503: time.sleep(1) continue break +<<<<<<< ours +======= + assert response.status_code == 200, response.text + + +def test_admin() -> None: + """Tests that the admin page will provide the login page.""" + response = requests.get("https://front/admin/", verify=False, timeout=30) # nosec +>>>>>>> theirs assert response.status_code == 200, response.text diff --git a/upgrade b/upgrade new file mode 100755 index 000000000..c52341095 --- /dev/null +++ b/upgrade @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2019-2023, Camptocamp SA +# All rights reserved. + +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: + +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. + +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. + + +import argparse +import os +import platform +import re +import subprocess +import sys + +parser = argparse.ArgumentParser(description="Upgrade the project") +parser.add_argument( + "--debug", help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure" +) +parser.add_argument("version", help="the version to upgrade to (master or x.y.z)") +parser.add_argument("step", nargs="?", help="the step to run") +parser_finalize = argparse.ArgumentParser(description="Upgrade the project", add_help=False) +parser_finalize.add_argument("--finalize", action="store_true", help="finalize the upgrade") +parser_finalize.add_argument("--help", action="help", help="show this help message and exit") +parser_finalize.add_argument("build_arg", nargs="*", help="build arguments") + +if len(sys.argv) >= 2 and sys.argv[1] == "--finalize": + args = parser_finalize.parse_args() + + if platform.system() == "Windows": + code = subprocess.call(["python", "build"] + args.build_arg) + else: + code = subprocess.call(["./build"] + args.build_arg) + if code != 0: + sys.exit(code) + + subprocess.call(["docker", "compose", "down", "--remove-orphans"]) + subprocess.call( + ["docker", "compose", "pull", "--ignore-pull-failures"], + env={**os.environ, "DOCKER_TAG": "unexisting"}, + ) + subprocess.check_call(["docker", "compose", "up", "-d"]) + subprocess.check_call( + [ + "docker", + "compose", + "exec", + "geoportal", + "alembic", + "--name=main", + "--config=alembic.ini", + "upgrade", + "head", + ] + ) + +else: + args = parser.parse_args() + + c2cupgrade_args = ["--step", args.step] if args.step is not None else [] + + if os.environ.get("CI") != "true" and args.step is None: + major_version = args.version + match = re.match(r"^([0-9]+\.[0-9]+)\.[0-9]+$", args.version) + if match is not None: + major_version = match.group(1) + match = re.match(r"^([0-9]+\.[0-9]+)\.[0-9a-z]+\.[0-9]+$", args.version) + if match is not None: + major_version = match.group(1) + if not args.debug: + subprocess.check_call( + [ + "docker", + "pull", + f"camptocamp/geomapfish:{major_version}", + ] + ) + subprocess.check_call(["docker", "pull", f"camptocamp/geomapfish-tools:{args.version}"]) + subprocess.check_call( + [ + "docker", + "pull", + f"camptocamp/geomapfish-config:{major_version}", + ] + ) + + debug_volumes = ( + [ + "--volume={debug}/geoportal/c2cgeoportal_geoportal/scripts/c2cupgrade.py:".format( + debug=args.debug + ), + "/opt/c2cgeoportal/geoportal/c2cgeoportal_geoportal/scripts/c2cupgrade.py", + ] + if args.debug + else [] + ) + + win = platform.system() == "Windows" + sys.exit( + subprocess.call( + [ + "docker", + "run", + "--rm", + "--env=CI", + f"--volume={os.getcwd()}:/src", + ] + + debug_volumes + + [ + f"camptocamp/geomapfish-tools:{args.version}", + "run-git", + subprocess.check_output(["git", "config", "--get", "user.name"]).decode().strip(), + subprocess.check_output(["git", "config", "--get", "user.email"]).decode().strip(), + "" if win else subprocess.check_output(["id", "-u"]).decode().strip(), + "" if win else subprocess.check_output(["id", "-g"]).decode().strip(), + "/src", + "c2cupgrade", + ] + + c2cupgrade_args + ) + )