Skip to content

Commit fc3e2a3

Browse files
committed
Improve container configuration and documentation
1 parent 5ce6f4b commit fc3e2a3

File tree

5 files changed

+84
-35
lines changed

5 files changed

+84
-35
lines changed

.devcontainer/Dockerfile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ FROM erlang:27
22

33
ENV DEBIAN_FRONTEND=noninteractive
44

5+
# Create a default user for the devcontainer
6+
RUN useradd -ms /bin/bash builder
7+
58
# Install dependencies
69
RUN apt-get update && apt-get install -y \
710
git \
@@ -16,24 +19,32 @@ RUN apt-get update && apt-get install -y \
1619
ruby \
1720
ruby-dev \
1821
asciidoctor \
22+
default-jre \
23+
graphviz \
1924
&& apt-get clean
2025

26+
# Additional Ruby packages
27+
RUN gem install asciidoctor-pdf asciidoctor-diagram rouge
28+
2129
# Install rebar3
2230
RUN git clone https://github.com/erlang/rebar3.git && \
2331
cd rebar3 && \
2432
./bootstrap && \
2533
./rebar3 local install
2634

27-
# Set environment variable for Erlang shell history
28-
ENV ERL_AFLAGS "-kernel shell_history enabled"
35+
# Set Erlang flags for unicode text and shell history
36+
ENV ERL_AFLAGS "+pc unicode -kernel shell_history enabled"
2937

3038
# Initialize PostgreSQL database for examples
3139
USER postgres
3240
RUN /etc/init.d/postgresql start && \
3341
psql --command "CREATE USER myuser WITH SUPERUSER PASSWORD 'mypassword';" && \
3442
createdb -O myuser mydb
3543

36-
USER root
44+
USER builder
45+
46+
# stop git from complaining
47+
RUN git config --global --add safe.directory /workspaces/theBeamBook
3748

3849
# Set the default command to start PostgreSQL and keep the container running
39-
CMD service postgresql start && tail -f /var/lib/postgresql/data/logfile
50+
CMD service postgresql start && tail -f /var/lib/postgresql/data/logfile

.devcontainer/devcontainer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
"ms-vscode.cpptools-extension-pack",
1717
"ms-vscode.cpptools-themes",
1818
"ms-vscode.makefile-tools",
19-
"pgourlain.erlang",
20-
"rebornix.ruby",
19+
"erlang-language-platform.erlang-language-platform",
2120
"twxs.cmake",
22-
"wingrunr21.vscode-ruby",
21+
"editorconfig.editorconfig",
22+
"Shopify.ruby-lsp"
2323
]
2424
},
2525
"settings": {
2626
"terminal.integrated.shell.linux": "/bin/bash"
2727
}
28-
},
29-
"postCreateCommand": ". /workspace/venv/bin/activate && pip install -r requirements.txt"
28+
}
3029
}

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
ASSET_CHAPTERS = $(shell find chapters -type f)
22

3-
.PHONY: docker
3+
.PHONY: all pdf html docker docker-build clean serve
44

5-
all: chapters/contributors.txt beam-book.pdf index.html
5+
all: pdf html
6+
7+
pdf: beam-book.pdf
68

79
chapters/contributors.txt: .git
810
git --no-pager log | git --no-pager shortlog -s -n | awk '{$$1=""}1' | grep -v "Your Name" > $@
911

1012
beam-book.pdf: chapters/opcodes_doc.asciidoc book.asciidoc chapters/contributors.txt $(ASSET_CHAPTERS)
1113
asciidoctor-pdf -r ./style/custom-pdf-converter.rb -r asciidoctor-diagram -r ./style/custom-admonition-block.rb -a config=./style/ditaa.cfg --doctype=book -a pdf-style=./style/pdf-theme.yml book.asciidoc -o $@
1214

13-
index.html: $(ASSET_CHAPTERS)
15+
html: chapters/contributors.txt $(ASSET_CHAPTERS)
1416
cp -r images site
1517
asciidoctor -r asciidoctor-diagram -r ./style/custom-admonition-block.rb -a config=style/ditaa.cfg --backend=html5 --doctype=book -o site/index.html book.asciidoc --trace
1618
rsync -R code/*/*.png site
@@ -27,8 +29,8 @@ genop.tab:
2729

2830
clean:
2931
find site -type f -name '.[^gitignore]*' -delete
30-
rm -rfv beam-book.pdf site/index.html site/*.png site/*.md5 xml/*.png xml/*.md5 xml/beam-book-from-ab.xml ./images/diag-*.png site/code/*/*.png site/images/*
31-
rmdir site/code/* site/images site/code
32+
rm -f beam-book.pdf site/index.html site/*.png site/*.md5 xml/*.png xml/*.md5 xml/beam-book-from-ab.xml images/diag-*.png
33+
rm -rf site/code site/images .asciidoctor site/.asciidoctor
3234

3335
serve: all
3436
cd site && python3 -m http.server

README.md

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,29 +136,73 @@ an issue declaring what you intend to do.
136136

137137
## Building the PDF locally from source
138138

139-
The project contains a makefile which
139+
The project contains a Makefile which
140140
will let you build your own PDF from the source, provided
141-
that you have all the needed tools installed.
141+
that you have all the needed tools installed. Just running
142+
the command
143+
```shell
144+
make
145+
```
146+
will build the file `beam-book.pdf` in the top directory
147+
as well as the HTML version under the `site` directory.
148+
149+
We assume that you already have an Erlang installation of
150+
your choice for running examples etc. Apart from that, see
151+
below for what you need in order to build the book.
142152

143153
### Docker
144154

145-
You can build the project locally using docker by first building the docker image
146-
```
155+
You can build the project locally via Docker without having to
156+
install any addtional software, by first building the docker
157+
image. Assuming you have Docker installed, run:
158+
```shell
147159
make docker-build
148160
```
149-
And then building the project by
150-
```
161+
And then you can build the book by running
162+
```shell
151163
make docker
152164
```
165+
(Note: On Linux, the resulting files will be created with
166+
User ID 1000, regardless of what your current user ID is
167+
outside Docker. This is due to how Docker integrates with
168+
the file system.)
169+
170+
#### Devcontainers in the IDE
171+
172+
If you use VSCode or any other editor that has support for
173+
Devcontainers, this repository contains a configuration that
174+
can be used out of the box. By opening the project in the dev
175+
container, you get a shell inside the container with all the
176+
tools pre-installed and with access to the project files so
177+
that all you need to do is run `make`.
178+
179+
For a tutorial on devcontainers, see
180+
[Introduction to Dev Containers](https://happihacking.com/blog/posts/2023/dev-containers/),
181+
[Decvontainer setup](https://happihacking.com/blog/posts/2023/dev-containers-emacs/),
182+
and [Devcontainers, UIDs and file permissions](https://happihacking.com/blog/posts/2024/dev-containers-uids/).
183+
184+
If you prefer to build natively rather than use Docker,
185+
see the following sections depending on your system.
153186

154187
### Linux
155-
WIP, to be updated
156-
```shell
157-
make
158-
```
188+
189+
The following should work on a Debian based system, such as Ubuntu:
190+
1. `apt install git rsync wget curl make`
191+
1. `apt install ruby ruby-dev default-jre`
192+
1. `apt install asciidoctor graphviz`
193+
1. `gem install asciidoctor-pdf asciidoctor-diagram rouge`
194+
1. `make`
159195

160196
### Mac OSX
161197

198+
#### Using Homebrew
199+
200+
1. `brew install asciidoctor graphviz wget ditaa`
201+
1. `gem install asciidoctor-pdf asciidoctor-diagram rouge`
202+
1. `make`
203+
204+
#### Manual installation
205+
162206
1. Install [asciidoc](https://github.com/asciidoctor/asciidoctor)
163207
1. Install [asciidoctor-pdf](https://github.com/asciidoctor/asciidoctor-pdf)
164208
1. Install [asciidoctor-diagram](http://asciidoctor.org/docs/asciidoctor-diagram/)
@@ -168,17 +212,6 @@ make
168212
1. Install [wget](https://www.gnu.org/software/wget/)
169213
1. `make`
170214

171-
### Mac OSX (using brew etc)
172-
173-
1. `brew install asciidoctor`
174-
1. `gem install asciidoctor-pdf`
175-
1. `gem install asciidoctor-diagram`
176-
1. `brew install ditaa`
177-
1. `brew install graphviz`
178-
1. `gem install rouge`
179-
1. `brew install wget`
180-
1. `make`
181-
182215
## License
183216

184217
_The Erlang Runtime System_ by Erik Stenman is licensed under a

docker/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
FROM asciidoctor/docker-asciidoctor:latest
22

3+
# Create a default user instead of root
4+
RUN adduser --disabled-password --shell /bin/bash builder
5+
36
RUN apk add --no-cache\
47
git\
58
rsync\
69
erlang
710

11+
USER builder
812
RUN git config --global --add safe.directory /documents
913
WORKDIR /documents
1014
CMD ["make"]

0 commit comments

Comments
 (0)