mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-11-04 12:18:17 +00:00 
			
		
		
		
	Different optimations and bugs
This commit is contained in:
		@@ -41,6 +41,3 @@
 | 
			
		||||
  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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								roles/docker-portfolio/filter_plugins/simpleicons_source.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								roles/docker-portfolio/filter_plugins/simpleicons_source.py
									
									
									
									
									
										Normal file
									
								
							@@ -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,
 | 
			
		||||
        }
 | 
			
		||||
@@ -24,3 +24,5 @@ galaxy_info:
 | 
			
		||||
  documentation: "https://github.com/kevinveenbirkenbach/portfolio#readme"
 | 
			
		||||
  logo:
 | 
			
		||||
    class: "fa-solid fa-briefcase"
 | 
			
		||||
  run_after:
 | 
			
		||||
  - docker-simpleicons
 | 
			
		||||
@@ -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) }}"
 | 
			
		||||
 
 | 
			
		||||
@@ -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' %}
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -24,3 +24,8 @@
 | 
			
		||||
  vars:
 | 
			
		||||
    domain:     "{{ domains | get_domain(application_id) }}"
 | 
			
		||||
    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
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
@@ -21,3 +21,8 @@
 | 
			
		||||
  vars:
 | 
			
		||||
    domain:     "{{ domains | get_domain(application_id) }}"
 | 
			
		||||
    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
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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 %}
 | 
			
		||||
		Reference in New Issue
	
	Block a user