General optimations and refactorings in preparation for simpleicon role implementation

This commit is contained in:
2025-07-06 14:54:31 +02:00
parent eed72368c1
commit cfeb8a5bf8
41 changed files with 421 additions and 151 deletions

View File

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

View File

View File

@@ -1,25 +0,0 @@
# ---- Builder Stage ----
FROM node:latest AS builder
WORKDIR /app
# Nur package.json und package-lock.json kopieren für schnellere Caching-Layers
COPY package*.json ./
# simple-icons installieren
RUN npm install
# ---- Runtime Stage ----
FROM node:latest
WORKDIR /app
# Nur node_modules aus dem Builder übernehmen
COPY --from=builder /app/node_modules ./node_modules
# Kopiere den Server-Code
COPY server.js .
# Port, auf dem der Server lauscht
ENV PORT=3000
EXPOSE 3000
# Startbefehl
CMD ["node", "server.js"]

View File

@@ -1,14 +0,0 @@
version: '3.8'
services:
icons:
build:
context: .
dockerfile: Dockerfile
image: simpleicons-server:latest
container_name: simpleicons-server
ports:
- "3000:3000"
environment:
- PORT=3000
restart: unless-stopped

View File

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

View File

@@ -5,7 +5,7 @@ import sharp from 'sharp';
const app = express();
const port = process.env.PORT || 3000;
// Helper: turn 'nextcloud' → 'siNextcloud'
// Helper: convert 'nextcloud' → 'siNextcloud'
function getExportName(slug) {
return 'si' + slug
.split('-')
@@ -13,8 +13,13 @@ function getExportName(slug) {
.join('');
}
// GET /icons/:slug.svg
app.get('/icons/:slug.svg', (req, res) => {
// Root: redirect to your documentation
app.get('/', (req, res) => {
res.redirect('https://docs.cymais.cloud/roles/docker-{{ 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];
@@ -23,11 +28,12 @@ app.get('/icons/:slug.svg', (req, res) => {
return res.status(404).send('Icon not found');
}
res.type('image/svg+xml').send(icon.svg);
res.type('image/svg+xml');
res.send(icon.svg);
});
// GET /icons/:slug.png?size=...
app.get('/icons/:slug.png', async (req, res) => {
// 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);
@@ -38,12 +44,13 @@ app.get('/icons/:slug.png', async (req, res) => {
}
try {
const png = await sharp(Buffer.from(icon.svg))
const pngBuffer = await sharp(Buffer.from(icon.svg))
.resize(size, size)
.png()
.toBuffer();
res.type('image/png').send(png);
res.type('image/png');
res.send(pngBuffer);
} catch (err) {
console.error('PNG generation error:', err);
res.status(500).send('PNG generation error');

View File

@@ -0,0 +1 @@
application_id: simpleicons