|
2 | 2 | set -o errexit
|
3 | 3 | set -o nounset
|
4 | 4 | set -o pipefail
|
| 5 | +shopt -s extglob |
5 | 6 |
|
6 |
| -HERE=$(dirname "$0") |
7 |
| -cd "$HERE/../.." |
8 |
| - |
9 |
| -DOCKER_USERNAME="domenicdenicola" |
10 |
| -DOCKER_HUB_REPO="whatwg/html-deploy" |
11 |
| - |
12 |
| -# Set from the outside: |
13 |
| -TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST:-false} |
14 |
| -IS_TEST_OF_HTML_BUILD_ITSELF=${IS_TEST_OF_HTML_BUILD_ITSELF:-false} |
15 |
| - |
16 |
| -# When not running pull request builds: |
17 |
| -# - DOCKER_PASSWORD is set from the outside |
18 |
| -# - ENCRYPTION_LABEL is set from the outside |
19 |
| - |
20 |
| -git clone --depth 1 https://github.com/pts/pdfsizeopt.git pdfsizeopt |
21 |
| - |
22 |
| -# Copy the Docker-related stuff into the working (grandparent) directory. |
23 |
| -cp "$HERE"/{.dockerignore,Dockerfile} . |
24 |
| - |
25 |
| -# Build the Docker image, using Docker Hub as a cache. (This will be fast if nothing has changed |
26 |
| -# in wattsi or html-build). |
27 |
| -docker pull "$DOCKER_HUB_REPO:latest" |
28 |
| -docker build --cache-from "$DOCKER_HUB_REPO:latest" \ |
29 |
| - --tag "$DOCKER_HUB_REPO:latest" \ |
30 |
| - --build-arg "travis_pull_request=$TRAVIS_PULL_REQUEST" \ |
31 |
| - --build-arg "is_test_of_html_build_itself=$IS_TEST_OF_HTML_BUILD_ITSELF" \ |
32 |
| - . |
33 |
| -if [[ "$TRAVIS_PULL_REQUEST" == "false" && "$IS_TEST_OF_HTML_BUILD_ITSELF" == "false" ]]; then |
34 |
| - # Decrypt the deploy key from this script's location into the html/ directory, since that's the |
35 |
| - # directory that will be shared with the container (but not built into the image). |
36 |
| - ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" |
37 |
| - ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" |
38 |
| - ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} |
39 |
| - ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} |
40 |
| - openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" \ |
41 |
| - -in "$HERE/deploy-key.enc" -out html/deploy-key -d |
42 |
| -fi |
43 |
| - |
44 |
| -# Run the inside-container.sh script, with the html/ directory mounted inside the container. |
45 |
| -echo "" |
46 |
| -docker run --volume "$(pwd)/html":/whatwg/html "$DOCKER_HUB_REPO:latest" |
47 |
| - |
48 |
| -if [[ "$TRAVIS_PULL_REQUEST" == "false" && "$IS_TEST_OF_HTML_BUILD_ITSELF" == "false" ]]; then |
49 |
| - # If the build succeeded and we got here, upload the Docker image to Docker Hub, so that future runs |
50 |
| - # can use it as a cache. |
| 7 | +HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 8 | +TMP_DIR=$(mktemp -d) |
| 9 | + |
| 10 | +function main { |
| 11 | + cp "$HERE/Dockerfile" "$TMP_DIR" |
| 12 | + cd "$HERE/.." |
| 13 | + cp -r !(.*|html|Dockerfile) "$TMP_DIR" |
| 14 | + cp .*.pl "$TMP_DIR" |
| 15 | + cd "$TMP_DIR" |
| 16 | + trap cleanTemp EXIT |
| 17 | + |
| 18 | + DOCKER_USERNAME="domenicdenicola" |
| 19 | + DOCKER_HUB_REPO="whatwg/html-deploy" |
| 20 | + |
| 21 | + # Set from the outside: |
| 22 | + TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST:-false} |
| 23 | + IS_TEST_OF_HTML_BUILD_ITSELF=${IS_TEST_OF_HTML_BUILD_ITSELF:-false} |
| 24 | + |
| 25 | + # When not running pull request builds: |
| 26 | + # - DOCKER_PASSWORD is set from the outside |
| 27 | + # - ENCRYPTION_LABEL is set from the outside |
| 28 | + |
| 29 | + # Build the Docker image, using Docker Hub as a cache. (This will be fast if nothing has changed |
| 30 | + # in wattsi or html-build). |
| 31 | + docker build --cache-from "$DOCKER_HUB_REPO:latest" \ |
| 32 | + --tag "$DOCKER_HUB_REPO:latest" \ |
| 33 | + --build-arg "html_build_dir=$TMP_DIR" \ |
| 34 | + --build-arg "travis_pull_request=$TRAVIS_PULL_REQUEST" \ |
| 35 | + --build-arg "is_test_of_html_build_itself=$IS_TEST_OF_HTML_BUILD_ITSELF" \ |
| 36 | + . |
| 37 | + if [[ "$TRAVIS_PULL_REQUEST" == "false" && "$IS_TEST_OF_HTML_BUILD_ITSELF" == "false" ]]; then |
| 38 | + # Decrypt the deploy key from this script's location into the html/ directory, since that's the |
| 39 | + # directory that will be shared with the container (but not built into the image). |
| 40 | + ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" |
| 41 | + ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" |
| 42 | + ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} |
| 43 | + ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} |
| 44 | + openssl aes-256-cbc -K "$ENCRYPTED_KEY" -iv "$ENCRYPTED_IV" \ |
| 45 | + -in "$HERE/deploy-key.enc" -out html/deploy-key -d |
| 46 | + fi |
| 47 | + |
| 48 | + # Run the inside-container.sh script, with the html/ directory mounted inside the container. |
51 | 49 | echo ""
|
52 |
| - docker tag "$DOCKER_HUB_REPO:latest" "$DOCKER_HUB_REPO:$TRAVIS_BUILD_NUMBER" && |
53 |
| - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" |
54 |
| - docker push "$DOCKER_HUB_REPO" |
55 |
| -fi |
| 50 | + cd "$HERE/../.." |
| 51 | + docker run --mount "type=bind,source=$(pwd)/html,destination=/whatwg/html,readonly=1" "$DOCKER_HUB_REPO:latest" |
| 52 | + |
| 53 | + if [[ "$TRAVIS_PULL_REQUEST" == "false" && "$IS_TEST_OF_HTML_BUILD_ITSELF" == "false" ]]; then |
| 54 | + # If the build succeeded and we got here, upload the Docker image to Docker Hub, so that future runs |
| 55 | + # can use it as a cache. |
| 56 | + echo "" |
| 57 | + docker tag "$DOCKER_HUB_REPO:latest" "$DOCKER_HUB_REPO:$TRAVIS_BUILD_NUMBER" && |
| 58 | + docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" |
| 59 | + docker push "$DOCKER_HUB_REPO" |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +function cleanTemp { |
| 64 | + rm -rf "$TMP_DIR" |
| 65 | +} |
| 66 | + |
| 67 | +main "$@" |
0 commit comments