diff --git a/flake.nix b/flake.nix index 452c56e..1ff3994 100644 --- a/flake.nix +++ b/flake.nix @@ -40,8 +40,20 @@ }; }; - devShells.default = - pkgs.mkShell {buildInputs = with pkgs; [go gopls goreleaser docker];}; + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + # Go tools + go + gopls + goreleaser + + # Required for goreleaser + docker + + # Testing + skaffold + ]; + }; }; flake = { }; diff --git a/k8s/bridge.yaml b/k8s/bridge.yaml new file mode 100644 index 0000000..68be542 --- /dev/null +++ b/k8s/bridge.yaml @@ -0,0 +1,59 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: bridge-config +data: + config.scfg: | + http-address 0.0.0.0:8080 + log-level info + log-format text + + ntfy { + server http://ntfy:80 + } + + handler "/flux" { + type "flux" + topic "flux" + } +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: bridge +spec: + selector: + matchLabels: + app: bridge + template: + metadata: + labels: + app: bridge + spec: + containers: + - name: bridge + image: forge.babariviere.com/babariviere/ntfy-bridge:latest + ports: + - containerPort: 8080 + volumeMounts: + - mountPath: /etc/ntfy-bridge/config.scfg + subPath: config.scfg + name: config-volume + volumes: + - name: config-volume + configMap: + name: bridge-config + +--- +apiVersion: v1 +kind: Service +metadata: + name: bridge +spec: + ports: + - port: 8080 + name: http + type: LoadBalancer + selector: + app: bridge diff --git a/k8s/flux.yaml b/k8s/flux.yaml new file mode 100644 index 0000000..f43fec9 --- /dev/null +++ b/k8s/flux.yaml @@ -0,0 +1,42 @@ +--- +apiVersion: notification.toolkit.fluxcd.io/v1beta2 +kind: Provider +metadata: + name: ntfy-bridge-dev +spec: + type: generic + secretRef: + name: ntfy-bridge-dev-address +--- +apiVersion: v1 +kind: Secret +metadata: + name: ntfy-bridge-dev-address +stringData: + address: "http://bridge.ntfy-bridge-dev.svc.cluster.local:8080/flux" +--- +apiVersion: notification.toolkit.fluxcd.io/v1beta2 +kind: Alert +metadata: + name: ntfy-bridge-dev +spec: + summary: "k3s cluster" + providerRef: + name: ntfy-bridge-dev + eventSeverity: info + eventSources: + - kind: GitRepository + name: '*' + namespace: flux-system + - kind: Kustomization + name: '*' + namespace: flux-system + - kind: HelmRepository + name: '*' + namespace: flux-system + - kind: HelmChart + name: '*' + namespace: flux-system + - kind: HelmRelease + name: '*' + namespace: flux-system diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml new file mode 100644 index 0000000..c2f6c97 --- /dev/null +++ b/k8s/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: ntfy-bridge-dev +resources: + - namespace.yaml + - bridge.yaml + - flux.yaml + - ntfy.yaml diff --git a/k8s/namespace.yaml b/k8s/namespace.yaml new file mode 100644 index 0000000..7ae0689 --- /dev/null +++ b/k8s/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: ntfy-bridge-dev diff --git a/k8s/ntfy.yaml b/k8s/ntfy.yaml new file mode 100644 index 0000000..5e18fd1 --- /dev/null +++ b/k8s/ntfy.yaml @@ -0,0 +1,77 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: ntfy-config +data: + server.yml: | + cache-file: "/var/cache/ntfy/cache.db" +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ntfy + labels: + app: ntfy +spec: + revisionHistoryLimit: 1 + replicas: 1 + selector: + matchLabels: + app: ntfy + template: + metadata: + labels: + app: ntfy + spec: + containers: + - name: ntfy + image: binwiederhier/ntfy:latest + imagePullPolicy: Always + args: ["serve"] + env: + - name: TZ # set timezone + value: Etc/UTC + - name: NTFY_DEBUG # enable/disable debug + value: "true" + - name: NTFY_LOG_LEVEL # adjust log level + value: INFO + ports: + - name: ntfy-http + containerPort: 80 + resources: + limits: + memory: 300Mi + requests: + cpu: 150m + memory: 150Mi + volumeMounts: + - mountPath: /etc/ntfy/server.yml + subPath: server.yml + name: config-volume + - mountPath: /var/cache/ntfy + name: cache-volume #cache volume mounted to persistent volume + - mountPath: /var/lib/ntfy + name: lib-volume + volumes: + - name: config-volume + configMap: + name: ntfy-config + - name: cache-volume + emptyDir: {} + - name: lib-volume + emptyDir: {} +--- +apiVersion: v1 +kind: Service +metadata: + name: ntfy-http +spec: + type: ClusterIP + selector: + app: ntfy + ports: + - name: ntfy-http-out + protocol: TCP + port: 80 + targetPort: ntfy-http diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..22c9473 --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,15 @@ +apiVersion: skaffold/v4beta6 +kind: Config +metadata: + name: ntfy-bridge +build: + artifacts: + - image: forge.babariviere.com/babariviere/ntfy-bridge + buildpacks: +manifests: + kustomize: + paths: + - k8s +deploy: + kubectl: + defaultNamespace: ntfy-bridge-dev