Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with odd issue! #1

Closed
proteo opened this issue Mar 9, 2020 · 4 comments
Closed

Help with odd issue! #1

proteo opened this issue Mar 9, 2020 · 4 comments

Comments

@proteo
Copy link

proteo commented Mar 9, 2020

Hi. I've spent the last few hours pulling my hair trying to figure out what's going on with my setup and finally gave up, so I thought somebody here could give me a hand.

I'm using the following docker-compose.yml file:

version: '2'

services:
  web:
    container_name: ${DOMAIN_KEY}
    image: nginx
    volumes:
      - ./html:/var/www/html
    labels:
      - 'traefik.enable=true'
      - "traefik.http.routers.${DOMAIN_KEY}-http.rule=Host(`www.${DOMAIN_KEY}.test`)"
      - "traefik.http.routers.${DOMAIN_KEY}-http.entrypoints=http"
    expose:
     - 80
    networks:
      - dockernet

  browsersync:
    container_name: ${DOMAIN_KEY}_bs
    image: demyx/browsersync
    environment:
      BROWSERSYNC_PROXY: http://www.${DOMAIN_KEY}.test
      BROWSERSYNC_DOMAIN_SOCKET: http://bs.${DOMAIN_KEY}.test
      BROWSERSYNC_FILES: "[\"/var/www/html/assets/css/*.css\"]"
      BROWSERSYNC_PORT: 3000
      BROWSERSYNC_PATH: "false"
      BROWSERSYNC_PREFIX: "false"
    volumes_from:
      - web
    expose:
     - 3000
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.${DOMAIN_KEY}-bs.rule=(Host(`bs.${DOMAIN_KEY}.test`))"
      - "traefik.http.routers.${DOMAIN_KEY}-bs.entrypoints=http"
    networks:
      - dockernet

networks:
  dockernet:
    external: true

This gives me two working containers, my web app at http://www.site.test and another with BrowserSync at http://bs.site.test. Everything seems OK with the BrowserSync container, I can see the proxy site and the "BrowserSync: connected" badge at the top of the page when I open it in the browser. But here's the thing: I can't make it reload files automatically when they're changed.

I use two computers for my development work: my workstation is an iMac where all the files are stored. A second computer (a Mac Mini) is running Ubuntu Server, which is where Docker is running. Since the actual code files live in the workstation, everything is mounted as a nfs share from the Ubuntu server. From there, Docker containers load volumes as local directories.

So, whenever I make a change in a file from the remote workstation, the change is propagated to the Ubuntu server, and picked up by the Docker volume. This usually works great and gives me no issues whatsoever. But for some reason, it won't trigger the event that makes BrowserSync to recognize that the file has changed.

Obviously, I first checked for errors in paths, etc. But any change from the workstation is being propagated just fine to the server, as usual. When logged in the Ubuntu server I can see how files are modified as soon as I make a change from the workstation.

Now, the funny thing is that if I manually change a file when logged in the server like this:

mini$ touch /users/proteo/sites/html/assets/css/styles.css

The change is detected perfectly by BrowserSync and http://bs.site.test is updated immediately. I can also make the change inside the BrowserSync container, and it also works flawlessly:

mini$ docker exec -ti site-bs /bin/bash
bash-5.0$ touch /var/www/html/assets/css/styles.css

Hope you can give a hint. Thanks in advance!

@demyxco
Copy link
Collaborator

demyxco commented Mar 9, 2020

Interesting setup you got here, I've made all my images with remote setup in mind. When the BrowserSync container is running can you cat the bs.js file?

docker exec <bs_container> cat /etc/demyx/bs.js

@proteo
Copy link
Author

proteo commented Mar 9, 2020

Thanks for your response. Yes, I can see the contents of the bs.js file:

module.exports={
    ui: false,
    open: false,
    files: ["/var/www/html/assets/css/*.css"],
    proxy: "http://www.site.test",
    port: 3000,
    rewriteRules:[{
        match: /http:\/\/localhost/g,
        fn: function (e,r,t) {
            return "http://localhost"
        }
    }],
    scriptPath: function (path) {
        return "" + path;
    },
    socket: {
        domain: "http://bs.site.test"
    }
};

Actually, the issue may have nothing to do with demyx/browsersync. In the meantime, I've been looking around and found out that NFS doesn't seem to support inotify events, which may explain why everything works when I manually trigger a change from the linux box, but not when the change is triggered from the other end of the nfs share.

I'll update this thread if I can find a way around the problem.

Thanks!

@demyxco
Copy link
Collaborator

demyxco commented Mar 9, 2020

No problem, I will close this for now.

@demyxco demyxco closed this as completed Mar 9, 2020
@proteo
Copy link
Author

proteo commented Mar 10, 2020

Just in case somebody else is having this problem:

Yes, the culprit here is NFS, which doesn't send fsevents to the client so the linux box simply isn't unable to react when a file is changed. I've spent most of the day trying different solutions and so far the easiest and more straightforward is notify-forwarder, which successfully triggers an ATTRIB event on the client side of the NFS share and makes BrowserSync happy again.

You can even setup some sort of automation process in your IDE to make it automagically for you (I did with PhpStorm and a handy bash script).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants