feat(infra/k8s): Rewrite cgit URLs by routing them through nginx

Configures nginx to rewrite all requests to cgit, except for those
retrieving static files, to `/depot/`.

In combination with the previous commits that apply patches to cgit
itself, this effectively means that the depot is rendered on the site
root.

This is pretty cool: It lets people do stuff like `git clone
https://git.tazj.in` and get the depot!
This commit is contained in:
Vincent Ambo 2019-12-20 18:42:56 +00:00
parent 0dee62cd7b
commit c3586aa8ba
3 changed files with 27 additions and 10 deletions

View file

@ -65,10 +65,9 @@ kind: Service
metadata: metadata:
name: cgit name: cgit
spec: spec:
type: NodePort
selector: selector:
app: cgit app: cgit
ports: ports:
- protocol: TCP - protocol: TCP
port: 2448 # cgit port: 80
targetPort: 8080 targetPort: 8080

View file

@ -8,20 +8,23 @@ metadata:
annotations: annotations:
networking.gke.io/managed-certificates: tazj-in, git-tazj-in, www-tazj-in, oslo-pub networking.gke.io/managed-certificates: tazj-in, git-tazj-in, www-tazj-in, oslo-pub
spec: spec:
# Default traffic is routed to the blog, in case people go to rules:
# peculiar hostnames. # Route blog to the blog ...
- host: tazj.in
http:
paths:
- path: /*
backend: backend:
serviceName: tazblog serviceName: tazblog
servicePort: 8000 servicePort: 8000
rules:
# Route git.tazj.in to the cgit pods # Route git.tazj.in to the cgit pods
- host: git.tazj.in - host: git.tazj.in
http: http:
paths: paths:
- path: / - path: /*
backend: backend:
serviceName: cgit serviceName: nginx
servicePort: 2448 servicePort: 6756
# Route oslo.pub to the nginx instance which serves redirects # Route oslo.pub to the nginx instance which serves redirects
- host: oslo.pub - host: oslo.pub
http: http:

View file

@ -41,4 +41,19 @@ http {
return 302 https://www.google.com/maps/d/viewer?mid=1pJIYY9cuEdt9DuMTbb4etBVq7hs; return 302 https://www.google.com/maps/d/viewer?mid=1pJIYY9cuEdt9DuMTbb4etBVq7hs;
} }
} }
server {
listen 80;
server_name git.tazj.in;
# Static assets must always hit the root.
location ~ ^/(favicon\.ico|cgit\.(css|png))$ {
proxy_pass http://cgit;
}
# Everything else hits the depot directly.
location / {
proxy_pass http://cgit/cgit.cgi/depot/;
}
}
} }