Skip to content

Commit e48b8c9

Browse files
defunctzombiedomenic
authored andcommitted
Allow using Docker to build
Closes whatwg#55. Supercedes whatwg/html#612.
1 parent bb72c20 commit e48b8c9

File tree

5 files changed

+140
-24
lines changed

5 files changed

+140
-24
lines changed

Diff for: .dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git/
2+
.cache/
3+
.temp/
4+
output/
5+
html/.git/

Diff for: Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM debian:sid
2+
3+
## dependency installation: apache, wattsi, and other build tools
4+
## enable some apache mods (the ln -s lines)
5+
## cleanup freepascal since it is no longer needed after wattsi build
6+
RUN apt-get update && \
7+
apt-get install -y ca-certificates curl git unzip fp-compiler-3.0.0 apache2 && \
8+
cd /etc/apache2/mods-enabled && \
9+
ln -s ../mods-available/headers.load && \
10+
ln -s ../mods-available/expires.load && \
11+
git clone https://github.com/whatwg/wattsi.git /whatwg/wattsi && \
12+
cd /whatwg/wattsi && \
13+
/whatwg/wattsi/build.sh && \
14+
cp /whatwg/wattsi/bin/wattsi /bin/ && \
15+
apt-get purge -y fp-compiler-3.0.0 && \
16+
apt-get autoremove -y && \
17+
rm -rf /var/lib/apt/lists/*
18+
19+
ADD . /whatwg/build
20+
21+
ARG html_source_dir
22+
ADD $html_source_dir /whatwg/html
23+
ENV HTML_SOURCE /whatwg/html
24+
25+
WORKDIR /whatwg/build
26+
27+
## build and copy assets to final apache dir
28+
29+
ARG verbose_or_quiet_flag
30+
ARG no_update_flag
31+
32+
# no_update_flag doesn't really work; .cache directory is re-created empty each time
33+
RUN SKIP_BUILD_UPDATE_CHECK=true ./build.sh $verbose_or_quiet_flag $no_update_flag && \
34+
rm -rf /var/www/html && \
35+
mv output /var/www/html && \
36+
chmod -R o+rX /var/www/html && \
37+
cp site.conf /etc/apache2/sites-available/000-default.conf
38+
39+
CMD ["apache2ctl", "-DFOREGROUND"]

Diff for: README.md

+47-22
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,39 @@
22

33
This repository contains the tools and instructions necessary for building the [HTML Standard](https://html.spec.whatwg.org/multipage/) from its [source](https://github.com/whatwg/html).
44

5-
## Prerequisites
5+
## Getting set up
66

7-
Before building, make sure you have the following commands installed on your system.
7+
Make sure you have `git` installed on your system, and you are using a Bash shell. (On Windows, `cmd.exe` will not work, but the Git Bash shell that comes with [Git for Windows](https://git-for-windows.github.io/) works nicely.)
88

9-
- `curl`, `git`, `grep`, `perl`, `unzip`
9+
Then, clone this ([html-build](https://github.com/whatwg/html-build)) repo:
1010

11-
Optionally, for faster builds, you can install [Wattsi](https://github.com/whatwg/wattsi) on your system. If you don't bother with that, the build will use [Wattsi Server](https://github.com/domenic/wattsi-server).
11+
```
12+
git clone https://github.com/whatwg/html-build.git && cd html-build
13+
```
14+
15+
You then have a decision to make as to how you want to do your builds: locally, on your computer, or using a [Docker](https://www.docker.com/) container. We suggest going the Docker route if and only if you are already comfortable with Docker.
1216

13-
## Build
17+
## Building locally
1418

15-
Building your own copy of the HTML Standard from its source requires just these simple steps:
19+
### Prerequisites
1620

17-
1. If you want to submit a pull request to the [whatwg/html](https://github.com/whatwg/html) repo, fork it and clone your fork. (If not, you can skip this step.)
18-
```
19-
git clone https://github.com/<username>/html.git
20-
```
21+
To build locally, you'll need the following commands installed on your system:
2122

22-
1. Clone this ([html-build](https://github.com/whatwg/html-build)) repo:
23-
```
24-
git clone https://github.com/whatwg/html-build.git && cd html-build
25-
```
23+
- `curl`, `grep`, `perl`, `unzip`
2624

27-
1. Run the `build.sh` script from inside your `html-build` working directory, like this:
28-
```
29-
./build.sh
30-
```
25+
Optionally, for faster builds, you can install [Wattsi](https://github.com/whatwg/wattsi). If you don't bother with that, the build will use [Wattsi Server](https://github.com/domenic/wattsi-server), which requires an internet connection.
3126

32-
## Output
27+
### Running the build
28+
29+
Run the `build.sh` script from inside your `html-build` working directory, like this:
30+
31+
```
32+
./build.sh
33+
```
34+
35+
The first time this runs, it will ask for your input on where to clone the HTML source from, or where on your system to find it if you've already done that. If you're working to submit a pull request to [whatwg/html](https://github.com/whatwg/html), be sure to give it the URL of your fork.
36+
37+
### Output
3338

3439
After you complete the build steps above, the build will run and generate the single-page version of the spec, the multipage version, and more. If all goes well, you should very soon have all the following in your `output/` directory:
3540

@@ -42,16 +47,36 @@ After you complete the build steps above, the build will run and generate the si
4247
- `link-fixup.js`
4348
- `multipage/*`
4449

45-
And then you're also ready to edit the `html/source` file—and after you make your changes, you can run the `build.sh` script again to see the new output.
50+
Now you're ready to edit the `html/source` file—and after you make your changes, you can run the `build.sh` script again to see the new output.
51+
52+
## Building using a Docker container
53+
54+
The Dockerized version of the build allows you to run the build entirely inside a "container" (lightweight virtual machine). This includes tricky dependencies like a local copy of Wattsi, as well as the Apache HTTP server with a setup analogous to that of https://html.spec.whatwg.org.
4655

47-
## Options
56+
To perform a Dockerized build, use the `--docker` flag:
57+
58+
```
59+
./build.sh --docker
60+
```
61+
62+
The first time you do this, Docker will download a bunch of stuff to set up the container properly, but subsequent runs will simply build the standard and be very fast.
63+
64+
After building the standard, this will launch a HTTP server that allows you to view the result at `http://localhost:8080`. (OS X and Windows users will need to use the IP address of their docker-machine VM instead of `localhost`. You can get this with the `docker-machine env` command.)
65+
66+
Note that due to the way Docker works, the HTML source repository must be contained in a subdirectory of the `html-build` working directory. This will happen automatically if you let `build.sh` clone for you, but if you have a preexisting clone you'll need to move it.
67+
68+
## A note on Git history
69+
70+
Your clone doesn't need the HTML standard's complete revision history just for you to build the spec and contribute patches. So, if you use `build.sh` to create the clone, we don't start you out with a clone of the history. That makes your first build finish much faster. And if later you decide you do want to clone the complete history, you can still get it, by doing this:
4871

49-
Your clone doesn't need the HTML standard's complete revision history just for you to build the spec and contribute patches. So, by default we don't start you out with a clone of the history. That makes your first build finish much faster. And if later you decide you do want to clone the complete history, you can still get it, by doing this:
5072
```
5173
cd ./html && git fetch --unshallow
5274
```
75+
5376
That said, if you really do want to *start out* with the complete history of the repo, then run the build script for the first time like this:
77+
5478
```
5579
HTML_GIT_CLONE_OPTIONS="" ./build.sh
5680
```
81+
5782
That will clone the complete history for you. But be warned: It'll make your first build take *dramatically* longer to finish!

Diff for: build.sh

+36-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cd "$( dirname "${BASH_SOURCE[0]}" )"
77
DIR=$(pwd)
88

99
DO_UPDATE=true
10+
USE_DOCKER=false
1011
VERBOSE=false
1112
QUIET=false
1213
export DO_UPDATE
@@ -32,18 +33,23 @@ do
3233
-h|--help)
3334
echo "Usage: $0 [-c|--clean]"
3435
echo " $0 [-h|--help]"
35-
echo "Usage: $0 [-n|--no-update] [-q|--quiet] [-v|--verbose]"
36+
echo " $0 [-d|--docker]"
37+
echo " $0 [-n|--no-update] [-q|--quiet] [-v|--verbose]"
3638
echo
3739
echo " -c|--clean Remove downloaded dependencies and generated files (then stop)."
3840
echo " -h|--help Show this usage statement."
3941
echo " -n|--no-update Don't update before building; just build."
42+
echo " -d|--docker Use Docker to build in and serve from a container."
4043
echo " -q|--quiet Don't emit any messages except errors/warnings."
4144
echo " -v|--verbose Show verbose output from every build step."
4245
exit 0
4346
;;
4447
-n|--no-update|--no-updates)
4548
DO_UPDATE=false
4649
;;
50+
-d|--docker)
51+
USE_DOCKER=true
52+
;;
4753
-q|--quiet)
4854
QUIET=true
4955
VERBOSE=false
@@ -58,7 +64,9 @@ do
5864
esac
5965
done
6066

61-
if [ "$DO_UPDATE" == true ]; then
67+
# $SKIP_BUILD_UPDATE_CHECK is set inside the Dockerfile so that we don't check for updates both inside and outside
68+
# the Docker container.
69+
if [ "$DO_UPDATE" == true -a "$SKIP_BUILD_UPDATE_CHECK" != true ]; then
6270
$QUIET || echo "Checking if html-build is up to date..."
6371
# TODO: `git remote get-url origin` is nicer, but new in Git 2.7.
6472
ORIGIN_URL=$(git config --get remote.origin.url)
@@ -200,6 +208,32 @@ else
200208
fi
201209
export HTML_SOURCE
202210

211+
if [ "$USE_DOCKER" == true ]; then
212+
if [[ "$HTML_SOURCE" != $(pwd)/* ]]; then
213+
echo "When using Docker, the HTML source must be checked out in a subdirectory of the html-build repo. Cannot continue."
214+
exit 1
215+
fi
216+
217+
# $SOURCE_RELATIVE helps on Windows with Git Bash, where /c/... is a symlink, which Docker doesn't like.
218+
SOURCE_RELATIVE=$(realpath --relative-to=. $HTML_SOURCE)
219+
220+
VERBOSE_OR_QUIET_FLAG=""
221+
$QUIET && VERBOSE_OR_QUIET_FLAG+="--quiet"
222+
$VERBOSE && VERBOSE_OR_QUIET_FLAG+="--verbose"
223+
224+
NO_UPDATE_FLAG="--no-update"
225+
$DO_UPDATE && NO_UPDATE_FLAG=""
226+
227+
docker build --tag whatwg-html \
228+
--build-arg html_source_dir=$SOURCE_RELATIVE \
229+
--build-arg verbose_or_quiet_flag=$VERBOSE_OR_QUIET_FLAG \
230+
--build-arg no_update_flag=$NO_UPDATE_FLAG \
231+
$($QUIET && echo "--quiet") .
232+
docker run --rm -it -p 8080:80 whatwg-html
233+
exit 0
234+
fi
235+
236+
203237
$QUIET || echo "Linting the source file..."
204238
./lint.sh $HTML_SOURCE/source || {
205239
echo

Diff for: site.conf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /var/www/html
3+
4+
<Directory "/var/www/html">
5+
Options Indexes FollowSymLinks
6+
AllowOverride All
7+
Require all granted
8+
</Directory>
9+
10+
ErrorLog ${APACHE_LOG_DIR}/error.log
11+
</VirtualHost>
12+
13+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

0 commit comments

Comments
 (0)