diff --git a/.buildkite/pipelines/pipeline_pull_request_deploy_docs.yml b/.buildkite/pipelines/pipeline_pull_request_deploy_docs.yml deleted file mode 100644 index 82d4113607c..00000000000 --- a/.buildkite/pipelines/pipeline_pull_request_deploy_docs.yml +++ /dev/null @@ -1,8 +0,0 @@ -## 🏠/.buildkite/pipelines/pipeline_pull_request_deploy_docs.yml - -steps: - - command: .buildkite/scripts/pipelines/pipeline_deploy_docs.sh - label: ":newspaper: Build and deploy EUI documentation website" - agents: - provider: "gcp" - if: build.branch != "main" # We don't want to deploy docs on main, only on manual release diff --git a/.buildkite/pipelines/pipeline_pull_request_test_and_deploy.yml b/.buildkite/pipelines/pipeline_pull_request_test_and_deploy.yml index a5cf3680715..d4cb99a4483 100644 --- a/.buildkite/pipelines/pipeline_pull_request_test_and_deploy.yml +++ b/.buildkite/pipelines/pipeline_pull_request_test_and_deploy.yml @@ -6,14 +6,3 @@ steps: build: branch: "${BUILDKITE_BRANCH}" commit: "${BUILDKITE_COMMIT}" - - trigger: "eui-pull-request-deploy-docs" - label: ":newspaper: EUI pull request deploy docs" - build: - message: "${BUILDKITE_MESSAGE}" - branch: "${BUILDKITE_BRANCH}" - commit: "${BUILDKITE_COMMIT}" - env: - BUILDKITE_PULL_REQUEST: "${BUILDKITE_PULL_REQUEST}" - BUILDKITE_PULL_REQUEST_BASE_BRANCH: "${BUILDKITE_PULL_REQUEST_BASE_BRANCH}" - GIT_BRANCH: "${BUILDKITE_BRANCH}" - GIT_PULL_REQUEST_ID: "${BUILDKITE_PULL_REQUEST}" diff --git a/.buildkite/pipelines/pipeline_release_deploy_docs.yml b/.buildkite/pipelines/pipeline_release_deploy_docs.yml deleted file mode 100644 index b3980c0b0b2..00000000000 --- a/.buildkite/pipelines/pipeline_release_deploy_docs.yml +++ /dev/null @@ -1,10 +0,0 @@ -## 🏠/.buildkite/pipelines/pipeline_release_deploy_docs.yml - -steps: - - agents: - provider: "gcp" - command: .buildkite/scripts/pipelines/pipeline_deploy_docs.sh - env: - GIT_BRANCH: "${BUILDKITE_BRANCH}" - GIT_PULL_REQUEST_ID: "${BUILDKITE_PULL_REQUEST}" - GIT_TAG: "${BUILDKITE_TAG}" diff --git a/.buildkite/scripts/pipelines/pipeline_deploy_new_docs.sh b/.buildkite/scripts/pipelines/pipeline_deploy_new_docs.sh index b544e2be425..80f97557d5b 100644 --- a/.buildkite/scripts/pipelines/pipeline_deploy_new_docs.sh +++ b/.buildkite/scripts/pipelines/pipeline_deploy_new_docs.sh @@ -3,74 +3,163 @@ set -eo pipefail +############################################################ +# Setup # +############################################################ + # include .bash_profile and utils source ~/.bash_profile source .buildkite/scripts/common/utils.sh -# Enable corepack to expose yarn cli command +# Enable corepack to expose the correct yarn cli command corepack enable # Print out debug information echo "Node.js version: $(node -v)" echo "Yarn version: $(yarn -v)" -# Calculate paths and directories -if [[ -n "${BUILDKITE_PULL_REQUEST}" ]] && [[ "${BUILDKITE_PULL_REQUEST}" != "false" ]]; then +############################################################ +# Configuration # +############################################################ + +# GCS storage project and bucket +storage_vault="secret/ci/elastic-eui/website-storage-bucket" +GCLOUD_PROJECT="$(retry 5 vault read -field=google_cloud_project "${storage_vault}")" +GCLOUD_BUCKET="$(retry 5 vault read -field=google_cloud_bucket "${storage_vault}")" +GCLOUD_BUCKET_FULL="${GCLOUD_PROJECT}-${GCLOUD_BUCKET}" + +# GCS storage copy arguments +GCLOUD_CP_ARGS=( + --cache-control="public, max-age=1800, must-revalidate" # set caching policy + --recursive # copy all files recursively + --predefined-acl="publicRead" # ensure copied files are publicly accessible + --gzip-local="js,css,html,svg,png,jpg,ico" # gzip these file extensions before copying to the bucket +) + +# Default to production deployment of Storybook +export STORYBOOK_BASE_URL="https://eui.elastic.co/storybook" + +# GTM identifier +analytics_vault="secret/ci/elastic-eui/analytics" +export DOCS_GOOGLE_TAG_MANAGER_ID="$(retry 5 vault read -field=google_tag_manager_id "${analytics_vault}")" + +# A pattern to recognize git tag names used for tagging actual releases with +release_tag_pattern="v[0-9]+\.[0-9]+\.[0-9]+" + +# Whether this deployment should _also_ be copied to bucket's root directory (/) +# USE WITH CAUTION! +copy_to_root_directory=false + +############################################################ +# Utility pipeline functions # +############################################################ + +# Whether the pipeline is triggered by a pull request +is_pipeline_trigger_pull_request() { + [[ -n "${BUILDKITE_PULL_REQUEST}" ]] && [[ "${BUILDKITE_PULL_REQUEST}" != "false" ]] +} + +# Whether the pipeline is triggered by a pushed tag +# It should be used in above the is_pipeline_trigger_branch check +# since BUILDKITE_BRANCH is sometimes set to the tag name +is_pipeline_trigger_tag() { + [[ -n "${BUILDKITE_TAG}" ]] && [[ "${BUILDKITE_TAG}" =~ $release_tag_pattern ]] +} + +# Whether the pipeline is triggered by an updated `main` branch +is_pipeline_trigger_branch() { + if [[ -z "$1" ]]; then + echo >&2 "is_pipeline_trigger_branch must be called with a branch name as an argument" + exit 3 + fi + + [[ -n "${BUILDKITE_BRANCH}" ]] && [[ "${BUILDKITE_BRANCH}" == "$1" ]] +} + +############################################################ +# Step 1 - Calculate paths and directories # +############################################################ + +if is_pipeline_trigger_pull_request; then PR_SLUG="pr_${BUILDKITE_PULL_REQUEST}" export STORYBOOK_BASE_URL="https://eui.elastic.co/${PR_SLUG}/storybook" - bucket_directory="${PR_SLUG}/new-docs/" + bucket_directory="${PR_SLUG}/" echo "Detected a PR preview environment configuration. The built files will be copied to ${bucket_directory}" -elif [[ -n "${BUILDKITE_BRANCH}" ]] && [[ "${BUILDKITE_BRANCH}" == "main" ]]; then - # TODO: Detect if 'main' branch updated due to a new version being released based on BUILDKITE_TAG - export STORYBOOK_BASE_URL="https://eui.elastic.co/storybook" +elif is_pipeline_trigger_tag; then + bucket_directory="${BUILDKITE_TAG}/" + + latest_release_tag_on_main=$(git describe --tags "$(git rev-list --branches=main --tags --max-count=1)") + if [[ "${BUILDKITE_TAG}" == "${latest_release_tag_on_main}" ]]; then + copy_to_root_directory=true + echo "Detected a tagged release. The built files will be copied to ${bucket_directory} and the root directory" + else + echo "Detected a tagged release. The built files will be copied to ${bucket_directory}" + fi +elif is_pipeline_trigger_branch "main"; then bucket_directory="next/" echo "Detected a 'main' branch environment configuration. The built files will be copied to ${bucket_directory}" else - echo "The script has been triggered with no pull request or branch information. This is a no-op." + echo "The script has been triggered with no pull request, branch or tag information. This is a no-op." exit 1 fi +############################################################ +# Step 2 - Dependencies # +############################################################ + echo "+++ :yarn: Installing dependencies" yarn +############################################################ +# Step 3 - Build # +############################################################ + echo "+++ :yarn: Building @elastic/eui-website and its local dependencies" -analytics_vault="secret/ci/elastic-eui/analytics" # Pass base url to docusaurus. It must have a leading and trailing slash included. export DOCS_BASE_URL="/${bucket_directory}" -export DOCS_GOOGLE_TAG_MANAGER_ID="$(retry 5 vault read -field=google_tag_manager_id "${analytics_vault}")" yarn workspace @elastic/eui-website run build:workspaces +############################################################ +# Step 4 - Deployment # +############################################################ + echo "+++ Configuring environment for website deployment" gcloud auth activate-service-account --key-file <(echo "${GCE_ACCOUNT}") unset GCE_ACCOUNT -storage_vault="secret/ci/elastic-eui/website-storage-bucket" -GCLOUD_PROJECT="$(retry 5 vault read -field=google_cloud_project "${storage_vault}")" -GCLOUD_BUCKET="$(retry 5 vault read -field=google_cloud_bucket "${storage_vault}")" -GCLOUD_BUCKET_FULL="${GCLOUD_PROJECT}-${GCLOUD_BUCKET}" - -GCLOUD_CP_ARGS=( - --cache-control="public, max-age=1800, must-revalidate" # set caching policy - --recursive # copy all files recursively - --predefined-acl="publicRead" # ensure copied files are publicly accessible - --gzip-local="js,css,html,svg,png,jpg,ico" # gzip these file extensions before copying to the bucket -) - # Copy files to the GCS bucket echo "+++ :bucket: Copying built files to the bucket" # additional protection layer in case bucket_directory is ever unset if [[ -z "${bucket_directory}" ]]; then - bucket_directory="new-docs/" + echo >&2 "Detected an unset 'bucket_directory' variable. This is likely a mistake." + exit 2 fi echo "Beginning to copy built files to /${bucket_directory}" gcloud storage cp "${GCLOUD_CP_ARGS[@]}" packages/website/build/* "gs://${GCLOUD_BUCKET_FULL}/${bucket_directory}" +echo "Successfully copied files to /${bucket_directory}" + +# Copy deployed tagged release to / +if [[ $copy_to_root_directory == true ]]; then + echo "Beginning to copy built files to /" + # Use "copy in the cloud" to speed up the process + gcloud storage cp "${GCLOUD_CP_ARGS[@]}" "gs://${GCLOUD_BUCKET_FULL}/${bucket_directory}" "gs://${GCLOUD_BUCKET_FULL}/" + echo "Successfully copied files to /" +fi + +############################################################ +# Step 5 - Notify # +############################################################ + +published_website_url="https://eui.elastic.co/${bucket_directory}" -echo "New documentation website deployed: https://eui.elastic.co/${bucket_directory}" | buildkite-agent annotate --style "success" --context "deployed" +# Add an annotation on top of the pipeline +echo "New documentation website deployed: ${published_website_url}" | buildkite-agent annotate --style "success" --context "deployed" -echo "* [Documentation website](https://eui.elastic.co/${bucket_directory})" | buildkite-agent meta-data set pr_comment:docs_deployment_link:head +# Add an annotation in build status github comment +echo "* [Documentation website](${published_website_url})" | buildkite-agent meta-data set pr_comment:docs_deployment_link:head diff --git a/catalog-info.yaml b/catalog-info.yaml index d6b320c7898..7801351eb75 100644 --- a/catalog-info.yaml +++ b/catalog-info.yaml @@ -20,7 +20,7 @@ metadata: description: Elastic design system library links: [ { - url: "https://eui.elastic.co/#/", + url: "https://eui.elastic.co/", title: "EUI documentation", } ] @@ -31,50 +31,6 @@ spec: owner: group:eui-team lifecycle: production ---- -## -# Example pipeline -# TODO: Remove this resource and related pipeline if they're not needed anymore -## - -# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/e57ee3bed7a6f73077a3f55a38e76e40ec87a7cf/rre.schema.json -apiVersion: backstage.io/v1alpha1 -kind: Resource -metadata: - name: buildkite-pipeline-eui - description: EUI example pipeline that echoes a greeting - links: [ - { - title: "EUI - example pipeline", - url: "https://buildkite.com/elastic/eui", - } - ] - -spec: - type: buildkite-pipeline - owner: group:eui-team - system: buildkite - implementation: - apiVersion: buildkite.elastic.dev/v1 - kind: Pipeline - metadata: - name: eui - spec: - repository: elastic/eui - pipeline_file: ".buildkite/pipeline.yml" - default_branch: main - # Setting all triggers to false to prevent the default job from running. - # Keeping the job available if needed for smoke testing during the migration. - provider_settings: - build_branches: false - build_tags: false - build_pull_requests: false - teams: - eui-team: - access_level: MANAGE_BUILD_AND_READ - everyone: - access_level: READ_ONLY - --- ## # buildkite-pipeline-eui-pull-request-test @@ -119,53 +75,6 @@ spec: everyone: access_level: BUILD_AND_READ ---- -## -# buildkite-pipeline-eui-pull-request-deploy-docs -# Pull request - deploy docs website PR preview -## - -# TODO: Remove when the old documentation site is replaced with EUI+ - -# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/e57ee3bed7a6f73077a3f55a38e76e40ec87a7cf/rre.schema.json -apiVersion: backstage.io/v1alpha1 -kind: Resource -metadata: - name: buildkite-pipeline-eui-pull-request-deploy-docs - description: EUI pipeline to deploy docs to cloud on pull request - links: [ - { - title: "EUI - pull-request-deploy-docs", - url: "https://buildkite.com/elastic/eui-pull-request-deploy-docs", - } - ] - -spec: - type: buildkite-pipeline - owner: group:eui-team - system: buildkite - implementation: - apiVersion: buildkite.elastic.dev/v1 - kind: Pipeline - metadata: - name: eui-pull-request-deploy-docs - spec: - repository: elastic/eui - pipeline_file: ".buildkite/pipelines/pipeline_pull_request_deploy_docs.yml" - default_branch: main - cancel_intermediate_builds: true - # Job runs as a step in pull request combined job - provider_settings: - build_branches: false - build_tags: false - build_pull_requests: false - teams: - eui-team: - access_level: MANAGE_BUILD_AND_READ - everyone: - access_level: BUILD_AND_READ - - --- ## # buildkite-pipeline-eui-pull-request-test-and-deploy @@ -214,50 +123,6 @@ spec: everyone: access_level: BUILD_AND_READ ---- -## -# buildkite-pipeline-eui-release-deploy-docs -# EUI Release - publish docs to eui.elastic.co when we tag a new release -## - -# yaml-language-server: $schema=https://gist.githubusercontent.com/elasticmachine/988b80dae436cafea07d9a4a460a011d/raw/e57ee3bed7a6f73077a3f55a38e76e40ec87a7cf/rre.schema.json -apiVersion: backstage.io/v1alpha1 -kind: Resource -metadata: - name: buildkite-pipeline-eui-release-deploy-docs - description: EUI pipeline to deploy docs to the EUI subdomain when we tag a new release - links: [ - { - title: "EUI - release-deploy-docs", - url: "https://buildkite.com/elastic/eui-release-deploy-docs", - } - ] - -spec: - type: buildkite-pipeline - owner: group:eui-team - system: buildkite - implementation: - apiVersion: buildkite.elastic.dev/v1 - kind: Pipeline - metadata: - name: eui-release-deploy-docs - spec: - repository: elastic/eui - pipeline_file: ".buildkite/pipelines/pipeline_release_deploy_docs.yml" - provider_settings: - build_branches: false - build_tags: true # Will trigger job when GitHub release tags are created - build_pull_requests: false - filter_enabled: true - filter_condition: | # Eg v100.100.100 but skip v100.100.100.1 or v100.100.100-rc - build.tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/ - teams: - eui-team: - access_level: MANAGE_BUILD_AND_READ - everyone: - access_level: READ_ONLY - --- ## # buildkite-pipeline-eui-prune-staging-docs @@ -338,6 +203,8 @@ spec: filter_enabled: true # TODO: remove the test-automatic-releases condition when the pipeline is production-ready filter_condition: build.branch == "main" || build.branch == "build/test-automatic-releases" + # Disable the pipeline for now + trigger_mode: none teams: eui-team: access_level: MANAGE_BUILD_AND_READ @@ -384,10 +251,10 @@ spec: provider_settings: build_branches: true build_pull_requests: true - build_tags: false + build_tags: true filter_enabled: true # Allow PRs and 'main' branch updates - filter_condition: (build.pull_request.id != null || build.branch == "main") + filter_condition: (build.pull_request.id != null || build.branch == "main" || build.tag =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/) teams: eui-team: access_level: MANAGE_BUILD_AND_READ