From c8a88a578d07beba591500f809147d562f94b688 Mon Sep 17 00:00:00 2001 From: ange Date: Fri, 3 May 2024 17:16:30 +0200 Subject: [PATCH] feat: homepage --- .env | 2 + .gitea/workflows/deploy.yaml | 23 ++++++++++ README.md | 1 + compose.yaml | 9 ++++ config/bookmarks.yaml | 3 ++ config/custom.css | 0 config/custom.js | 0 config/kubernetes.yaml | 2 + config/settings.yaml | 6 +++ config/widgets.yaml | 9 ++++ manifests/bin/deploy.sh | 39 ++++++++++++++++ manifests/bin/devel.sh | 5 ++ manifests/bin/prod.sh | 5 ++ manifests/common/app.yaml | 76 +++++++++++++++++++++++++++++++ manifests/common/clusterrole.yaml | 31 +++++++++++++ manifests/devel/.gitkeep | 0 manifests/prod/.gitkeep | 0 17 files changed, 211 insertions(+) create mode 100644 .env create mode 100644 .gitea/workflows/deploy.yaml create mode 100644 README.md create mode 100644 compose.yaml create mode 100644 config/bookmarks.yaml create mode 100644 config/custom.css create mode 100644 config/custom.js create mode 100644 config/kubernetes.yaml create mode 100644 config/settings.yaml create mode 100644 config/widgets.yaml create mode 100755 manifests/bin/deploy.sh create mode 100755 manifests/bin/devel.sh create mode 100755 manifests/bin/prod.sh create mode 100644 manifests/common/app.yaml create mode 100644 manifests/common/clusterrole.yaml create mode 100644 manifests/devel/.gitkeep create mode 100644 manifests/prod/.gitkeep diff --git a/.env b/.env new file mode 100644 index 0000000..77c8380 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +PROD_URL=apps.gmoker.com +IMAGEAPP=ghcr.io/gethomepage/homepage:v0.8.12 diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..bd60ffd --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,23 @@ +on: push + +jobs: + deploy: + runs-on: debian + steps: + - uses: actions/checkout@v1 + - name: setup env + run: | + . ./.env || true + if [ "${{ gitea.ref_name }}" == prod ] && [ -n "$PROD_URL" ]; then + BASE_URL="$PROD_URL" + else + BASE_URL="${{ gitea.ref_name }}.$(tr / '\n' <<< "${{ gitea.repository }}" | tac | tr '\n' .)k8s.gmoker.com" + fi + cat <> .env + BASE_URL="$BASE_URL" + EOF + cat .env + + - uses: actions/k8sdeploy@v1 + with: + kubeconfig: "${{ secrets.K8S }}" diff --git a/README.md b/README.md new file mode 100644 index 0000000..29cdfd9 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Element diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..6536a73 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,9 @@ +--- +services: + element: + image: "$IMAGEAPP" + restart: unless-stopped + ports: + - "8080:80" + volumes: + - ./config.json:/app/config.json:ro diff --git a/config/bookmarks.yaml b/config/bookmarks.yaml new file mode 100644 index 0000000..bede0b4 --- /dev/null +++ b/config/bookmarks.yaml @@ -0,0 +1,3 @@ +--- +# For configuration options and examples, please see: +# https://gethomepage.dev/latest/configs/bookmarks diff --git a/config/custom.css b/config/custom.css new file mode 100644 index 0000000..e69de29 diff --git a/config/custom.js b/config/custom.js new file mode 100644 index 0000000..e69de29 diff --git a/config/kubernetes.yaml b/config/kubernetes.yaml new file mode 100644 index 0000000..1854325 --- /dev/null +++ b/config/kubernetes.yaml @@ -0,0 +1,2 @@ +--- +mode: cluster diff --git a/config/settings.yaml b/config/settings.yaml new file mode 100644 index 0000000..63fbcbb --- /dev/null +++ b/config/settings.yaml @@ -0,0 +1,6 @@ +--- +# For configuration options and examples, please see: +# https://gethomepage.dev/latest/configs/settings + +headerStyle: clean +instanceName: public diff --git a/config/widgets.yaml b/config/widgets.yaml new file mode 100644 index 0000000..cb4e9c6 --- /dev/null +++ b/config/widgets.yaml @@ -0,0 +1,9 @@ +--- +# For configuration options and examples, please see: +# https://gethomepage.dev/latest/configs/service-widgets + +- search: + provider: custom + url: https://searx.gmoker.com/search?q= + suggestionUrl: https://searx.gmoker.com/autocompleter?q= + target: _blank diff --git a/manifests/bin/deploy.sh b/manifests/bin/deploy.sh new file mode 100755 index 0000000..19c61f2 --- /dev/null +++ b/manifests/bin/deploy.sh @@ -0,0 +1,39 @@ +#!/bin/bash -e +set -o pipefail + +function kapply() { + for f in "$@"; do + kubectl apply -f \ + <(envsubst "$(env | xargs printf '$%s ')" < "manifests/$f") + done +} + +function kcreatesec() { + kubectl create secret generic --save-config --dry-run=client -oyaml "$@" | kubectl apply -f- +} + +function kcreatecm() { + kubectl create configmap --dry-run=client -oyaml "$@" | kubectl apply -f- +} + +function kgseckey() { + local sec="$1"; shift + local key="$1"; shift + + kubectl get secret "$sec" -o jsonpath="{.data.$key}" | base64 -d +} + +function kgcmkey() { + local cm="$1"; shift + local key="$1"; shift + + kubectl get configmap "$cm" -o jsonpath="{.data.$key}" +} + + +mapfile -t files "$(printf -- '--from-file=%s\n' config/*)" +kcreatecm homepage-config "${files[@]}" + +kapply common/clusterrole.yaml common/app.yaml + +kubectl rollout restart deployment app diff --git a/manifests/bin/devel.sh b/manifests/bin/devel.sh new file mode 100755 index 0000000..464c4d0 --- /dev/null +++ b/manifests/bin/devel.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +export NB_REPLICAS=1 + +. ./manifests/bin/deploy.sh diff --git a/manifests/bin/prod.sh b/manifests/bin/prod.sh new file mode 100755 index 0000000..c97fc9e --- /dev/null +++ b/manifests/bin/prod.sh @@ -0,0 +1,5 @@ +#!/bin/bash -e + +export NB_REPLICAS=3 + +. ./manifests/bin/deploy.sh diff --git a/manifests/common/app.yaml b/manifests/common/app.yaml new file mode 100644 index 0000000..84dec71 --- /dev/null +++ b/manifests/common/app.yaml @@ -0,0 +1,76 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: app + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod +spec: + ingressClassName: nginx + tls: + - secretName: tls-app + hosts: + - "$BASE_URL" + rules: + - host: "$BASE_URL" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: app + port: + name: http +--- +apiVersion: v1 +kind: Service +metadata: + name: app + labels: + app: app +spec: + selector: + app: app + ports: + - name: http + port: 80 + targetPort: http +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app + labels: + app: app +spec: + revisionHistoryLimit: 3 + replicas: $NB_REPLICAS + selector: + matchLabels: + app: app + template: + metadata: + labels: + app: app + spec: + serviceAccountName: homepage + imagePullSecrets: + - name: regcred + containers: + - name: app + image: "$IMAGEAPP" + ports: + - name: http + containerPort: 3000 + volumeMounts: + - name: config + mountPath: /app/config/ + readOnly: true + env: + - name: LOG_TARGETS + value: stdout + volumes: + - name: config + configMap: + name: homepage-config diff --git a/manifests/common/clusterrole.yaml b/manifests/common/clusterrole.yaml new file mode 100644 index 0000000..839975e --- /dev/null +++ b/manifests/common/clusterrole.yaml @@ -0,0 +1,31 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: homepage +automountServiceAccountToken: true +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: homepage +rules: + - apiGroups: + - networking.k8s.io + resources: + - ingresses + verbs: + - get + - list +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: homepage +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: homepage +subjects: + - kind: ServiceAccount + name: homepage diff --git a/manifests/devel/.gitkeep b/manifests/devel/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifests/prod/.gitkeep b/manifests/prod/.gitkeep new file mode 100644 index 0000000..e69de29