Giter Club home page Giter Club logo

Comments (2)

thockin avatar thockin commented on August 19, 2024

I am not an nginx expert, but I also struggled with this. The default nginx content dir (/usr/share/nginx/html) is expected to hold data. There is no flag to nginx (AFAICT) to change that - I think you have to replace the whole config file, which means either mounting it in as a volume or building a custom image based on nginx.

from git-sync.

thockin avatar thockin commented on August 19, 2024

A little more detail.

If you git-sync into /usr/share/nginx/html, you end up with data at /usr/share/nginx/html/<link>/http1/http1.2/index.html - not useful.

If you git-sync into /usr/share/nginx/ with html as the link name, you end up with data at /usr/share/nginx/html/http1/http1.2/index.html - still not useful.

If you use Kubernetes and subPath=<link> on the volume mount, then you race* (and almost always lose) - not useful. Also, at best you end up with data at /usr/share/nginx/html/http1/http1.2/index.html - still not useful.

If you use Kubernetes and subPath=<link>/http1/http1.2 on the volume mount, then you race* (and almost always lose) - not useful. Even if you win, you don't get any sync updates because of how linux works with bind mounts and symlinks.

I did find a way - the proverbial "another level of indirection. I am pasting a kubernete deployment yaml below.

  • the race: Kubernetes sees it as emptyDir - in order to bind mount a sub-path, that path has to exist. Container runtimes will mkdir the path if it isn't found, which gives nginx an empty directory and causes git-sync to fail to publish the link.
# 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

from git-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.