From a6d226769ca5e25684c5e2c73746b86d47b409f6 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 7 Jul 2025 12:52:37 +0200 Subject: [PATCH] Different optimations and bugs --- roles/docker-compose/tasks/files.yml | 5 +- .../filter_plugins/simpleicons_source.py | 58 +++++++++++++++++++ roles/docker-portfolio/meta/main.yml | 2 + roles/docker-portfolio/tasks/main.yml | 8 +++ .../docker-portfolio/templates/config.yaml.j2 | 8 ++- roles/docker-portfolio/vars/configuration.yml | 2 + roles/docker-presentation/tasks/main.yml | 9 ++- roles/docker-simpleicons/tasks/main.yml | 2 +- roles/docker-sphinx/tasks/main.yml | 9 ++- .../templates/docker-compose.yml.j2 | 2 +- templates/docker_role/tasks/main.yml.j2 | 2 +- 11 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 roles/docker-portfolio/filter_plugins/simpleicons_source.py diff --git a/roles/docker-compose/tasks/files.yml b/roles/docker-compose/tasks/files.yml index 77f8e515..862dae9c 100644 --- a/roles/docker-compose/tasks/files.yml +++ b/roles/docker-compose/tasks/files.yml @@ -40,7 +40,4 @@ register: docker_ps changed_when: (docker_ps.stdout | trim) == "" notify: docker compose up - when: not (docker_compose_template.changed or env_template.changed) - -- name: flush docker compose up - meta: flush_handlers + when: not (docker_compose_template.changed or env_template.changed) \ No newline at end of file diff --git a/roles/docker-portfolio/filter_plugins/simpleicons_source.py b/roles/docker-portfolio/filter_plugins/simpleicons_source.py new file mode 100644 index 00000000..2f29949b --- /dev/null +++ b/roles/docker-portfolio/filter_plugins/simpleicons_source.py @@ -0,0 +1,58 @@ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +import requests +import re +from ansible.errors import AnsibleFilterError + + +def slugify(name): + """Convert a display name to a simple-icons slug format.""" + # Replace spaces and uppercase letters + return re.sub(r'\s+', '-', name.strip().lower()) + + +def add_simpleicon_source(cards, domains, web_protocol='https'): + """ + For each card in portfolio_cards, check if an icon exists in the simpleicons server. + If it does, add icon.source with the URL to the card entry. + + :param cards: List of card dictionaries (portfolio_cards) + :param domains: Mapping of application_id to domain names + :param web_protocol: Protocol to use (https or http) + :return: New list of cards with icon.source set when available + """ + # Determine simpleicons service domain + simpleicons_domain = domains.get('simpleicons') + if isinstance(simpleicons_domain, list): + simpleicons_domain = simpleicons_domain[0] + if not simpleicons_domain: + raise AnsibleFilterError("Domain for 'simpleicons' not found in domains mapping") + base_url = f"{web_protocol}://{simpleicons_domain}" + + enhanced = [] + for card in cards: + title = card.get('title', '') + if not title: + enhanced.append(card) + continue + # Create slug from title + slug = slugify(title) + icon_url = f"{base_url}/{slug}.svg" + try: + resp = requests.head(icon_url, timeout=2) + if resp.status_code == 200: + card.setdefault('icon', {})['source'] = icon_url + except requests.RequestException: + # Ignore network errors and move on + pass + enhanced.append(card) + return enhanced + + +class FilterModule(object): + """Ansible filter plugin to add simpleicons source URLs to portfolio cards""" + def filters(self): + return { + 'add_simpleicon_source': add_simpleicon_source, + } \ No newline at end of file diff --git a/roles/docker-portfolio/meta/main.yml b/roles/docker-portfolio/meta/main.yml index 831a9074..daf968af 100644 --- a/roles/docker-portfolio/meta/main.yml +++ b/roles/docker-portfolio/meta/main.yml @@ -24,3 +24,5 @@ galaxy_info: documentation: "https://github.com/kevinveenbirkenbach/portfolio#readme" logo: class: "fa-solid fa-briefcase" + run_after: + - docker-simpleicons \ No newline at end of file diff --git a/roles/docker-portfolio/tasks/main.yml b/roles/docker-portfolio/tasks/main.yml index 6420d63e..4c6e1087 100644 --- a/roles/docker-portfolio/tasks/main.yml +++ b/roles/docker-portfolio/tasks/main.yml @@ -1,4 +1,5 @@ --- + - name: "include docker-compose role" include_role: name: docker-compose @@ -30,6 +31,13 @@ portfolio_cards: "{{ lookup('docker_cards', 'roles') }}" when: run_once_docker_portfolio is not defined +- name: "Load images for applications feature simpleicons is enabled " + set_fact: + portfolio_cards: "{{ portfolio_cards | add_simpleicon_source(domains, web_protocol) }}" + when: + - (applications | is_feature_enabled('simpleicons',application_id)) + - run_once_docker_portfolio is not defined + - name: Group docker cards set_fact: portfolio_menu_data: "{{ lookup('docker_cards_grouped', portfolio_cards, portfolio_menu_categories) }}" diff --git a/roles/docker-portfolio/templates/config.yaml.j2 b/roles/docker-portfolio/templates/config.yaml.j2 index b54aae93..8f02288b 100644 --- a/roles/docker-portfolio/templates/config.yaml.j2 +++ b/roles/docker-portfolio/templates/config.yaml.j2 @@ -102,7 +102,7 @@ company: navigation: header: children: - - link: accounts.publishingchannels.children + - link: accounts.publishingchannels - name: Contact description: Get in touch with {{ 'us' if service_provider.type == 'legal' else 'me' }} icon: @@ -140,4 +140,10 @@ navigation: {% endif %} + - name: Toggle Fullscreen + description: Enter or exit fullscreen mode + icon: + class: fa-solid fa-expand-arrows-alt + onclick: "toggleFullscreen()" + {% include 'footer_menu.yaml.j2' %} \ No newline at end of file diff --git a/roles/docker-portfolio/vars/configuration.yml b/roles/docker-portfolio/vars/configuration.yml index 3bce8e50..8fcf60ca 100644 --- a/roles/docker-portfolio/vars/configuration.yml +++ b/roles/docker-portfolio/vars/configuration.yml @@ -2,6 +2,8 @@ features: matomo: true css: true portfolio_iframe: false + simpleicons: true # Activate Brand Icons for your groups +nasa_api_key: false # Set api key to use the Nasa Picture of the Day as Background csp: whitelist: script-src-elem: diff --git a/roles/docker-presentation/tasks/main.yml b/roles/docker-presentation/tasks/main.yml index f3058a9c..db039d94 100644 --- a/roles/docker-presentation/tasks/main.yml +++ b/roles/docker-presentation/tasks/main.yml @@ -4,7 +4,7 @@ name: pkgmgr-install vars: package_name: cymais-presentation - package_notify: docker compose up + # package_notify: docker compose up - name: Get path of cymais-presentation using pkgmgr command: pkgmgr path cymais-presentation @@ -23,4 +23,9 @@ name: nginx-domain-setup vars: domain: "{{ domains | get_domain(application_id) }}" - http_port: "{{ ports.localhost.http[application_id] }}" \ No newline at end of file + http_port: "{{ ports.localhost.http[application_id] }}" + +# Hack because it wasn't possible to fix an handler bug in pkgmgr install +- name: „Trigger“ docker compose up + command: /bin/true + notify: docker compose up \ No newline at end of file diff --git a/roles/docker-simpleicons/tasks/main.yml b/roles/docker-simpleicons/tasks/main.yml index a65e7216..0430d8a5 100644 --- a/roles/docker-simpleicons/tasks/main.yml +++ b/roles/docker-simpleicons/tasks/main.yml @@ -26,5 +26,5 @@ - name: run the simpleicons tasks once set_fact: - run_once_docker_portfolio: true + run_once_docker_simpleicon: true when: run_once_docker_simpleicons is not defined diff --git a/roles/docker-sphinx/tasks/main.yml b/roles/docker-sphinx/tasks/main.yml index 23513dc6..3b0651a4 100644 --- a/roles/docker-sphinx/tasks/main.yml +++ b/roles/docker-sphinx/tasks/main.yml @@ -5,7 +5,7 @@ name: pkgmgr-install vars: package_name: cymais-sphinx - package_notify: docker compose up + # package_notify: docker compose up - name: Get path of cymais-sphinx using pkgmgr command: pkgmgr path cymais-sphinx @@ -20,4 +20,9 @@ name: nginx-domain-setup vars: domain: "{{ domains | get_domain(application_id) }}" - http_port: "{{ ports.localhost.http[application_id] }}" \ No newline at end of file + http_port: "{{ ports.localhost.http[application_id] }}" + +# Hack because it wasn't possible to fix an handler bug in pkgmgr install +- name: „Trigger“ docker compose up + command: /bin/true + notify: docker compose up \ No newline at end of file diff --git a/roles/docker-sphinx/templates/docker-compose.yml.j2 b/roles/docker-sphinx/templates/docker-compose.yml.j2 index 8c6ee57e..03630561 100644 --- a/roles/docker-sphinx/templates/docker-compose.yml.j2 +++ b/roles/docker-sphinx/templates/docker-compose.yml.j2 @@ -1,6 +1,6 @@ {% include 'roles/docker-compose/templates/base.yml.j2' %} application: -{% set container_port = 8008 %} +{% set container_port = 8000 %} build: context: {{ path_cymais_sphinx_output.stdout }} dockerfile: {{ path_cymais_sphinx_output.stdout }}/Dockerfile diff --git a/templates/docker_role/tasks/main.yml.j2 b/templates/docker_role/tasks/main.yml.j2 index 723130e2..0808cbfd 100644 --- a/templates/docker_role/tasks/main.yml.j2 +++ b/templates/docker_role/tasks/main.yml.j2 @@ -33,6 +33,6 @@ - name: run the {% endraw %}{{ application_id }}{% raw %} tasks once set_fact: - run_once_docker_portfolio: true + run_once_docker_{% endraw %}{{ application_id }}{% raw %}: true when: run_once_docker_{% endraw %}{{ application_id }}{% raw %} is not defined {% endraw %} \ No newline at end of file