From c3586aa8bacb9f2b882c81c938e4c89ad3d95675 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 20 Dec 2019 18:42:56 +0000 Subject: [PATCH] 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! --- infra/kubernetes/cgit/config.yaml | 3 +-- infra/kubernetes/https-lb/ingress.yaml | 19 +++++++++++-------- infra/kubernetes/nginx/nginx.conf | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/infra/kubernetes/cgit/config.yaml b/infra/kubernetes/cgit/config.yaml index 577a56650..e48544d50 100644 --- a/infra/kubernetes/cgit/config.yaml +++ b/infra/kubernetes/cgit/config.yaml @@ -65,10 +65,9 @@ kind: Service metadata: name: cgit spec: - type: NodePort selector: app: cgit ports: - protocol: TCP - port: 2448 # cgit + port: 80 targetPort: 8080 diff --git a/infra/kubernetes/https-lb/ingress.yaml b/infra/kubernetes/https-lb/ingress.yaml index 0a3092da2..069771a42 100644 --- a/infra/kubernetes/https-lb/ingress.yaml +++ b/infra/kubernetes/https-lb/ingress.yaml @@ -8,20 +8,23 @@ metadata: annotations: networking.gke.io/managed-certificates: tazj-in, git-tazj-in, www-tazj-in, oslo-pub spec: - # Default traffic is routed to the blog, in case people go to - # peculiar hostnames. - backend: - serviceName: tazblog - servicePort: 8000 rules: + # Route blog to the blog ... + - host: tazj.in + http: + paths: + - path: /* + backend: + serviceName: tazblog + servicePort: 8000 # Route git.tazj.in to the cgit pods - host: git.tazj.in http: paths: - - path: / + - path: /* backend: - serviceName: cgit - servicePort: 2448 + serviceName: nginx + servicePort: 6756 # Route oslo.pub to the nginx instance which serves redirects - host: oslo.pub http: diff --git a/infra/kubernetes/nginx/nginx.conf b/infra/kubernetes/nginx/nginx.conf index ead5c4061..918aa6067 100644 --- a/infra/kubernetes/nginx/nginx.conf +++ b/infra/kubernetes/nginx/nginx.conf @@ -41,4 +41,19 @@ http { 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/; + } + } }