Skip to content

Add a Docker-based setup. #600

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need Node.js as well to build the website?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need it for one the plugins, which calls into JS for some reason. I added a comment.


RUN gem install bundler:2.3.10

WORKDIR /srv/jekyll

COPY Gemfile .
COPY Gemfile.lock .

RUN chmod u+s /bin/chown
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😨 😨

RUN bundle install
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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
```
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing the usual UID hackery, have you considered:

  • read-only mounting the sources
  • configure jekyll's build directory away into the docker overlay FS --destination /tmp/jekyll-site

For fully building the website (to deploy), I suggest docker cp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I have no idea what I'm doing. I have 0 Docker knowledge. I copy-pasted from the setup for scala-lang which is at https://github.com/scala/scala-lang/blob/main/docker-compose.yml
This was apparently copied from docs.scala-lang.org to solve some issue, copying changes in scala/docs.scala-lang#2622

🤷‍♂️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) that's pretty much how this looked 😹

If this is not super urgent, I can make an alternative suggestion (I use docker daily now).

If yes, I'd appreciate a quick description of your deployment process to make sure I'm not making it worse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not urgent at all. I only use it locally. I can keep it local until there's something good.

The deployment is still working Docker-free in GitHub Actions. It's in https://github.com/scala-js/scala-js-website/blob/main/.github/workflows/deploy.yml