4 Commits

Author SHA1 Message Date
685fe225f4 update kubernetes service port 2025-08-26 20:04:58 +02:00
0e8a99a277 update dependencies 2025-08-26 19:26:57 +02:00
76ac71a755 varnish on slimer OS 2025-08-23 23:32:21 +02:00
7251753df5 cleanup console & landing page 2025-08-23 22:33:28 +02:00
11 changed files with 436 additions and 1100 deletions

View File

@@ -91,12 +91,15 @@ steps:
settings: settings:
registry: ghcr.io registry: ghcr.io
repo: ghcr.io/kevinmidboe/varnish-infra-map repo: ghcr.io/kevinmidboe/varnish-infra-map
dockerfile: varnish/Dockerfile contexT: varnish
dockerfile: Dockerfile
compress: true compress: true
username: username:
from_secret: GITHUB_USERNAME from_secret: GITHUB_USERNAME
password: password:
from_secret: GHCR_UPLOAD_TOKEN from_secret: GHCR_UPLOAD_TOKEN
build_args_from_env:
-
tags: tags:
- latest - latest
- ${DRONE_COMMIT_SHA} - ${DRONE_COMMIT_SHA}

View File

@@ -1,5 +1,11 @@
DATABASE_URL=
TRAEFIK_URL=
HTTP_HEALTH_ENDPOINTS=
PROXMOX_URL= PROXMOX_URL=
PROXMOX_TOKEN= PROXMOX_TOKEN=
HOMEASSISTANT_URL= HOMEASSISTANT_URL=
HOMEASSISTANT_TOKEN= HOMEASSISTANT_TOKEN=
TRAEFIK_URL= KUBERNETES_SERVICE_HOST=
KUBERNETES_SA_TOKEN=
KUBERNETES_CA_CERT_PATH=

View File

@@ -9,8 +9,9 @@ metadata:
spec: spec:
ports: ports:
- port: 80 - port: 80
name: http
protocol: TCP protocol: TCP
targetPort: 3000 targetPort: 6081
selector: selector:
app: infra-map app: infra-map
sessionAffinity: None sessionAffinity: None

View File

@@ -1,20 +1,34 @@
# --- Stage 1: Compile svelte-kit project ---
FROM node:22-alpine3.20 AS builder FROM node:22-alpine3.20 AS builder
WORKDIR /app WORKDIR /app
# Copy source files
COPY src/ src COPY src/ src
COPY static/ static COPY static/ static
COPY package.json yarn.lock svelte.config.js tsconfig.json vite.config.ts ./ COPY package.json yarn.lock svelte.config.js tsconfig.json vite.config.ts ./
# Install dependencies
RUN yarn --frozen-lockfile RUN yarn --frozen-lockfile
# Build project
ENV NODE_ENV=production
RUN yarn build RUN yarn build
# --- Stage 2: Run project with node ---
FROM node:22-alpine3.20 FROM node:22-alpine3.20
# Copy compiled project files
WORKDIR /opt/infra-map WORKDIR /opt/infra-map
COPY --from=builder /app/build build COPY --from=builder /app/build build
EXPOSE 3000
ENV NODE_ENV=production ENV NODE_ENV=production
# Install dependencies
RUN yarn install --frozen-lockfile
RUN yarn add @sveltejs/kit
EXPOSE 3000
ENV PORT=3000
CMD [ "node", "build/index.js" ] CMD [ "node", "build/index.js" ]

View File

@@ -61,20 +61,50 @@ Follow hass documentation on generating a api token: https://developers.home-ass
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash ```bash
npm run dev yarn dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
``` ```
## Building ## Building
To create a production version of your app: To create a production version to be run from node:
```bash ```bash
npm run build yarn build
``` ```
You can preview the production build with `npm run preview`. To preview either use vite to serve or execute node entrypoint:
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment. ```bash
yarn preview
```
or
```bash
node build/index.js
```
## Run using docker
The application is configure to be used either standalone or behind a webserver. To build the svelte-application docker image run:
> NB! Remember to configure .env, which is automatically picked up by docker-compose. Set and override for both containers in this file.
Svelte-kit application:
```bash
docker build -t infra-map .
```
Varnish cache:
```bash
cd varnish
docker build -t infra-varnish-cache .
```
Or both using docker compose:
```bash
docker compose up
```

View File

@@ -6,8 +6,9 @@ services:
context: varnish context: varnish
dockerfile: Dockerfile dockerfile: Dockerfile
args: args:
HASS_HOST: 10.0.0.82 # sets build variables. Overridden by env, but has sane defaults
FRONTEND_HOST: app IMAGE_HOST: ${IMAGE_HOST:-homeassistant.local}
PROXY_HOST: ${PROXY_HOST:-app}
ports: ports:
- '6081:6081' - '6081:6081'
depends_on: depends_on:
@@ -17,8 +18,9 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
env_file: '.env' env_file: .env # sets container's environment
environment: environment:
- NODE_ENV=production - NODE_ENV=production
- PORT=3000 - PROTOCOL_HEADER=x-forwarded-proto
- ORIGIN=http://localhost:3000 - HOST_HEADER=x-forwarded-host
- PORT_HEADER=x-forwarded-port

View File

@@ -31,8 +31,6 @@
"prettier": "^3.4.2", "prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.3", "prettier-plugin-svelte": "^3.3.3",
"sass-embedded": "^1.86.0", "sass-embedded": "^1.86.0",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
"svelte": "^5.38.2", "svelte": "^5.38.2",
"svelte-check": "^4.0.0", "svelte-check": "^4.0.0",
"sveltekit-sse": "^0.13.16", "sveltekit-sse": "^0.13.16",

View File

@@ -1,6 +1,5 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'; import { page } from '$app/stores';
import User from '$lib/icons/user.svelte';
import { derived } from 'svelte/store'; import { derived } from 'svelte/store';
// Create a derived store to extract breadcrumb data // Create a derived store to extract breadcrumb data
@@ -9,14 +8,6 @@
return segments.map((segment, index) => { return segments.map((segment, index) => {
let label = decodeURI(segment); let label = decodeURI(segment);
// if not uuid pattern, this is weird order of ops
/*
if (!segment.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)) {
label = label.replace(/-/g, ' ')
}
*/
return { return {
label, label,
path: '/' + segments.slice(0, index + 1).join('/') path: '/' + segments.slice(0, index + 1).join('/')
@@ -40,10 +31,6 @@
<a href={crumb.path}>{crumb.label}</a> <a href={crumb.path}>{crumb.label}</a>
{/each} {/each}
</div> </div>
<div class="right">
<User />
</div>
</div> </div>
<style lang="scss"> <style lang="scss">

View File

@@ -1,4 +1,5 @@
FROM debian:bullseye # --- Stage 1: Compile varnish w/ vmods ---
FROM debian:bullseye-slim AS builder
# Install dependencies # Install dependencies
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
@@ -21,21 +22,36 @@ RUN git clone https://github.com/varnish/libvmod-digest.git /opt/libvmod-digest
./configure VARNISHSRC=/usr/include/varnish && \ ./configure VARNISHSRC=/usr/include/varnish && \
make && make install make && make install
# --- Stage 2: Runtime image ---
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y \
curl gnupg apt-transport-https lsb-release && \
curl -fsSL https://packagecloud.io/varnishcache/varnish73/gpgkey | gpg --dearmor -o /usr/share/keyrings/varnish.gpg && \
echo "deb [signed-by=/usr/share/keyrings/varnish.gpg] https://packagecloud.io/varnishcache/varnish73/debian/ $(lsb_release -cs) main" \
> /etc/apt/sources.list.d/varnish.list && \
apt-get update && apt-get install -y varnish libmhash2 && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy VMOD from builder
COPY --from=builder /usr/lib/varnish/vmods/* /usr/lib/varnish/vmods/
# Copy gomplate from official image
COPY --from=hairyhenderson/gomplate:stable /gomplate /bin/gomplate COPY --from=hairyhenderson/gomplate:stable /gomplate /bin/gomplate
ARG HASS_HOST # Copy configuration
ARG FRONTEND_HOST
ENV HASS_HOST=$HASS_HOST
ENV FRONTEND_HOST=$FRONTEND_HOST
COPY default.vcl.tmpl /etc/varnish/ COPY default.vcl.tmpl /etc/varnish/
COPY *.vcl /etc/varnish/ COPY *.vcl /etc/varnish/
COPY includes /etc/varnish/includes COPY includes /etc/varnish/includes
# Set variables for *.tmpl files
ARG PROXY_HOST=$PROXY_HOST
ARG IMAGE_HOST=$IMAGE_HOST
# Generate VCL
RUN gomplate -f /etc/varnish/default.vcl.tmpl -o /etc/varnish/default.vcl RUN gomplate -f /etc/varnish/default.vcl.tmpl -o /etc/varnish/default.vcl
RUN rm /etc/varnish/default.vcl.tmpl RUN rm /etc/varnish/default.vcl.tmpl
EXPOSE 6081 EXPOSE 6081
CMD ["varnishd", "-F", "-f", "/etc/varnish/default.vcl", "-a", ":6081", "-s", "malloc,512m"] CMD ["varnishd", "-F", "-f", "/etc/varnish/default.vcl", "-a", ":6081", "-s", "malloc,512m"]

View File

@@ -2,18 +2,19 @@ vcl 4.0;
import std; import std;
import digest; import digest;
import directors;
include "includes/x-cache-header.vcl"; include "includes/x-cache-header.vcl";
include "vcl_deliver.vcl"; include "vcl_deliver.vcl";
# Define backend pointing to Home Assistant IP # Define backend pointing to Home Assistant IP
backend hass_backend { backend hass_backend {
.host = "{{ getenv `HASS_HOST` `homeassistant.local` }}"; .host = "{{ getenv `IMAGE_HOST` `homeassistant.local` }}";
.port = "8123"; .port = "8123";
} }
backend app_frontend { backend app_frontend {
.host = "{{ getenv `FRONTEND_HOST` `localhost` }}"; .host = "{{ getenv `PROXY_HOST` `localhost` }}";
.port = "3000"; .port = "3000";
} }
@@ -45,6 +46,17 @@ sub vcl_recv {
unset req.http.Cookie; unset req.http.Cookie;
} }
// Svelte-kit needs to distinguish between it's own files and the Host header.
// The X-Forwarded-* headers below are to tell svelte-kit where it's local files are,
// and the Host header is included in the returned html & js referencing the external
// domain or proxy requested by client.
// https://svelte.dev/docs/kit/adapter-node#Environment-variables-ORIGIN-PROTOCOL_HEADER-HOST_HEADER-and-PORT_HEADER
sub vcl_backend_fetch {
set bereq.http.X-Forwarded-Host = "localhost";
set bereq.http.X-Forwarded-Port = "3000";
set bereq.http.X-Forwarded-Proto = "http";
}
sub vcl_synth { sub vcl_synth {
if (resp.status == 204) { if (resp.status == 204) {
set resp.http.Access-Control-Allow-Origin = "*"; set resp.http.Access-Control-Allow-Origin = "*";

1385
yarn.lock

File diff suppressed because it is too large Load Diff