mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 18:29:21 +00:00 
			
		
		
		
	General optimations and refactorings in preparation for simpleicon role implementation
This commit is contained in:
		| @@ -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"] | ||||
| @@ -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 | ||||
							
								
								
									
										14
									
								
								roles/docker-simpleicons/templates/docker-compose.yml.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								roles/docker-simpleicons/templates/docker-compose.yml.j2
									
									
									
									
									
										Normal 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' %} | ||||
|  | ||||
| @@ -1,9 +0,0 @@ | ||||
| { | ||||
|   "name": "simpleicons-server", | ||||
|   "type": "module", | ||||
|   "dependencies": { | ||||
|     "express": "^4.18.2", | ||||
|     "simple-icons": "^9.0.0", | ||||
|     "sharp": "^0.32.0" | ||||
|   } | ||||
| } | ||||
| @@ -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'); | ||||
		Reference in New Issue
	
	Block a user