From ef014a0815313b619f2607ba85f91055d16bb191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 31 Jan 2023 13:35:01 +0100 Subject: [PATCH] Add a Docker-based setup. I can't run Ruby 2.7.x on my machine anymore. Docker was the only solution I found. It may help others getting started to contribute to this website as well. The setup is basically copied from that of `scala-lang.org`, but with an additional setup of Node.js. --- Dockerfile | 16 ++++++++++++++++ README.md | 36 +++++++++++++++++++++++++++++++++--- docker-compose.yml | 11 +++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..80257e71 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM ruby:2.7.5 + +# We need Node.js for the `execjs` gem, used by `_plugins/tokenize.rb` +RUN apt install -y curl +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - +RUN apt install -y nodejs + +RUN gem install bundler:2.3.10 + +WORKDIR /srv/jekyll + +COPY Gemfile . +COPY Gemfile.lock . + +RUN chmod u+s /bin/chown +RUN bundle install diff --git a/README.md b/README.md index 3a286116..ed1e969b 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,35 @@ The key to contributing is being able to edit and preview your content. [Your pull requests are welcome](https://github.com/scala-js/scala-js-website/compare)! ## Set up + +### With Docker + +You need to have [Docker Engine](https://docs.docker.com/engine/) and [Docker Compose](https://docs.docker.com/compose/) installed on your machine. +Under Mac OS (Intel or Apple silicon), instead of installing [Docker Desktop](https://docs.docker.com/desktop/) you can also use [HomeBrew](https://brew.sh/) with [Colima](https://github.com/abiosoft/colima): `brew install colima docker docker-compose`. +UID and GID environment variables are needed to avoid docker from writing files as root in your directory. + +``` +env UID="$(id -u)" GID="$(id -g)" docker-compose up +``` + +On Linux you may have to prefix that command with `sudo`, depending on your Docker setup. + +The generated site is available at `http://localhost:4000`. + +When the website dependencies change (the content of the `Gemfile`), you have to re-build the Docker image: + +``` +env UID="$(id -u)" GID="$(id -g)" docker-compose up --build +``` + +If you have problems with the Docker image or want to force the rebuild of the Docker image: + +``` +env UID="$(id -u)" GID="$(id -g)" docker-compose build --no-cache +``` + +### Manually with Ruby tooling + As this website is built with [Jekyll](http://jekyllrb.com/), we will need to set up some Ruby tooling. @@ -22,7 +51,7 @@ $ rvm use 2.7.5 --install # Set up Bundler, a Ruby package manager # It downloads dependencies specified in a Gemfile -# but into a local path unlike gem +# but into a local path unlike gem $ gem install bundler # and if this fails, try installing libffi first (distro-specific): # sudo apt install libffi-dev @@ -34,8 +63,9 @@ $ bundle install $ bundle exec jekyll build ``` -## Editing live -This is what you would do after initial installation: +#### Editing live + +This is what you would do after the initial installation: ```bash $ bundle exec jekyll serve --watch ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1c0e09b5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '2' + +services: + jekyll: + user: "${UID}:${GID}" + build: . + command: sh -c "chown $UID / && bundle exec jekyll serve --watch --host=0.0.0.0 " + ports: + - '4000:4000' + volumes: + - .:/srv/jekyll