release.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env bash
  2. set -e
  3. set -o pipefail
  4. usage() {
  5. cat >&2 <<'EOF'
  6. To publish the Docker documentation you need to set your access_key and secret_key in the docs/awsconfig file
  7. (with the keys in a [profile $AWS_S3_BUCKET] section - so you can have more than one set of keys in your file)
  8. and set the AWS_S3_BUCKET env var to the name of your bucket.
  9. make AWS_S3_BUCKET=docs-stage.docker.com docs-release
  10. will then push the documentation site to your s3 bucket.
  11. EOF
  12. exit 1
  13. }
  14. [ "$AWS_S3_BUCKET" ] || usage
  15. VERSION=$(cat VERSION)
  16. if [ "$$AWS_S3_BUCKET" == "docs.docker.com" ]; then
  17. if [ "${VERSION%-dev}" != "$VERSION" ]; then
  18. echo "Please do not push '-dev' documentation to docs.docker.com ($VERSION)"
  19. exit 1
  20. fi
  21. fi
  22. # Remove the last version - 1.0.2-dev -> 1.0
  23. MAJOR_MINOR="v${VERSION%.*}"
  24. export MAJOR_MINOR
  25. export BUCKET=$AWS_S3_BUCKET
  26. export AWS_CONFIG_FILE=$(pwd)/awsconfig
  27. [ -e "$AWS_CONFIG_FILE" ] || usage
  28. export AWS_DEFAULT_PROFILE=$BUCKET
  29. echo "cfg file: $AWS_CONFIG_FILE ; profile: $AWS_DEFAULT_PROFILE"
  30. setup_s3() {
  31. echo "Create $BUCKET"
  32. # Try creating the bucket. Ignore errors (it might already exist).
  33. aws s3 mb --profile $BUCKET s3://$BUCKET 2>/dev/null || true
  34. # Check access to the bucket.
  35. echo "test $BUCKET exists"
  36. aws s3 --profile $BUCKET ls s3://$BUCKET
  37. # Make the bucket accessible through website endpoints.
  38. echo "make $BUCKET accessible as a website"
  39. #aws s3 website s3://$BUCKET --index-document index.html --error-document jsearch/index.html
  40. s3conf=$(cat s3_website.json | envsubst)
  41. echo
  42. echo $s3conf
  43. echo
  44. aws s3api --profile $BUCKET put-bucket-website --bucket $BUCKET --website-configuration "$s3conf"
  45. }
  46. build_current_documentation() {
  47. mkdocs build
  48. }
  49. upload_current_documentation() {
  50. src=site/
  51. dst=s3://$BUCKET$1
  52. echo
  53. echo "Uploading $src"
  54. echo " to $dst"
  55. echo
  56. #s3cmd --recursive --follow-symlinks --preserve --acl-public sync "$src" "$dst"
  57. #aws s3 cp --profile $BUCKET --cache-control "max-age=3600" --acl public-read "site/search_content.json" "$dst"
  58. # a really complicated way to send only the files we want
  59. # if there are too many in any one set, aws s3 sync seems to fall over with 2 files to go
  60. # versions.html_fragment
  61. endings=( json html xml css js gif png JPG ttf svg woff html_fragment )
  62. for i in ${endings[@]}; do
  63. include=""
  64. for j in ${endings[@]}; do
  65. if [ "$i" != "$j" ];then
  66. include="$include --exclude *.$j"
  67. fi
  68. done
  69. echo "uploading *.$i"
  70. run="aws s3 sync --profile $BUCKET --cache-control \"max-age=3600\" --acl public-read \
  71. $include \
  72. --exclude *.txt \
  73. --exclude *.text* \
  74. --exclude *Dockerfile \
  75. --exclude *.DS_Store \
  76. --exclude *.psd \
  77. --exclude *.ai \
  78. --exclude *.eot \
  79. --exclude *.otf \
  80. --exclude *.rej \
  81. --exclude *.rst \
  82. --exclude *.orig \
  83. --exclude *.py \
  84. $src $dst"
  85. echo "======================="
  86. #echo "$run"
  87. #echo "======================="
  88. $run
  89. done
  90. }
  91. setup_s3
  92. # Default to only building the version specific docs so we don't clober the latest by accident with old versions
  93. if [ "$BUILD_ROOT" == "yes" ]; then
  94. echo "Building root documentation"
  95. build_current_documentation
  96. upload_current_documentation
  97. fi
  98. #build again with /v1.0/ prefix
  99. sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml
  100. echo "Building the /$MAJOR_MINOR/ documentation"
  101. build_current_documentation
  102. upload_current_documentation "/$MAJOR_MINOR/"