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

mkdocs 1.2.x livereload no longer working #2457

Closed
GordonMcKinney opened this issue Jun 13, 2021 · 15 comments · Fixed by #2477
Closed

mkdocs 1.2.x livereload no longer working #2457

GordonMcKinney opened this issue Jun 13, 2021 · 15 comments · Fixed by #2477

Comments

@GordonMcKinney
Copy link

mkdocs==1.2 and latest no longer works
mkdocs==1.1.2 works

MacOS 11.4
Docker version 20.10.7, build f0df350
python:3.8-alpine (3.9.5 and 10-rc same behavior)

I checked the Docker container and the markdown is updating but the generated html is not. This seems to be associated with the 1.2 change with watcher.

LMK what logs/config/diag I can provide to help RCA the issue.

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Jun 13, 2021

Ah, I recently experienced issues with watchdog + Docker/Kubernetes setups. Basically the observer based on inotify is a bit limited on Docker setups, I did not dig deep into it but it seems the inotify events on directories within a volume are only available to one container. I solved it by using the observer that polls the file system instead. Do you happen to have your docs files in a volume mounted on several containers?

@GordonMcKinney
Copy link
Author

We mount our source docs to /tmp in the container. We do have several containers that run this way but we observed the issue in a singleton environment (compose down, prune, and a single compose up).

Happy to help troubleshoot. LMK.

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Jun 13, 2021

Could you try to add "dependencies" (not sure if this is the right term) to your docker-compose configuration so as to make sure the container running MkDocs starts last, and tell us if livereload still does not work?

@GordonMcKinney
Copy link
Author

I understand now. The docker compose has a single container only.

In summary, I see the markdown update but not the HTML file change when observed inside the container with docker exec -it /bin/sh

I tested with mkdoc -v serve and saw no output after a change.

@squidfunk
Copy link
Sponsor Contributor

Users of Material for MkDocs are also reporting this new behavior, i.e. mkdocs serve not working properly. It would be great if we could somehow ensure that it also works from within Docker, because many users use the Docker image for previewing.

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Jun 14, 2021

A quick test would be to patch https://github.com/mkdocs/mkdocs/blob/master/mkdocs/livereload/__init__.py#L65 to use PollingObserver instead of Observer to see if it fixes the issue.

from watchdog.observers.polling import PollingObserver

@ultrabug
Copy link
Member

@oprypin hi, what's your point of view on this please mate?

@imolavirus
Copy link

A quick test would be to patch https://github.com/mkdocs/mkdocs/blob/master/mkdocs/livereload/__init__.py#L65 to use PollingObserver instead of Observer to see if it fixes the issue.

from watchdog.observers.polling import PollingObserver

I'm using docker compose with a single container and this patch fixed the issue for me.

@oprypin
Copy link
Contributor

oprypin commented Jun 15, 2021

Does reproducing this issue require running MkDocs in Docker on Mac? Or are there perhaps other conditions to this?

I don't know how to reproduce it, because just running in Docker on Linux works.

@imolavirus
Copy link

I saw the issue when running Docker on Windows, with the docs files mounted from the Windows file system.

However, using Docker on WSL2 with the docs files mounted from the Linux file system, I'm not able to reproduce the issue.

@stevejr
Copy link

stevejr commented Jun 16, 2021

I am running Docker on Mac and see this issue too. Some initial logs:

INFO - Documentation built in 51.21 seconds DEBUG - [13:26:54] Watching directory '/docs/docs' DEBUG - [13:26:54] Watching file '/docs/mkdocs.yml' through directory '/docs' INFO - [13:26:54] Serving on http://0.0.0.0:8000/ DEBUG - [13:26:56] "GET /livereload/47543439/47625824 HTTP/1.1" code 200

We run the docker container as follows:

docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest

The Dockerfile CMD is CMD ["serve", "-v", "--dev-addr=0.0.0.0:8000"]

These are the dependencies we use when building the image:

mkdocs==1.2.1
Pygments>=2.4 
markdown>=3.2 
pymdown-extensions>=7.0 
mkdocs-material-extensions>=1.0
mkdocs-git-revision-date-localized-plugin>=0.7.3 
mkdocs-material>=7.1.8

stevejr added a commit to lensapp/lens that referenced this issue Jun 16, 2021
- Re-enable strict mode in the verify docs command now that the latest version of mkdocs-material is available and supports the new Google Analytics layout
- Amend mkdocs config to use the new Google Analytics layout
- Bump to use latest 1.2 version of mkdocs

Note - current issue mkdocs/mkdocs#2457 stops live reload from work in mkdocs 1.2 so developers will need to amend the mkdocs.yml
to pin mkdocs to version 1.1.2

Signed-off-by: Steve Richards <srichards@mirantis.com>
stevejr added a commit to lensapp/lens that referenced this issue Jun 16, 2021
…#3073)

- Re-enable strict mode in the verify docs command now that the latest version of mkdocs-material is available and supports the new Google Analytics layout
- Amend mkdocs config to use the new Google Analytics layout
- Bump to use latest 1.2 version of mkdocs

Note - current issue mkdocs/mkdocs#2457 stops live reload from work in mkdocs 1.2 so developers will need to amend the mkdocs.yml
to pin mkdocs to version 1.1.2

Signed-off-by: Steve Richards <srichards@mirantis.com>
@oprypin
Copy link
Contributor

oprypin commented Jun 27, 2021

I have a proposed fix in #2477.
I did not figure out any hybrid approach that would let us still benefit from the fast implementation in most cases.

Please try it and let me know if something's wrong.

pip install git+https://github.com/mkdocs/mkdocs.git@refs/pull/2477/head

@GordonMcKinney
Copy link
Author

@oprypin, I can confirm git+https://github.com/mkdocs/mkdocs.git@refs/pull/2477/head fixes the issue in docker compose on MacOS.

@oprypin
Copy link
Contributor

oprypin commented Jul 18, 2021

The fix is now included in the latest release.

n2ygk added a commit to n2ygk/mkdocs-techdocs-core that referenced this issue Jul 19, 2021
@samuelcolvin
Copy link
Contributor

Time for mkdocs to move to watchfiles ? 👀

(Admission: watchfiles is me)

@mkdocs mkdocs locked as resolved and limited conversation to collaborators Nov 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants