General optimations

This commit is contained in:
2025-07-09 10:17:32 +02:00
parent a69b2c9cb2
commit af3767fdfa
72 changed files with 377 additions and 618 deletions

View File

@@ -0,0 +1,34 @@
# Simple Icons
## Description
This Ansible role deploys and manages a containerized [Simple Icons](https://simpleicons.org/) server, providing easy access to over 2,000 SVG and PNG icons for use in web projects, documentation, and branding.
## Overview
Ideal for developers and content creators, the role simplifies deploying a dedicated icon server. It automates container setup, configuration, and routing, ensuring reliable, quick access to icons. Easily integrate scalable icons into your projects without managing individual asset files.
## Purpose
The Docker-SimpleIcons role streamlines the deployment and management of a simple, efficient icon server. It helps you:
- Quickly deploy a lightweight, dedicated icon server.
- Serve icons consistently and reliably across multiple projects.
- Reduce manual maintenance of icon assets.
- Integrate seamlessly with complementary Ansible roles and web server configurations.
## Features
- **Icon Server:** Serves scalable SVG and PNG icons from the Simple Icons collection.
- **Containerized Deployment:** Utilizes Docker and Docker Compose for isolated, reliable deployment.
- **Dynamic Icon Delivery:** Icons are dynamically served via RESTful endpoints.
- **Customizable Setup:** Configure icon sizes, formats, and routes effortlessly.
- **Efficient Integration:** Works seamlessly with web server roles for robust domain routing.
- **Automated Maintenance:** Simplifies updates and re-deployments via automated container management.
## Credits 📝
Developed and maintained by **Kevin Veen-Birkenbach**.
Learn more at [www.veen.world](https://www.veen.world)
Part of the [CyMaIS Project](https://github.com/kevinveenbirkenbach/cymais)
License: [CyMaIS NonCommercial License (CNCL)](https://s.veen.world/cncl)

View File

@@ -0,0 +1,27 @@
credentials: {}
docker:
images: {} # @todo Move under services
versions: {} # @todo Move under services
services:
redis:
enabled: false # Enable Redis
database:
enabled: false # Enable the database
features:
matomo: false # Matomo tracking isn't necessary
css: true # Enable Global CSS Styling
portfolio_iframe: true # Enable loading of app in iframe
ldap: false # Enable LDAP Network
central_database: false # Enable Central Database Network
recaptcha: false # Enable ReCaptcha
oauth2: false # Enable the OAuth2-Proy
csp: {}
domains:
canonical:
- "icons.{{ primary_domain }}"
rbac:
roles:
mail-bot:
description: "Has an token to send and recieve emails"

View File

@@ -0,0 +1,26 @@
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Deploy and serve SVG and PNG icons effortlessly with Simple Icons, a containerized icon server ideal for web projects, documentation, and branding."
license: "CyMaIS NonCommercial License (CNCL)"
license_url: "https://s.veen.world/cncl"
company: |
Kevin Veen-Birkenbach
Consulting & Coaching Solutions
https://www.veen.world
min_ansible_version: "2.9"
platforms:
- name: Docker
versions:
- latest
galaxy_tags:
- docker
- icons
- branding
- svg
- png
repository: "https://s.veen.world/cymais"
issue_tracker_url: "https://s.veen.world/cymaisissues"
documentation: "https://s.veen.world/cymais"
logo:
class: "fa-solid fa-icons"
run_after: []

View File

@@ -0,0 +1,30 @@
---
- name: "include docker-compose role"
include_role:
name: docker-compose
when: run_once_docker_simpleicons is not defined
- name: "include role srv-web-proxy-domain for {{application_id}}"
include_role:
name: srv-web-proxy-domain
vars:
domain: "{{ domains | get_domain(application_id) }}"
http_port: "{{ ports.localhost.http[application_id] }}"
when: run_once_docker_simpleicons is not defined
- name: "Copy '{{ application_id }}' files"
template:
src: "{{ item.source }}"
dest: "{{ item.target }}"
mode: '0755'
loop:
- { source: "server.js.j2", target: "{{ simpleicons_host_server_file }}" }
- { source: "package.json.j2", target: "{{ simpleicons_host_package_file }}" }
notify:
- docker compose up
when: run_once_docker_simpleicons is not defined
- name: run the simpleicons tasks once
set_fact:
run_once_docker_simpleicon: true
when: run_once_docker_simpleicons is not defined

View File

@@ -0,0 +1,16 @@
FROM node:latest AS builder
WORKDIR /app
COPY ./config/package*.json ./
RUN npm install
FROM node:latest
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY ./config/server.js .
EXPOSE {{ container_port }}
CMD ["node", "server.js"]

View File

@@ -0,0 +1,14 @@
{% include 'roles/docker-compose/templates/base.yml.j2' %}
application:
build:
context: .
dockerfile: Dockerfile
image: simpleicons-server:latest
container_name: simpleicons-server
ports:
- "{{ports.localhost.http[application_id]}}:{{ container_port }}"
{% include 'roles/docker-container/templates/base.yml.j2' %}
{% include 'roles/docker-container/templates/networks.yml.j2' %}
{% include 'roles/docker-container/templates/healthcheck/curl.yml.j2' %}
{% include 'roles/docker-compose/templates/networks.yml.j2' %}

View File

@@ -0,0 +1 @@
{# This file just exists, because the framework requests it. #}

View File

@@ -0,0 +1,9 @@
{
"name": "simpleicons-server",
"type": "module",
"dependencies": {
"express": "*",
"simple-icons": "*",
"sharp": "*"
}
}

View File

@@ -0,0 +1,62 @@
import express from 'express';
import * as icons from 'simple-icons';
import sharp from 'sharp';
const app = express();
const port = {{ container_port }};
// Helper: convert 'nextcloud' → 'siNextcloud'
function getExportName(slug) {
return 'si' + slug
.split('-')
.map(part => part[0].toUpperCase() + part.slice(1))
.join('');
}
// Root: redirect to your documentation
app.get('/', (req, res) => {
res.redirect('{{ domains | get_url('sphinx', web_protocol) }}/roles/web-app-{{ application_id }}/README.html');
});
// GET /:slug.svg
app.get('/:slug.svg', (req, res) => {
const slug = req.params.slug.toLowerCase();
const exportName = getExportName(slug);
const icon = icons[exportName];
if (!icon) {
return res.status(404).send('Icon not found');
}
res.type('image/svg+xml');
res.send(icon.svg);
});
// GET /:slug.png?size=...
app.get('/:slug.png', async (req, res) => {
const slug = req.params.slug.toLowerCase();
const size = parseInt(req.query.size, 10) || 128;
const exportName = getExportName(slug);
const icon = icons[exportName];
if (!icon) {
return res.status(404).send('Icon not found');
}
try {
const pngBuffer = await sharp(Buffer.from(icon.svg))
.resize(size, size)
.png()
.toBuffer();
res.type('image/png');
res.send(pngBuffer);
} catch (err) {
console.error('PNG generation error:', err);
res.status(500).send('PNG generation error');
}
});
app.listen(port, () => {
console.log(`Simple-Icons server listening at http://0.0.0.0:${port}`);
});

View File

@@ -0,0 +1,4 @@
application_id: simpleicons
container_port: 3000
simpleicons_host_server_file: "{{docker_compose.directories.config}}server.js"
simpleicons_host_package_file: "{{docker_compose.directories.config}}package.json"