Skip to content

Commit d201cd5

Browse files
sjrdgzm0
authored andcommitted
Add a Docker-based setup.
Based off scala-js#600. 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 inspired by that of `scala-lang.org`, but modified to avoid UID hackery (instead has some volume hackery).
1 parent 7632d04 commit d201cd5

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

.asset-cache/.gitkeep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory is required for the docker volume hackery (see Dockerfile) to work.
2+
3+
https://stackoverflow.com/questions/37883895/can-i-have-a-writable-docker-volume-mounted-under-a-read-only-volume

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM ruby:2.7.5-bullseye
2+
3+
# We need Node.js for the `execjs` gem, used by `_plugins/tokenize.rb`
4+
# Since it is a (sufficiently) standalone binary, we can just copy it from the node image.
5+
# Note that both the ruby and node docker images are based off buildpack-deps so they have
6+
# essentially the same base.
7+
COPY --from=node:18.14-bullseye /usr/local/bin/node /usr/local/bin/node
8+
9+
RUN gem install bundler:2.3.10
10+
11+
WORKDIR /srv/jekyll
12+
13+
COPY Gemfile .
14+
COPY Gemfile.lock .
15+
16+
RUN bundle install
17+
18+
# jekyll serve will listen to port 4000
19+
EXPOSE 4000
20+
21+
# declare volumes for jekyll output
22+
# Unfortunately jekyll 3.x isn't sufficiently configurable to not write to the
23+
# output directory.
24+
#
25+
# The docker-compose file will ro mount the sources to /srv/jekyll,
26+
# and then (implicitly) create anonymous volumes at these locations.
27+
#
28+
# A better approach (for jekyll 4.x) would be to set
29+
# --destination to a different location and also set
30+
# --disable-disk-cache to avoid creating .asset-cache.
31+
VOLUME ["/srv/jekyll/.asset-cache", "/srv/jekyll/_site"]
32+
33+
CMD ["bundle", "exec", "jekyll", "serve", "--watch", "--host=0.0.0.0"]

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ The key to contributing is being able to edit and
1212
preview your content. [Your pull requests are welcome](https://github.com/scala-js/scala-js-website/compare)!
1313

1414
## Set up
15+
16+
### With Docker
17+
18+
You need to have [Docker Engine](https://docs.docker.com/engine/) and [Docker Compose](https://docs.docker.com/compose/) installed on your machine.
19+
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`.
20+
21+
```
22+
docker-compose up --build
23+
```
24+
25+
On Linux you may have to prefix that command with `sudo`, depending on your Docker setup.
26+
27+
The generated site is available at `http://localhost:4000`.
28+
29+
When the website dependencies change (the content of the `Gemfile`), you have to kill and re-run the command.
30+
31+
If you have problems with the Docker image or want to force the rebuild of the Docker image:
32+
33+
```
34+
docker-compose build --no-cache
35+
```
36+
37+
### Manually with Ruby tooling
38+
1539
As this website is built with [Jekyll](http://jekyllrb.com/),
1640
we will need to set up some Ruby tooling.
1741

@@ -22,7 +46,7 @@ $ rvm use 2.7.5 --install
2246

2347
# Set up Bundler, a Ruby package manager
2448
# It downloads dependencies specified in a Gemfile
25-
# but into a local path unlike gem
49+
# but into a local path unlike gem
2650
$ gem install bundler
2751
# and if this fails, try installing libffi first (distro-specific):
2852
# sudo apt install libffi-dev
@@ -34,8 +58,9 @@ $ bundle install
3458
$ bundle exec jekyll build
3559
```
3660

37-
## Editing live
38-
This is what you would do after initial installation:
61+
#### Editing live
62+
63+
This is what you would do after the initial installation:
3964
```bash
4065
$ bundle exec jekyll serve --watch
4166
```

_site/.gitkeep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory is required for the docker volume hackery (see Dockerfile) to work.
2+
3+
https://stackoverflow.com/questions/37883895/can-i-have-a-writable-docker-volume-mounted-under-a-read-only-volume

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2'
2+
3+
services:
4+
jekyll:
5+
build: .
6+
ports:
7+
- '4000:4000'
8+
volumes:
9+
- .:/srv/jekyll:ro

0 commit comments

Comments
 (0)