From c0bc95c5d965539abe056c1e14ac3432e8bd99d4 Mon Sep 17 00:00:00 2001 From: Amir Pourmand Date: Sat, 7 Oct 2023 10:03:58 +0330 Subject: [PATCH] Add Reload to Docker (Automatic Reload of Changes to _config.yaml) (#1702) - #1640 --- Dockerfile | 7 +++++-- README.md | 6 +++--- bin/docker_build_image.sh | 5 ----- bin/docker_run.sh | 8 -------- bin/dockerhub_run.sh | 8 -------- bin/entry_point.sh | 22 ++++++++++++++++++++++ docker-compose.yml | 1 + docker-local.yml | 10 ---------- 8 files changed, 31 insertions(+), 36 deletions(-) delete mode 100755 bin/docker_build_image.sh delete mode 100755 bin/docker_run.sh delete mode 100755 bin/dockerhub_run.sh create mode 100755 bin/entry_point.sh delete mode 100644 docker-local.yml diff --git a/Dockerfile b/Dockerfile index 96e7294df365..7af3df2e4006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,12 +9,15 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \ ruby-full \ build-essential \ zlib1g-dev \ - jupyter-nbconvert && \ + jupyter-nbconvert \ + inotify-tools procps && \ apt-get clean && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* + RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \ locale-gen + ENV LANG=en_US.UTF-8 \ LANGUAGE=en_US:en \ LC_ALL=en_US.UTF-8 \ @@ -33,4 +36,4 @@ RUN bundle install --no-cache # && rm -rf /var/lib/gems/3.1.0/cache EXPOSE 8080 -CMD ["/bin/bash", "-c", "rm -f Gemfile.lock && exec jekyll serve --watch --port=8080 --host=0.0.0.0 --livereload --verbose --trace"] +CMD ["./bin/entry_point.sh"] diff --git a/README.md b/README.md index d9ed1bc6c114..553694aa1f08 100644 --- a/README.md +++ b/README.md @@ -227,12 +227,12 @@ You need to take the following steps to get `al-folio` up and running on your lo - Finally, run the following command that will pull the latest pre-built image from DockerHub and will run your website. ```bash -$ docker-compose up +$ docker compose up ``` Note that when you run it for the first time, it will download a docker image of size 400MB or so. -Now, feel free to customize the theme however you like (don't forget to change the name!). After you are done, you can use the same command (`docker-compose up`) to render the webpage with all you changes. Also, make sure to commit your final changes. +Now, feel free to customize the theme however you like (don't forget to change the name!). After you are done, you can use the same command (`docker compose up`) to render the webpage with all you changes. Also, make sure to commit your final changes. > To change port number, you can edit `docker-compose.yml` file. @@ -243,7 +243,7 @@ Now, feel free to customize the theme however you like (don't forget to change t Build and run a new docker image using: ```bash -$ docker-compose -f docker-local.yml up +$ docker compose up --build ``` > If you want to update jekyll, install new ruby packages, etc., all you have to do is build the image again using `--force-recreate` argument at the end of previous command! It will download ruby and jekyll and install all ruby packages again from scratch. diff --git a/bin/docker_build_image.sh b/bin/docker_build_image.sh deleted file mode 100755 index fe208afbf7ae..000000000000 --- a/bin/docker_build_image.sh +++ /dev/null @@ -1,5 +0,0 @@ - FILE=Gemfile.lock -if [ -f "$FILE" ]; then - rm $FILE -fi - docker build -t "al-folio:latest" . \ No newline at end of file diff --git a/bin/docker_run.sh b/bin/docker_run.sh deleted file mode 100755 index 9c3d3d8a0abb..000000000000 --- a/bin/docker_run.sh +++ /dev/null @@ -1,8 +0,0 @@ -FILE=Gemfile.lock -if [ -f "$FILE" ]; then - rm $FILE -fi -docker run --rm -v "$PWD:/srv/jekyll/" -p "8080:8080" \ - -it al-folio:latest bundler \ - exec jekyll serve --watch --port=8080 --host=0.0.0.0 \ - --verbose --livereload \ No newline at end of file diff --git a/bin/dockerhub_run.sh b/bin/dockerhub_run.sh deleted file mode 100755 index ac6a14e9ef2f..000000000000 --- a/bin/dockerhub_run.sh +++ /dev/null @@ -1,8 +0,0 @@ -FILE=Gemfile.lock -if [ -f "$FILE" ]; then - rm $FILE -fi -docker run --rm -v "$PWD:/srv/jekyll/" -p "8080:8080" \ - -it amirpourmand/al-folio bundler \ - exec jekyll serve --watch --port=8080 --host=0.0.0.0 \ - --verbose --livereload diff --git a/bin/entry_point.sh b/bin/entry_point.sh new file mode 100755 index 000000000000..917ae3572a6a --- /dev/null +++ b/bin/entry_point.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +CONFIG_FILE=_config.yml + +/bin/bash -c "rm -f Gemfile.lock && exec jekyll serve --watch --port=8080 --host=0.0.0.0 --livereload --verbose --trace --force_polling"& + +while true; do + + inotifywait -q -e modify,move,create,delete $CONFIG_FILE + + if [ $? -eq 0 ]; then + + echo "Change detected to $CONFIG_FILE, restarting Jekyll" + + jekyll_pid=$(pgrep -f jekyll) + kill -KILL $jekyll_pid + + /bin/bash -c "rm -f Gemfile.lock && exec jekyll serve --watch --port=8080 --host=0.0.0.0 --livereload --verbose --trace --force_polling"& + + fi + +done diff --git a/docker-compose.yml b/docker-compose.yml index 8671a4dc9eaa..7ec8ec5478db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,6 +3,7 @@ version: "3" services: jekyll: image: amirpourmand/al-folio + build: . ports: - 8080:8080 volumes: diff --git a/docker-local.yml b/docker-local.yml deleted file mode 100644 index 87826f4c2a75..000000000000 --- a/docker-local.yml +++ /dev/null @@ -1,10 +0,0 @@ -version: "3" - -services: - jekyll_custom: - build: . - image: al-folio-local-docker - ports: - - 8080:8080 - volumes: - - .:/srv/jekyll