website.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # website.sh — deploys the website to materialize.com in CI.
  12. set -euo pipefail
  13. . misc/shlib/shlib.bash
  14. # Evergreen, readable shortlinks.
  15. #
  16. # The materialize.com/s/ namespace is reserved for shortlinks. The idea is that
  17. # even if we change hosting providers, or switch platforms for the marketing
  18. # website, the /s path can always be easily reserved for shortlinks.
  19. #
  20. # This is not a general-purpose URL shortener. Only evergreen content should be
  21. # added here, and only when the layer of indirection is necessary. For example,
  22. # the "bug" shortlink allows us to embed a bug reporting URL in the
  23. # materialized binary that can be updated if we ever switch away from GitHub
  24. # or change how we want bugs to be filed.
  25. declare -A shortlinks=(
  26. [bug]="https://github.com/MaterializeInc/materialize/issues/new?labels=C-bug&template=01-bug.yml"
  27. [docs]="https://materialize.com/docs"
  28. [non-materialized-error]="https://materialize.com/blog/views-indexes/"
  29. [sink-key-selection]="https://materialize.com/docs/sql/create-sink/kafka/#upsert-key-selection"
  30. [aws-connection-role-trust-policy]="https://materialize.com/docs/sql/create-connection/#permissions"
  31. [chat]="https://join.slack.com/t/materializecommunity/shared_invite/zt-36u094n7l-M_fE43Lfpy74kCyI9Ar~7w"
  32. [pricing]="https://materialize.com/pdfs/pricing.pdf"
  33. )
  34. cd doc/user
  35. if [[ "$BUILDKITE_ORGANIZATION_SLUG" == "materialize" ]] && [[ "$BUILDKITE_BRANCH" == self-managed-docs/* ]]; then
  36. VERSION=${BUILDKITE_BRANCH#self-managed-docs/}
  37. hugo --gc --baseURL "/docs/self-managed/$VERSION" --destination "public/docs/self-managed/$VERSION"
  38. else
  39. hugo --gc --baseURL /docs --destination public/docs
  40. fi
  41. hugo deploy --maxDeletes -1
  42. touch empty
  43. # Make the alias redirects into server-side redirects rather than client side
  44. # redirects.
  45. (
  46. cd public
  47. grep -lr '#HUGOALIAS' | while IFS= read -r src; do
  48. src=${src#./}
  49. dst=$(sed -nE 's/<!-- #HUGOALIAS# (.*) -->/\1/p' "$src")
  50. echo "Installing server-side redirect $src => $dst"
  51. aws s3 cp ../empty "s3://materialize-website/$src" --website-redirect "$dst"
  52. done
  53. )
  54. # NOTE(benesch): this code does not delete old shortlinks. That's fine, because
  55. # the whole point is that the shortlinks live forever.
  56. for slug in "${!shortlinks[@]}"; do
  57. # Remove the potentially existing shortlink first, otherwise the redirect does not get updated
  58. aws s3 rm "s3://materialize-website/s/$slug" || true
  59. aws s3 cp empty "s3://materialize-website/s/$slug" --website-redirect "${shortlinks[$slug]}"
  60. done
  61. # Hugo's CloudFront invalidation feature doesn't do anything smarter than
  62. # invalidating the entire distribution (and has bugs fetching AWS credentials in
  63. # recent versions), so we just do it here to make it clear that we're
  64. # invalidating the shortlinks too.
  65. AWS_PAGER="" aws cloudfront create-invalidation --distribution-id E1F8Q2NUUC41QE --paths "/*"