diff --git a/.buildkite/scripts/steps/artifacts/docker_image.sh b/.buildkite/scripts/steps/artifacts/docker_image.sh index 551910432c413..77790bf3d5a8a 100755 --- a/.buildkite/scripts/steps/artifacts/docker_image.sh +++ b/.buildkite/scripts/steps/artifacts/docker_image.sh @@ -18,46 +18,82 @@ export KIBANA_IMAGE="$KIBANA_BASE_IMAGE:$KIBANA_IMAGE_TAG" echo "--- Verify manifest does not already exist" echo "Checking manifest for $KIBANA_IMAGE" -if docker manifest inspect $KIBANA_IMAGE &> /dev/null; then - echo "Manifest already exists, exiting" - exit 1 +SKIP_BUILD=false +if docker manifest inspect "$KIBANA_IMAGE" &> /dev/null; then + # If a staging build manifest already exists, there's a workflow error and the root cause should be investigated. + if [[ "${BUILDKITE_PULL_REQUEST:-false}" == "false" ]]; then + echo "Manifest already exists, exiting" + exit 1 + else + echo "Manifest already exists, skipping build. Look up previous build for artifacts." + SKIP_BUILD=true + fi fi -echo "--- Build Kibana" -node scripts/build \ - --debug \ - --release \ - --serverless \ - --docker-cross-compile \ - --docker-namespace="kibana-ci" \ - --docker-tag="$KIBANA_IMAGE_TAG" - -echo "--- Tag images" -docker rmi "$KIBANA_IMAGE" -docker load < "target/kibana-serverless-$BASE_VERSION-docker-image.tar.gz" -docker tag "$KIBANA_IMAGE" "$KIBANA_IMAGE-amd64" - -docker rmi "$KIBANA_IMAGE" -docker load < "target/kibana-serverless-$BASE_VERSION-docker-image-aarch64.tar.gz" -docker tag "$KIBANA_IMAGE" "$KIBANA_IMAGE-arm64" - -echo "--- Push images" -docker image push "$KIBANA_IMAGE-arm64" -docker image push "$KIBANA_IMAGE-amd64" - -echo "--- Create and push manifests" -docker manifest create \ - "$KIBANA_IMAGE" \ - --amend "$KIBANA_IMAGE-arm64" \ - --amend "$KIBANA_IMAGE-amd64" -docker manifest push "$KIBANA_IMAGE" - -if [[ "$BUILDKITE_BRANCH" == "$KIBANA_BASE_BRANCH" ]] && [[ "${BUILDKITE_PULL_REQUEST:-false}" == "false" ]]; then +if [[ "$SKIP_BUILD" == "false" ]]; then + echo "--- Build Kibana" + node scripts/build \ + --debug \ + --release \ + --serverless \ + --docker-cross-compile \ + --docker-namespace="kibana-ci" \ + --docker-tag="$KIBANA_IMAGE_TAG" + + echo "--- Tag images" + docker rmi "$KIBANA_IMAGE" + docker load < "target/kibana-serverless-$BASE_VERSION-docker-image.tar.gz" + docker tag "$KIBANA_IMAGE" "$KIBANA_IMAGE-amd64" + + docker rmi "$KIBANA_IMAGE" + docker load < "target/kibana-serverless-$BASE_VERSION-docker-image-aarch64.tar.gz" + docker tag "$KIBANA_IMAGE" "$KIBANA_IMAGE-arm64" + + echo "--- Push images" + docker image push "$KIBANA_IMAGE-arm64" + docker image push "$KIBANA_IMAGE-amd64" + + echo "--- Create and push manifests" docker manifest create \ - "$KIBANA_BASE_IMAGE:latest" \ + "$KIBANA_IMAGE" \ --amend "$KIBANA_IMAGE-arm64" \ --amend "$KIBANA_IMAGE-amd64" - docker manifest push "$KIBANA_BASE_IMAGE:latest" + docker manifest push "$KIBANA_IMAGE" + + if [[ "$BUILDKITE_BRANCH" == "$KIBANA_BASE_BRANCH" ]] && [[ "${BUILDKITE_PULL_REQUEST:-false}" == "false" ]]; then + docker manifest create \ + "$KIBANA_BASE_IMAGE:latest" \ + --amend "$KIBANA_IMAGE-arm64" \ + --amend "$KIBANA_IMAGE-amd64" + docker manifest push "$KIBANA_BASE_IMAGE:latest" + fi + + echo "--- Build dependencies report" + node scripts/licenses_csv_report "--csv=target/dependencies-$GIT_ABBREV_COMMIT.csv" + + echo "--- Upload archives" + buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-linux-x86_64.tar.gz" + buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-linux-aarch64.tar.gz" + buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-image.tar.gz" + buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-image-aarch64.tar.gz" + buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-build-context.tar.gz" + buildkite-agent artifact upload "kibana-$BASE_VERSION-cdn-assets.tar.gz" + buildkite-agent artifact upload "dependencies-$GIT_ABBREV_COMMIT.csv" + + echo "--- Upload CDN assets" + cd target + gcloud auth activate-service-account --key-file <(echo "$GCS_SA_CDN_KEY") + + CDN_ASSETS_FOLDER=$(mktemp -d) + tar -xf "kibana-$BASE_VERSION-cdn-assets.tar.gz" -C "$CDN_ASSETS_FOLDER" --strip=1 + + gsutil -m cp -r "$CDN_ASSETS_FOLDER/*" "gs://$GCS_SA_CDN_BUCKET/$GIT_ABBREV_COMMIT" + gcloud auth revoke "$GCS_SA_CDN_EMAIL" + + echo "--- Validate CDN assets" + ts-node "$(git rev-parse --show-toplevel)/.buildkite/scripts/steps/artifacts/validate_cdn_assets.ts" \ + "$GCS_SA_CDN_URL" \ + "$CDN_ASSETS_FOLDER" fi cat << EOF | buildkite-agent annotate --style "info" --context image @@ -75,33 +111,6 @@ if [[ "${BUILDKITE_PULL_REQUEST:-false}" != "false" ]]; then buildkite-agent meta-data set pr_comment:early_comment_job_id "$BUILDKITE_JOB_ID" fi -echo "--- Build dependencies report" -node scripts/licenses_csv_report "--csv=target/dependencies-$GIT_ABBREV_COMMIT.csv" - -echo "--- Upload CDN assets" -cd target -gcloud auth activate-service-account --key-file <(echo "$GCS_SA_CDN_KEY") - -CDN_ASSETS_FOLDER=$(mktemp -d) -tar -xf "kibana-$BASE_VERSION-cdn-assets.tar.gz" -C "$CDN_ASSETS_FOLDER" --strip=1 - -gsutil -m cp -r "$CDN_ASSETS_FOLDER/*" "gs://$GCS_SA_CDN_BUCKET/$GIT_ABBREV_COMMIT" -gcloud auth revoke "$GCS_SA_CDN_EMAIL" - -echo "--- Validate CDN assets" -ts-node "$(git rev-parse --show-toplevel)/.buildkite/scripts/steps/artifacts/validate_cdn_assets.ts" \ - "$GCS_SA_CDN_URL" \ - "$CDN_ASSETS_FOLDER" - -echo "--- Upload archives" -buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-linux-x86_64.tar.gz" -buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-linux-aarch64.tar.gz" -buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-image.tar.gz" -buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-image-aarch64.tar.gz" -buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-build-context.tar.gz" -buildkite-agent artifact upload "kibana-$BASE_VERSION-cdn-assets.tar.gz" -buildkite-agent artifact upload "dependencies-$GIT_ABBREV_COMMIT.csv" - # This part is related with updating the configuration of kibana-controller, # so that new stack instances contain the latest and greatest image of kibana, # and the respective stack components of course.