From 71fe551802e6d66d300f69be304e3f01b57a6437 Mon Sep 17 00:00:00 2001 From: Brian Seeders Date: Thu, 19 Nov 2020 16:32:42 -0500 Subject: [PATCH] [CI] Build docker image during packer_cache (#82145) (#83667) --- .ci/build_docker.sh | 10 ++++++ .ci/packer_cache_for_branch.sh | 60 ++++++++++++++++++++++++++++++++++ vars/kibanaPipeline.groovy | 7 +--- 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100755 .ci/build_docker.sh create mode 100755 .ci/packer_cache_for_branch.sh diff --git a/.ci/build_docker.sh b/.ci/build_docker.sh new file mode 100755 index 0000000000000..1f45182aad840 --- /dev/null +++ b/.ci/build_docker.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "${0}")" + +cp /usr/local/bin/runbld ./ +cp /usr/local/bin/bash_standard_lib.sh ./ + +docker build -t kibana-ci -f ./Dockerfile . diff --git a/.ci/packer_cache_for_branch.sh b/.ci/packer_cache_for_branch.sh new file mode 100755 index 0000000000000..0d9b22b04dbd0 --- /dev/null +++ b/.ci/packer_cache_for_branch.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +set -e + +branch="$1" +checkoutDir="$(pwd)" + +if [[ "$branch" != "master" ]]; then + checkoutDir="/tmp/kibana-$branch" + git clone https://github.com/elastic/kibana.git --branch "$branch" --depth 1 "$checkoutDir" + cd "$checkoutDir" +fi + +source src/dev/ci_setup/setup.sh; + +# download es snapshots +node scripts/es snapshot --download-only; +node scripts/es snapshot --license=oss --download-only; + +# download reporting browsers +(cd "x-pack" && node ../node_modules/.bin/gulp downloadChromium); + +# cache the chromedriver archive +chromedriverDistVersion="$(node -e "console.log(require('chromedriver').version)")" +chromedriverPkgVersion="$(node -e "console.log(require('./package.json').devDependencies.chromedriver)")" +if [ -z "$chromedriverDistVersion" ] || [ -z "$chromedriverPkgVersion" ]; then + echo "UNABLE TO DETERMINE CHROMEDRIVER VERSIONS" + exit 1 +fi +mkdir -p .chromedriver +curl "https://chromedriver.storage.googleapis.com/$chromedriverDistVersion/chromedriver_linux64.zip" > .chromedriver/chromedriver.zip +echo "$chromedriverPkgVersion" > .chromedriver/pkgVersion + +# cache the geckodriver archive +geckodriverPkgVersion="$(node -e "console.log(require('./package.json').devDependencies.geckodriver)")" +if [ -z "$geckodriverPkgVersion" ]; then + echo "UNABLE TO DETERMINE geckodriver VERSIONS" + exit 1 +fi +mkdir -p ".geckodriver" +cp "node_modules/geckodriver/geckodriver.tar.gz" .geckodriver/geckodriver.tar.gz +echo "$geckodriverPkgVersion" > .geckodriver/pkgVersion + +echo "Creating bootstrap_cache archive" + +# archive cacheable directories +mkdir -p "$HOME/.kibana/bootstrap_cache" +tar -cf "$HOME/.kibana/bootstrap_cache/$branch.tar" \ + .chromium \ + .es \ + .chromedriver \ + .geckodriver; + +echo "created $HOME/.kibana/bootstrap_cache/$branch.tar" + +.ci/build_docker.sh + +if [[ "$branch" != "master" ]]; then + rm --preserve-root -rf "$checkoutDir" +fi diff --git a/vars/kibanaPipeline.groovy b/vars/kibanaPipeline.groovy index 2eca8d1deedcc..dd3d9c29f19c9 100644 --- a/vars/kibanaPipeline.groovy +++ b/vars/kibanaPipeline.groovy @@ -373,12 +373,7 @@ def scriptTaskDocker(description, script) { def buildDocker() { sh( - script: """ - cp /usr/local/bin/runbld .ci/ - cp /usr/local/bin/bash_standard_lib.sh .ci/ - cd .ci - docker build -t kibana-ci -f ./Dockerfile . - """, + script: "./.ci/build_docker.sh", label: 'Build CI Docker image' ) }