diff --git a/raw/README.md b/raw/README.md new file mode 100644 index 00000000..42e46a75 --- /dev/null +++ b/raw/README.md @@ -0,0 +1,13 @@ +# RAW + +Where all lonely children go to die + +Custom manifests we can't be bothered to template or properly structure. Still try to namespace them and stuff though. + + +```bash +raw +└── tos # site + └── oceanbox # cluster + └── database # whatever +``` diff --git a/raw/tos/oceanbox/database/README.md b/raw/tos/oceanbox/database/README.md new file mode 100644 index 00000000..be381ee7 --- /dev/null +++ b/raw/tos/oceanbox/database/README.md @@ -0,0 +1,6 @@ +Catch-all db for whatever. Currently just used for media files used in grafana. + +Example usage: +- `echo "select * from images" | ./query` +- `cat upload.sql | ./query` +- `./upload-img.sh my-image ~/Picture/pretty.png | ./query` diff --git a/raw/tos/oceanbox/database/create-grafana-image-table.sql b/raw/tos/oceanbox/database/create-grafana-image-table.sql new file mode 100644 index 00000000..c5a1bd55 --- /dev/null +++ b/raw/tos/oceanbox/database/create-grafana-image-table.sql @@ -0,0 +1,5 @@ +CREATE TABLE images ( + name text, + image bytea, + UNIQUE(name) +); diff --git a/raw/tos/oceanbox/database/oceanbox.cluster.yaml b/raw/tos/oceanbox/database/oceanbox.cluster.yaml new file mode 100644 index 00000000..d67e9101 --- /dev/null +++ b/raw/tos/oceanbox/database/oceanbox.cluster.yaml @@ -0,0 +1,20 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: oceanbox + namespace: oceanbox +spec: + instances: 1 + + storage: + size: 10Gi +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Database +metadata: + name: grafana-aux +spec: + name: aux + owner: app + cluster: + name: oceanbox diff --git a/raw/tos/oceanbox/database/query b/raw/tos/oceanbox/database/query new file mode 100755 index 00000000..772a12d6 --- /dev/null +++ b/raw/tos/oceanbox/database/query @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# NOTE(simkir): Pipe your queries into this +# E.g.: +# - echo "select * from images" | ./query +# - cat upload.sql | ./query + +kubectl --context oceanbox -n oceanbox exec -i svc/oceanbox-rw -c postgres -- psql aux diff --git a/raw/tos/oceanbox/database/upload-img.sh b/raw/tos/oceanbox/database/upload-img.sh new file mode 100755 index 00000000..d3f3eb08 --- /dev/null +++ b/raw/tos/oceanbox/database/upload-img.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Simple script for uploading a base64 encoded image into our database. For +# grafana business image panels. + +if [ $# -ne 2 ] +then + echo "Usage: $0 .png" + exit 1 +fi + +filename=$1 +file=$2 + +if [ ! -e $file ] +then + echo "file $file does not exist" + exit 1 +fi + +function create_image() { + local filename=$1 + local data=$2 +cat << EOF +INSERT INTO images VALUES('$filename', '$data'); +EOF +} + +data=$(cat $file | base64 -w0) +create_image $filename $data