mirror of
https://github.com/KevinMidboe/infra-map.git
synced 2025-10-29 17:40:28 +00:00
template varnish config using gomplate
This commit is contained in:
@@ -1,21 +1,24 @@
|
|||||||
version: '3.8'
|
version: '3.9'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
|
||||||
build: .
|
|
||||||
container_name: infra-map
|
|
||||||
ports:
|
|
||||||
- '3000:3000' # svelte-kit preview HTTP
|
|
||||||
varnish:
|
varnish:
|
||||||
build: varnish
|
build:
|
||||||
container_name: varnish-cache
|
context: varnish
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
HASS_HOST: 10.0.0.82
|
||||||
|
FRONTEND_HOST: app
|
||||||
ports:
|
ports:
|
||||||
- '6081:6081' # Varnish HTTP
|
- '6081:6081'
|
||||||
|
depends_on:
|
||||||
|
- app
|
||||||
|
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
env_file: '.env'
|
||||||
environment:
|
environment:
|
||||||
- VARNISH_LISTEN_PORT=6081
|
- NODE_ENV=production
|
||||||
command: >
|
- PORT=3000
|
||||||
varnishd
|
- ORIGIN=http://localhost:3000
|
||||||
-F
|
|
||||||
-f /etc/varnish/default.vcl
|
|
||||||
-s malloc,256m
|
|
||||||
-a :6081
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
import { grey400x225 } from '$lib/utils/staticImageSource';
|
import { grey400x225 } from '$lib/utils/staticImageSource';
|
||||||
import Dialog from './Dialog.svelte';
|
import Dialog from './Dialog.svelte';
|
||||||
|
|
||||||
const IMAGE_PROXY_URL = 'http://localhost:6081';
|
const IMAGE_REFRESH_INTERVAL = 3000;
|
||||||
const IMAGE_REFRESH_INTERVAL = 300;
|
|
||||||
|
|
||||||
let { imageUrl }: { imageUrl: string } = $props();
|
let { imageUrl }: { imageUrl: string } = $props();
|
||||||
let lastUpdated = new Date();
|
let lastUpdated = new Date();
|
||||||
@@ -17,10 +16,15 @@
|
|||||||
function loadBlob(blob: Blob) {
|
function loadBlob(blob: Blob) {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onloadend = () => {
|
reader.onloadend = () => {
|
||||||
imageSource = reader.result || '';
|
|
||||||
const img = document.getElementById('live-image') as HTMLImageElement;
|
const img = document.getElementById('live-image') as HTMLImageElement;
|
||||||
if (!img) return;
|
if (!img) return;
|
||||||
|
|
||||||
|
imageSource = reader?.result || '';
|
||||||
|
if (imageSource === '') {
|
||||||
|
console.log("no image data, returning")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// set imageSource to image element
|
// set imageSource to image element
|
||||||
img.src = `data:image/jpeg;base64; ${imageSource}`;
|
img.src = `data:image/jpeg;base64; ${imageSource}`;
|
||||||
lastUpdated = new Date();
|
lastUpdated = new Date();
|
||||||
@@ -80,6 +84,7 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<Dialog title="Live stream of printer" on:close={() => (fullscreen = false)}>
|
<Dialog title="Live stream of printer" on:close={() => (fullscreen = false)}>
|
||||||
<img style="width: 100%;" src={String(imageSource)} id="live-image" />
|
<img style="width: 100%;" src={String(imageSource)} id="live-image" />
|
||||||
|
<span>Last update {timestamp}s ago</span>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
<img src={String(grey400x225)} />
|
<img src={String(grey400x225)} />
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
if (counter + 1 >= colors.length) counter = 1;
|
if (counter + 1 >= colors.length) counter = 1;
|
||||||
else counter += 1;
|
else counter += 1;
|
||||||
|
|
||||||
console.log(counter);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bgColor: colors[counter - 1][0],
|
bgColor: colors[counter - 1][0],
|
||||||
color: colors[counter - 1][1],
|
color: colors[counter - 1][1],
|
||||||
@@ -99,7 +97,6 @@
|
|||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
line-height: 1.4;
|
line-height: 1.4;
|
||||||
line-height: 1.7;
|
line-height: 1.7;
|
||||||
max-width: 80%;
|
|
||||||
color: #333;
|
color: #333;
|
||||||
|
|
||||||
background-color: #fafafa; /* Subtle background to separate it from the rest */
|
background-color: #fafafa; /* Subtle background to separate it from the rest */
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ const AVAILABLE_RESOURCES = [
|
|||||||
|
|
||||||
export const load: PageServerLoad = async ({ params }) => {
|
export const load: PageServerLoad = async ({ params }) => {
|
||||||
const { resource, uid } = params;
|
const { resource, uid } = params;
|
||||||
console.log('PARAMS:', params);
|
|
||||||
|
|
||||||
if (!AVAILABLE_RESOURCES.includes(resource)) {
|
if (!AVAILABLE_RESOURCES.includes(resource)) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ import { produce } from 'sveltekit-sse';
|
|||||||
|
|
||||||
export function GET({ request }) {
|
export function GET({ request }) {
|
||||||
return produce(async function start({ emit }) {
|
return produce(async function start({ emit }) {
|
||||||
console.log('----- REQUEST -----');
|
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const pod = url.searchParams.get('pod');
|
const pod = url.searchParams.get('pod');
|
||||||
const namespace = url.searchParams.get('namespace');
|
const namespace = url.searchParams.get('namespace');
|
||||||
const container = url.searchParams.get('container');
|
const container = url.searchParams.get('container');
|
||||||
|
|
||||||
console.log('pod, namespace:', pod, namespace);
|
|
||||||
const k8sLogs = createLogStream(pod, namespace, container);
|
const k8sLogs = createLogStream(pod, namespace, container);
|
||||||
k8sLogs.start();
|
k8sLogs.start();
|
||||||
const unsubscribe = k8sLogs.logEmitter.subscribe((msg: string) => {
|
const unsubscribe = k8sLogs.logEmitter.subscribe((msg: string) => {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ async function fetchImage(src: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const GET: RequestHandler = async ({ url }) => {
|
export const GET: RequestHandler = async ({ url }) => {
|
||||||
console.log('GET');
|
|
||||||
url.pathname = url.pathname.replace('/image/', '');
|
url.pathname = url.pathname.replace('/image/', '');
|
||||||
|
|
||||||
const res = await fetchImage(url.href);
|
const res = await fetchImage(url.href);
|
||||||
@@ -21,7 +21,19 @@ 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
|
||||||
|
|
||||||
COPY . /etc/varnish/
|
COPY --from=hairyhenderson/gomplate:stable /gomplate /bin/gomplate
|
||||||
|
|
||||||
|
ARG HASS_HOST
|
||||||
|
ARG FRONTEND_HOST
|
||||||
|
ENV HASS_HOST=$HASS_HOST
|
||||||
|
ENV FRONTEND_HOST=$FRONTEND_HOST
|
||||||
|
|
||||||
|
COPY default.vcl.tmpl /etc/varnish/
|
||||||
|
COPY *.vcl /etc/varnish/
|
||||||
|
COPY includes /etc/varnish/includes
|
||||||
|
|
||||||
|
RUN gomplate -f /etc/varnish/default.vcl.tmpl -o /etc/varnish/default.vcl
|
||||||
|
RUN rm /etc/varnish/default.vcl.tmpl
|
||||||
|
|
||||||
EXPOSE 6081
|
EXPOSE 6081
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,18 @@ vcl 4.0;
|
|||||||
import std;
|
import std;
|
||||||
import digest;
|
import digest;
|
||||||
|
|
||||||
# include "handlers/ttl-override-handler.vcl";
|
|
||||||
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 = "10.0.0.82";
|
.host = "{{ getenv `HASS_HOST` `homeassistant.local` }}";
|
||||||
.port = "8123";
|
.port = "8123";
|
||||||
}
|
}
|
||||||
|
|
||||||
backend app_frontend {
|
backend app_frontend {
|
||||||
.host = "host.docker.internal";
|
.host = "{{ getenv `FRONTEND_HOST` `localhost` }}";
|
||||||
.port = "5173";
|
.port = "3000";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub vcl_recv {
|
sub vcl_recv {
|
||||||
Reference in New Issue
Block a user