diff options
Diffstat (limited to 'roles/cgit')
-rw-r--r-- | roles/cgit/defaults/main.yaml | 12 | ||||
-rw-r--r-- | roles/cgit/files/cgit/Chart.yaml | 5 | ||||
-rw-r--r-- | roles/cgit/files/cgit/templates/configmap.yaml | 31 | ||||
-rw-r--r-- | roles/cgit/files/cgit/templates/deployment.yaml | 38 | ||||
-rw-r--r-- | roles/cgit/files/cgit/templates/ingress.yaml | 47 | ||||
-rw-r--r-- | roles/cgit/files/cgit/templates/pv.yaml | 16 | ||||
-rw-r--r-- | roles/cgit/files/cgit/templates/pvc.yaml | 14 | ||||
-rw-r--r-- | roles/cgit/files/cgit/templates/service.yaml | 21 | ||||
-rw-r--r-- | roles/cgit/files/image/Caddyfile | 13 | ||||
-rw-r--r-- | roles/cgit/files/image/Dockerfile | 12 | ||||
-rwxr-xr-x | roles/cgit/files/image/start.sh | 4 | ||||
-rw-r--r-- | roles/cgit/files/image/syntax-highlighting.py | 55 | ||||
-rw-r--r-- | roles/cgit/files/image/theme.css | 172 | ||||
-rw-r--r-- | roles/cgit/files/image/theme.html | 1 | ||||
-rw-r--r-- | roles/cgit/tasks/main.yaml | 21 |
15 files changed, 462 insertions, 0 deletions
diff --git a/roles/cgit/defaults/main.yaml b/roles/cgit/defaults/main.yaml new file mode 100644 index 0000000..727c4a9 --- /dev/null +++ b/roles/cgit/defaults/main.yaml @@ -0,0 +1,12 @@ +cgit: + enabled: false + replicas: 1 + port: 80 + image: aadityadhruv/cgit + version: latest +softserve: + image: charmcli/soft-serve + version: v0.8.5 + +nfs: + path: "/mnt/nfs/k3s/cgit" diff --git a/roles/cgit/files/cgit/Chart.yaml b/roles/cgit/files/cgit/Chart.yaml new file mode 100644 index 0000000..a5722d5 --- /dev/null +++ b/roles/cgit/files/cgit/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v2 +name: cgit +description: Subsonic compatible music server +type: application +version: 0.1.0 diff --git a/roles/cgit/files/cgit/templates/configmap.yaml b/roles/cgit/files/cgit/templates/configmap.yaml new file mode 100644 index 0000000..e64de68 --- /dev/null +++ b/roles/cgit/files/cgit/templates/configmap.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Chart.Name }}-config +data: + cgitrc: | + cache-size=1000 + #css=/cgit.css + enable-http-clone=1 + enable-blame=1 + enable-commit-graph=1 + enable-log-filecount=1 + enable-log-linecount=1 + enable-git-config=1 + head-include=/usr/share/cgit/theme.html + enable-index-owner=0 + favicon=/favicon.ico + logo=/cgit.png + root-title=Space Junk + mimetype.gif=image/gif + mimetype.html=text/html + mimetype.jpg=image/jpeg + mimetype.jpeg=image/jpeg + mimetype.pdf=application/pdf + mimetype.png=image/png + mimetype.svg=image/svg+xml + source-filter=/usr/lib/cgit/syntax-highlighting.py + readme=:README.md + robots=noindex, nofollow + scan-path=/srv/git/ + diff --git a/roles/cgit/files/cgit/templates/deployment.yaml b/roles/cgit/files/cgit/templates/deployment.yaml new file mode 100644 index 0000000..6ad9c6e --- /dev/null +++ b/roles/cgit/files/cgit/templates/deployment.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "{{ .Chart.Name }}-deployment" + labels: + app: {{ .Chart.Name }} +spec: + replicas: {{ .Values.replicas }} + selector: + matchLabels: + app: {{ .Chart.Name }} + template: + metadata: + labels: + app: {{ .Chart.Name }} + spec: + containers: + - name: cgit + image: "{{ .Values.cgit.image }}:{{ .Values.cgit.version }}" + volumeMounts: + - mountPath: "/etc/cgitrc" + name: "config" + subPath: cgitrc + - mountPath: "/srv/git" + name: "{{ .Chart.Name }}-volume" + subPath: repos + - name: soft-serve + image: "{{ .Values.softserve.image }}:{{ .Values.softserve.version }}" + volumeMounts: + - mountPath: "/soft-serve" + name: "{{ .Chart.Name }}-volume" + volumes: + - name: "config" + configMap: + name: "{{ .Chart.Name }}-config" + - name: "{{ .Chart.Name }}-volume" + persistentVolumeClaim: + claimName: "{{ .Chart.Name }}-pvc" diff --git a/roles/cgit/files/cgit/templates/ingress.yaml b/roles/cgit/files/cgit/templates/ingress.yaml new file mode 100644 index 0000000..2b33366 --- /dev/null +++ b/roles/cgit/files/cgit/templates/ingress.yaml @@ -0,0 +1,47 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: cgit-le + annotations: + cert-manager.io/cluster-issuer: "letsencrypt-prod" +spec: + ingressClassName: traefik + tls: + - hosts: + - git.aadityadhruv.com + secretName: cgit-tls-le + rules: + - host: git.aadityadhruv.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: cgit-service + port: + number: 80 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: cgit-ca + annotations: + cert-manager.io/cluster-issuer: "ca-issuer" +spec: + ingressClassName: traefik + tls: + - hosts: + - git.home + secretName: cgit-tls-ca + rules: + - host: git.home + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: cgit-service + port: + number: 80 diff --git a/roles/cgit/files/cgit/templates/pv.yaml b/roles/cgit/files/cgit/templates/pv.yaml new file mode 100644 index 0000000..f62ea30 --- /dev/null +++ b/roles/cgit/files/cgit/templates/pv.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: "{{ .Chart.Name }}-pv" + labels: + app: "{{ .Chart.Name }}-pv" +spec: + storageClassName: nfs + capacity: + storage: 20Gi + accessModes: + - ReadWriteMany + nfs: + server: {{ .Values.nfs.server }} + path: {{ .Values.nfs.path }} + readOnly: false diff --git a/roles/cgit/files/cgit/templates/pvc.yaml b/roles/cgit/files/cgit/templates/pvc.yaml new file mode 100644 index 0000000..e6153d1 --- /dev/null +++ b/roles/cgit/files/cgit/templates/pvc.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Chart.Name }}-pvc +spec: + storageClassName: nfs + accessModes: + - ReadWriteMany + resources: + requests: + storage: 20Gi + selector: + matchLabels: + app: "{{ .Chart.Name }}-pv" diff --git a/roles/cgit/files/cgit/templates/service.yaml b/roles/cgit/files/cgit/templates/service.yaml new file mode 100644 index 0000000..945bac0 --- /dev/null +++ b/roles/cgit/files/cgit/templates/service.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Chart.Name }}-service +spec: + type: LoadBalancer + selector: + app: {{ .Chart.Name }} + ports: + - protocol: TCP + targetPort: 23231 + port: 22 + name: ssh + - protocol: TCP + port: 81 + targetPort: 23232 + name: http + - protocol: TCP + port: {{ .Values.port }} + targetPort: 80 + name: webui diff --git a/roles/cgit/files/image/Caddyfile b/roles/cgit/files/image/Caddyfile new file mode 100644 index 0000000..35a29b8 --- /dev/null +++ b/roles/cgit/files/image/Caddyfile @@ -0,0 +1,13 @@ +:80 { + @assets path /cgit.css /cgit.png /favicon.ico /theme.css /theme.html + handle @assets { + root * /usr/share/cgit + file_server + } + + reverse_proxy unix//run/fcgiwrap.socket { + transport fastcgi { + env SCRIPT_FILENAME /var/www/cgi-bin/cgit + } + } +} diff --git a/roles/cgit/files/image/Dockerfile b/roles/cgit/files/image/Dockerfile new file mode 100644 index 0000000..894e68a --- /dev/null +++ b/roles/cgit/files/image/Dockerfile @@ -0,0 +1,12 @@ +FROM docker.io/fedora:41 + +RUN dnf install cgit caddy fcgiwrap openssh-server python3-pygments -y +COPY Caddyfile /etc/caddy/Caddyfile +COPY start.sh start.sh +RUN mkdir /usr/lib/cgit -p +COPY theme.css /usr/share/cgit/theme.css +COPY theme.html /usr/share/cgit/theme.html +COPY syntax-highlighting.py /usr/lib/cgit/syntax-highlighting.py +RUN chmod 777 /usr/lib/cgit/syntax-highlighting.py +RUN adduser -m git +CMD ["./start.sh"] diff --git a/roles/cgit/files/image/start.sh b/roles/cgit/files/image/start.sh new file mode 100755 index 0000000..96a279b --- /dev/null +++ b/roles/cgit/files/image/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +/usr/sbin/fcgiwrap -s unix:/run/fcgiwrap.socket & +caddy run --config /etc/caddy/Caddyfile + diff --git a/roles/cgit/files/image/syntax-highlighting.py b/roles/cgit/files/image/syntax-highlighting.py new file mode 100644 index 0000000..e912594 --- /dev/null +++ b/roles/cgit/files/image/syntax-highlighting.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +# This script uses Pygments and Python3. You must have both installed +# for this to work. +# +# http://pygments.org/ +# http://python.org/ +# +# It may be used with the source-filter or repo.source-filter settings +# in cgitrc. +# +# The following environment variables can be used to retrieve the +# configuration of the repository for which this script is called: +# CGIT_REPO_URL ( = repo.url setting ) +# CGIT_REPO_NAME ( = repo.name setting ) +# CGIT_REPO_PATH ( = repo.path setting ) +# CGIT_REPO_OWNER ( = repo.owner setting ) +# CGIT_REPO_DEFBRANCH ( = repo.defbranch setting ) +# CGIT_REPO_SECTION ( = section setting ) +# CGIT_REPO_CLONE_URL ( = repo.clone-url setting ) + + +import sys +import io +from pygments import highlight +from pygments.util import ClassNotFound +from pygments.lexers import TextLexer +from pygments.lexers import guess_lexer +from pygments.lexers import guess_lexer_for_filename +from pygments.formatters import HtmlFormatter + + +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') +data = sys.stdin.read() +filename = sys.argv[1] +formatter = HtmlFormatter(style='pastie', nobackground=True) + +try: + lexer = guess_lexer_for_filename(filename, data) +except ClassNotFound: + # check if there is any shebang + if data[0:2] == '#!': + lexer = guess_lexer(data) + else: + lexer = TextLexer() +except TypeError: + lexer = TextLexer() + +# highlight! :-) +# printout pygments' css definitions as well +sys.stdout.write('<style>') +sys.stdout.write(formatter.get_style_defs('.highlight')) +sys.stdout.write('</style>') +sys.stdout.write(highlight(data, lexer, formatter, outfile=None)) diff --git a/roles/cgit/files/image/theme.css b/roles/cgit/files/image/theme.css new file mode 100644 index 0000000..54357b1 --- /dev/null +++ b/roles/cgit/files/image/theme.css @@ -0,0 +1,172 @@ +:root { + --bg_h: #1d2021; + --bg: #282828; + --bg_s: #32302f; + --bg1: #3c3836; + --bg2: #504945; + --bg3: #665c54; + --bg4: #7c6f64; + + --fg: #fbf1c7; + --fg1: #ebdbb2; + --fg2: #d5c4a1; + --fg3: #bdae93; + --fg4: #a89984; + + --red: #fb4934; + --green: #b8bb26; + --yellow: #fabd2f; + --blue: #83a598; + --purple: #d3869b; + --aqua: #8ec07c; + --gray: #928374; + --orange: #fe8019; + + --red-dim: #cc2412; + --green-dim: #98971a; + --yellow-dim: #d79921; + --blue-dim: #458588; + --purple-dim: #b16286; + --aqua-dim: #689d6a; + --gray-dim: #a89984; + --orange-dim: #d65d0e; +} + +body, #cgit, .path, div#cgit table.blob td.hashes, +div#cgit table.blob td.lines, div#cgit div.cgit-panel table, +div#cgit table.diffstat { + background: var(--bg) !important; + color: var(--fg) !important; + border: none +} + +a { + color: var(--fg) !important; + text-decoration: underline !important; +} + +select, input { + border: none; + background: var(--bg2); + color: var(--fg); +} + +/**************/ +/*** TABLES ***/ +/**************/ +div#cgit table.tabs td a.active { + background: var(--bg) !important; + color: var(--yellow) !important; +} + +div#cgit table.tabs, div#cgit div.content, +div#cgit table#header td.sub { + border: none; +} + +div#cgit table.list tr.nohover, +div#cgit table.list tr:nth-child(2n) { + background: var(--bg) !important; +} + +div#cgit table.list tr:nth-child(2n+1) { + background: var(--bg_s) !important; +} + +div#cgit table.list tr:hover:not(.nohover) { + background: var(--bg1) !important; +} + +/************/ +/*** CODE ***/ +/************/ +div#cgit table.blob td.linenumbers, +div#cgit table.blob { + border-color: var(--gray); +} + +div#cgit table.blob td.linenumbers a { + color: var(--gray) !important; + text-decoration: none !important; +} + +.markdown-body code, .markdown-body tt, +.markdown-body .highlight pre, .markdown-body pre { + background: var(--bg1) !important; +} + +/************/ +/*** AGES ***/ +/************/ +.age-hours { + color: var(--aqua) !important; +} + +.age-days { + color: var(--aqua-dim) !important; +} + +.age-weeks { + color: var(--fg) !important; +} + +.age-months { + color: var(--fg2) !important; +} + +.age-years { + color: var(--fg4) !important; +} + +/******************/ +/*** DECORATORS ***/ +/******************/ +div#cgit a.branch-deco { + background: var(--aqua); + border: none; + color: var(--bg) !important; +} + +div#cgit a.deco { + background: var(--yellow); + border: none; + color: var(--bg) !important; +} + +div#cgit a.tag-deco { + background: var(--gray); + border: none; + color: var(--bg) !important; +} + +/************/ +/*** DIFF ***/ +/************/ +div#cgit table.diff td div.hunk { + color: var(--blue); +} + +div#cgit table.diff td div.del { + color: var(--red); +} + +div#cgit table.diff td div.add { + color: var(--green); +} + +div#cgit table.diff td div.ctx { + color: var(--gray); +} + +div#cgit table.diff td div.head { + color: var(--fg); +} + +div#cgit table.diffstat td.graph td.add { + background: var(--green); +} + +div#cgit table.diffstat td.graph td.rem { + background: var(--red); +} + diff --git a/roles/cgit/files/image/theme.html b/roles/cgit/files/image/theme.html new file mode 100644 index 0000000..f95b5d1 --- /dev/null +++ b/roles/cgit/files/image/theme.html @@ -0,0 +1 @@ +<link rel="stylesheet" type="text/css" href="/theme.css"> diff --git a/roles/cgit/tasks/main.yaml b/roles/cgit/tasks/main.yaml new file mode 100644 index 0000000..0a99ce3 --- /dev/null +++ b/roles/cgit/tasks/main.yaml @@ -0,0 +1,21 @@ +--- +- name: Deploy cgit + kubernetes.core.helm: + name: cgit + chart_ref: "{{ lookup('env', 'PWD') }}/roles/cgit/files/cgit" + namespace: default + state: "{%- if cgit.enabled -%} present {%- else -%} absent {%- endif -%}" + values: + replicas: "{{ cgit.replicas }}" + port: "{{ cgit.port }}" + cgit: + image: "{{ cgit.image }}" + version: "{{ cgit.version }}" + softserve: + image: "{{ softserve.image }}" + version: "{{ softserve.version }}" + nfs: + server: "{{ nfs.server }}" + path: "{{ nfs.path }}" + delegate_to: localhost + run_once: true |