From 97e61276e8d57ec75cfb4696e45769d5166f938a Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 14 Feb 2019 20:44:53 +0800 Subject: [PATCH] Enable ccache for Alpine builds on Travis CI --- .travis.yml | 51 ++++++++++++++++++++++++++++++++++ 10/alpine/Dockerfile | 3 ++ 11/alpine/Dockerfile | 3 ++ 6/alpine/Dockerfile | 3 ++ 8/alpine/Dockerfile | 3 ++ AlpineCCacheTravisInjection.sh | 14 ++++++++++ Dockerfile-alpine.template | 3 ++ travis.yml.template | 11 ++++++++ update.sh | 12 ++++++++ 9 files changed, 103 insertions(+) create mode 100755 AlpineCCacheTravisInjection.sh diff --git a/.travis.yml b/.travis.yml index e949ab5acb..f1e03723e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,17 @@ services: echo "Skip build of $Dockerfile as it's not changed." exit fi + if [ "alpine" = "$VARIANT" ]; then + ./AlpineCCacheTravisInjection.sh + mkdir -p ccache + ( + cd ccache + ls -l + md5sum * + nc -v -l -p 5678 -q 1 < cache.tgz & + nc -v -l -p 1234 -q 1 > new-cache.tgz & + ) + fi script: ./test-build.sh $NODE_VERSION $VARIANT @@ -125,6 +136,16 @@ jobs: - NODE_VERSION="10" - VARIANT="alpine" + before_cache: + - ls -hl ccache/ + - ls -l ccache/ + - file ccache/* + - md5sum ccache/* + - mv ccache/new-cache.tgz ccache/cache.tgz + cache: + directories: + - ccache/ + - stage: Build before_script: *auto_skip name: 10 on stretch @@ -146,6 +167,16 @@ jobs: - NODE_VERSION="11" - VARIANT="alpine" + before_cache: + - ls -hl ccache/ + - ls -l ccache/ + - file ccache/* + - md5sum ccache/* + - mv ccache/new-cache.tgz ccache/cache.tgz + cache: + directories: + - ccache/ + - stage: Build before_script: *auto_skip name: 11 on stretch @@ -181,6 +212,16 @@ jobs: - NODE_VERSION="6" - VARIANT="alpine" + before_cache: + - ls -hl ccache/ + - ls -l ccache/ + - file ccache/* + - md5sum ccache/* + - mv ccache/new-cache.tgz ccache/cache.tgz + cache: + directories: + - ccache/ + - stage: Build before_script: *auto_skip name: 6 on onbuild @@ -223,6 +264,16 @@ jobs: - NODE_VERSION="8" - VARIANT="alpine" + before_cache: + - ls -hl ccache/ + - ls -l ccache/ + - file ccache/* + - md5sum ccache/* + - mv ccache/new-cache.tgz ccache/cache.tgz + cache: + directories: + - ccache/ + - stage: Build before_script: *auto_skip name: 8 on onbuild diff --git a/10/alpine/Dockerfile b/10/alpine/Dockerfile index ccfa1d4b95..7c719a827e 100644 --- a/10/alpine/Dockerfile +++ b/10/alpine/Dockerfile @@ -16,6 +16,7 @@ RUN addgroup -g 1000 node \ linux-headers \ make \ python \ + # Travis CI build deps injection # gpg keys listed at https://github.com/nodejs/node#release-keys && for key in \ 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ @@ -40,10 +41,12 @@ RUN addgroup -g 1000 node \ && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ && tar -xf "node-v$NODE_VERSION.tar.xz" \ && cd "node-v$NODE_VERSION" \ + # Travis CI ccache env setup and cache restore && ./configure \ && make -j$(getconf _NPROCESSORS_ONLN) \ && make install \ && apk del .build-deps \ + # Travis CI ccache summary, store and cleanup && cd .. \ && rm -Rf "node-v$NODE_VERSION" \ && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt diff --git a/11/alpine/Dockerfile b/11/alpine/Dockerfile index 6a1c9493b4..0cc7c7a80a 100644 --- a/11/alpine/Dockerfile +++ b/11/alpine/Dockerfile @@ -16,6 +16,7 @@ RUN addgroup -g 1000 node \ linux-headers \ make \ python \ + # Travis CI build deps injection # gpg keys listed at https://github.com/nodejs/node#release-keys && for key in \ 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ @@ -40,10 +41,12 @@ RUN addgroup -g 1000 node \ && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ && tar -xf "node-v$NODE_VERSION.tar.xz" \ && cd "node-v$NODE_VERSION" \ + # Travis CI ccache env setup and cache restore && ./configure \ && make -j$(getconf _NPROCESSORS_ONLN) \ && make install \ && apk del .build-deps \ + # Travis CI ccache summary, store and cleanup && cd .. \ && rm -Rf "node-v$NODE_VERSION" \ && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt diff --git a/6/alpine/Dockerfile b/6/alpine/Dockerfile index 46c3a466fa..37f9a183a5 100644 --- a/6/alpine/Dockerfile +++ b/6/alpine/Dockerfile @@ -16,6 +16,7 @@ RUN addgroup -g 1000 node \ linux-headers \ make \ python \ + # Travis CI build deps injection # gpg keys listed at https://github.com/nodejs/node#release-keys && for key in \ 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ @@ -40,10 +41,12 @@ RUN addgroup -g 1000 node \ && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ && tar -xf "node-v$NODE_VERSION.tar.xz" \ && cd "node-v$NODE_VERSION" \ + # Travis CI ccache env setup and cache restore && ./configure \ && make -j$(getconf _NPROCESSORS_ONLN) \ && make install \ && apk del .build-deps \ + # Travis CI ccache summary, store and cleanup && cd .. \ && rm -Rf "node-v$NODE_VERSION" \ && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt diff --git a/8/alpine/Dockerfile b/8/alpine/Dockerfile index 2e579beb95..7dd734bf1b 100644 --- a/8/alpine/Dockerfile +++ b/8/alpine/Dockerfile @@ -16,6 +16,7 @@ RUN addgroup -g 1000 node \ linux-headers \ make \ python \ + # Travis CI build deps injection # gpg keys listed at https://github.com/nodejs/node#release-keys && for key in \ 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ @@ -40,10 +41,12 @@ RUN addgroup -g 1000 node \ && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ && tar -xf "node-v$NODE_VERSION.tar.xz" \ && cd "node-v$NODE_VERSION" \ + # Travis CI ccache env setup and cache restore && ./configure \ && make -j$(getconf _NPROCESSORS_ONLN) \ && make install \ && apk del .build-deps \ + # Travis CI ccache summary, store and cleanup && cd .. \ && rm -Rf "node-v$NODE_VERSION" \ && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt diff --git a/AlpineCCacheTravisInjection.sh b/AlpineCCacheTravisInjection.sh new file mode 100755 index 0000000000..b2332a2a71 --- /dev/null +++ b/AlpineCCacheTravisInjection.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -ue + +for dockerfile in **/alpine/Dockerfile; do +# shellcheck disable=SC2016 + sed -Ei -e 's/# Travis CI build deps injection/ ccache netcat-openbsd \\/' \ + -e "s/# Travis CI ccache env setup and cache restore/&\n \&\& nc -v \"\$HOST_IP\" 5678 | tar -xz -C \/ || true \\\/" \ + -e "s/# Travis CI ccache env setup and cache restore/&\n \&\& HOST_IP=\"\$(ip route | awk '\/default\/ { print \$3 \}')\" \\\/" \ + -e 's/# Travis CI ccache env setup and cache restore/&\n \&\& ccache --set-config=max_size=150MB \\/' \ + -e 's/# Travis CI ccache env setup and cache restore/\&\& export PATH="\/usr\/lib\/ccache\/bin\/:$PATH" \\/' \ + -e 's/# Travis CI ccache summary, store and cleanup/&\n \&\& rm -rf \/root\/.ccache\/ \\/' \ + -e 's/# Travis CI ccache summary, store and cleanup/&\n \&\& ccache -s 1>\&2 \\/' \ + -e 's/# Travis CI ccache summary, store and cleanup/\&\& tar -czf - \/root\/.ccache\/ | nc -v -w 3 "$HOST_IP" 1234 || true \\/' "${dockerfile}" +done diff --git a/Dockerfile-alpine.template b/Dockerfile-alpine.template index ee54a07184..84a0a953b4 100644 --- a/Dockerfile-alpine.template +++ b/Dockerfile-alpine.template @@ -16,6 +16,7 @@ RUN addgroup -g 1000 node \ linux-headers \ make \ python \ + # Travis CI build deps injection # gpg keys listed at https://github.com/nodejs/node#release-keys && for key in \ "${NODE_KEYS[@]}" @@ -30,10 +31,12 @@ RUN addgroup -g 1000 node \ && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ && tar -xf "node-v$NODE_VERSION.tar.xz" \ && cd "node-v$NODE_VERSION" \ + # Travis CI ccache env setup and cache restore && ./configure \ && make -j$(getconf _NPROCESSORS_ONLN) \ && make install \ && apk del .build-deps \ + # Travis CI ccache summary, store and cleanup && cd .. \ && rm -Rf "node-v$NODE_VERSION" \ && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt diff --git a/travis.yml.template b/travis.yml.template index e561e6b26f..cfee22e772 100644 --- a/travis.yml.template +++ b/travis.yml.template @@ -27,6 +27,17 @@ services: echo "Skip build of $Dockerfile as it's not changed." exit fi + if [ "alpine" = "$VARIANT" ]; then + ./AlpineCCacheTravisInjection.sh + mkdir -p ccache + ( + cd ccache + ls -l + md5sum * + nc -v -l -p 5678 -q 1 < cache.tgz & + nc -v -l -p 1234 -q 1 > new-cache.tgz & + ) + fi script: ./test-build.sh $NODE_VERSION $VARIANT diff --git a/update.sh b/update.sh index 5565383ebd..bf3702bb88 100755 --- a/update.sh +++ b/update.sh @@ -204,6 +204,18 @@ function add_stage() { env: - NODE_VERSION="'"${version}"'" - VARIANT="'"${variant}"'"' >> .travis.yml + if [ "alpine" = "${variant}" ]; then + echo ' + before_cache: + - ls -hl ccache/ + - ls -l ccache/ + - file ccache/* + - md5sum ccache/* + - mv ccache/new-cache.tgz ccache/cache.tgz + cache: + directories: + - ccache/' >> .travis.yml + fi } echo '# DO NOT MODIFY. THIS FILE IS AUTOGENERATED #