-
Notifications
You must be signed in to change notification settings - Fork 419
git‐sync with nginx, where content is NOT the root of the repo
Tim Hockin edited this page Jul 5, 2024
·
1 revision
Git-sync is great for use-cases like serving content from git. Nginx is a great little web server. But sometimes your content is not at the root of the git repo, which trips up nginx. The demo app in this git repo is an example of this.
This is a trivial example of using another level of indirection to make things work. In truth, a non-trivial user would probably be willing to carry a custom nginx.conf, which makes this a little simpler. But as a demo, the below Kubernetes deployment works!
# This demonstrates a nearly-trivial nginx server publishing content from a
# subdir of a git repo.
apiVersion: apps/v1
kind: Deployment
metadata:
name: git-content-server
spec:
replicas: 1
selector:
matchLabels:
app: git-content-server
template:
metadata:
labels:
app: git-content-server
spec:
volumes:
- name: git # git-sync will write here
emptyDir: {}
- name: nginx # the "linker" container will write here
emptyDir: {}
containers:
# This container syncs from a git repo into the git volume.
- name: git-sync
image: registry.k8s.io/git-sync/git-sync:v4.2.4
args:
- --repo=https://github.com/kubernetes/git-sync
- --root=/git
- --period=60s
- --link=head
- --max-failures=1000000000
- -v=2
volumeMounts:
- mountPath: /git
name: git
# This container creates a symlink in the nginx volume, pointing to the
# content in a subdir of the git volume. This is needed to use the
# default nginx config, which assumes data is in /usr/share/nginx/html.
- name: linker
image: alpine
args:
- sh
- -c
- "ln -s /git/head/demo/html /usr/share/nginx/html; ls -l /usr/share/nginx/html; sleep inf;"
volumeMounts:
- mountPath: /usr/share/nginx
name: nginx
# This container serves content from the nginx volume, which follows the
# symlink to the git volume. This avoids having to carry a custom nginx
# config, but a non-trivial user would probably have to do that anyway.
- name: http
image: nginx
volumeMounts:
- mountPath: /git
name: git
readOnly: true
- mountPath: /usr/share/nginx
name: nginx
readOnly: true