Skip to content

Commit

Permalink
Re-do CI build
Browse files Browse the repository at this point in the history
Per the plan in whatwg/meta#173 (comment), this revamps the CI build to reduce coupling between the html-build and html repositories. Now, running CI (currently Travis) for the html-build repository produces a whatwg/html-build Docker container, pushed to Docker Hub, which can be given an input directory containing the contents of whatwg/html, and an output directory.

This will require corresponding changes on the whatwg/html side to make use of this new architecture.
  • Loading branch information
domenic committed Sep 24, 2020
1 parent 6233161 commit 2b140ed
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 181 deletions.
20 changes: 16 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ services:
- docker

script:
# Shellcheck
- shellcheck *.sh
- shellcheck ci-deploy/*.sh
- cd .. &&
git clone https://github.com/whatwg/html.git --depth 2 &&
IS_TEST_OF_HTML_BUILD_ITSELF=true bash ./html-build/ci-deploy/outside-container.sh
- shellcheck ci-build/*.sh

# Build the Docker container, tagged as whatwg/html-build
- bash ci-build/docker-build.sh

# Test the Docker container
- git clone https://github.com/whatwg/html.git --depth 2
- mkdir output
- bash ci-build/docker-run.sh html output

# Tag and publish the Docker container
- docker tag whatwg/html-build "whatwg/html-build:$(git rev-list --count HEAD)"
- docker tag whatwg/html-build whatwg/html-build:latest
- if [[ "$TRAVIS_PULL_REQUEST" = "false" ]]; then docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD"; fi
- if [[ "$TRAVIS_PULL_REQUEST" = "false" ]]; then docker push whatwg/html-build; fi

branches:
only:
Expand Down
14 changes: 1 addition & 13 deletions ci-deploy/Dockerfile → ci-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ RUN apt-get install --yes --no-install-recommends ./prince_13.5-1_debian10_amd64
rm prince_13.5-1_debian10_amd64.deb && \
echo '@font-face { font-family: serif; src: local("Symbola") }' >> /usr/lib/prince/style/fonts.css

ARG html_build_dir
ADD . /whatwg/html-build

# Note: we do not ADD /whatwg/html, but instead mount it in outside-container.html, since it
# contains the deploy_key, and thus should not be part of the image. The image is cached, publicly,
# on Docker Hub.
ENV HTML_SOURCE /whatwg/html

ARG travis_pull_request
ARG is_test_of_html_build_itself
ENV TRAVIS_PULL_REQUEST=${travis_pull_request}
ENV IS_TEST_OF_HTML_BUILD_ITSELF=${is_test_of_html_build_itself}

ENV SKIP_BUILD_UPDATE_CHECK=true
ENTRYPOINT ["bash", "/whatwg/html-build/ci-deploy/inside-container.sh"]
ENTRYPOINT ["bash", "/whatwg/html-build/ci-build/inside-container.sh"]
10 changes: 10 additions & 0 deletions ci-build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# HTML Standard CI Build

This directory contains the infrastructure for building and running a Docker container, [whatwg/html-build](https://hub.docker.com/r/whatwg/html-build), which performs a "full" build of the HTML Standard, producing artifacts ready for deployment.

The relevant entrypoints are:

- `docker-build.sh` will build the Docker container
- `docker-run.sh $INPUT $OUTPUT` will run the Docker container to do such a full build.
- `$INPUT` should contain the contents of the [whatwg/html](https://github.com/whatwg/html) repository
- `$OUTPUT` should be an empty directory
33 changes: 33 additions & 0 deletions ci-build/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s extglob

TMP_DIR=$(mktemp -d)

function main {
local here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cp "$here/Dockerfile" "$TMP_DIR"
cd "$here/.."
cp -r !(.*|html|output|Dockerfile) "$TMP_DIR"
cp .*.pl "$TMP_DIR"
cd "$TMP_DIR"
trap cleanTemp EXIT

local docker_hub_repo="whatwg/html-build"

# Build the Docker image, using Docker Hub as a cache. (This will be fast if nothing has changed
# in html-build or its dependencies).
docker pull whatwg/wattsi
docker pull ptspts/pdfsizeopt
docker pull "$docker_hub_repo" || true
docker build --cache-from "$docker_hub_repo" --tag "$docker_hub_repo" .
}

function cleanTemp {
rm -rf "$TMP_DIR"
}

main "$@"
15 changes: 15 additions & 0 deletions ci-build/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
shopt -s extglob

HTML_SOURCE=$(realpath "$1")
HTML_OUTPUT=$(realpath "$2")

docker run --rm --interactive --tty \
--mount "type=bind,source=$HTML_SOURCE,destination=/whatwg/html,readonly=1" \
--env "HTML_SOURCE=/whatwg/html" \
--mount "type=bind,source=$HTML_OUTPUT,destination=/whatwg/output" \
--env "HTML_OUTPUT=/whatwg/output" \
whatwg/html-build
32 changes: 32 additions & 0 deletions ci-build/inside-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
cd "$(dirname "$0")/../.."

PDF_SERVE_PORT=8080

SKIP_BUILD_UPDATE_CHECK=true ./html-build/build.sh

echo ""
echo "Running conformance checker..."
# the -Xmx1g argument sets the size of the Java heap space to 1 gigabyte
java -Xmx1g -jar ./vnu.jar --skip-non-html "$HTML_OUTPUT"
echo ""

# Serve the built output so that Prince can snapshot it
# The nohup/sleep incantations are necessary because normal & does not work inside Docker:
# https://stackoverflow.com/q/50211207/3191
(
cd "$HTML_OUTPUT"
nohup bash -c "python3 -m http.server $PDF_SERVE_PORT &" && sleep 4
)

echo ""
echo "Building PDF..."
PDF_TMP="$(mktemp --suffix=.pdf)"
prince --verbose --output "$PDF_TMP" "http://0.0.0.0:$PDF_SERVE_PORT/"

echo ""
echo "Optimizing PDF..."
PATH=/bin/pdfsizeopt:$PATH pdfsizeopt --v=30 "$PDF_TMP" "$HTML_OUTPUT/print.pdf"
3 changes: 0 additions & 3 deletions ci-deploy/.dockerignore

This file was deleted.

10 changes: 0 additions & 10 deletions ci-deploy/README.md

This file was deleted.

Binary file removed ci-deploy/deploy-key.enc
Binary file not shown.
84 changes: 0 additions & 84 deletions ci-deploy/inside-container.sh

This file was deleted.

67 changes: 0 additions & 67 deletions ci-deploy/outside-container.sh

This file was deleted.

0 comments on commit 2b140ed

Please sign in to comment.