From cfaffd1ad26cf64330b87d0f99a883215b4c5a3e Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Thu, 18 Dec 2014 16:46:43 +1000 Subject: [PATCH] Add docs Cloudfront cache invalidation Signed-off-by: Sven Dowideit Docker-DCO-1.1-Signed-off-by: Sven Dowideit (github: SvenDowideit) Signed-off-by: Sven Dowideit --- Makefile | 3 ++- docs/README.md | 8 ++++--- docs/release.sh | 46 ++++++++++++++++++++++++++++++++++++ project/RELEASE-CHECKLIST.md | 7 ++++-- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 180ae314d0..43a6a11c5e 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ docs-shell: docs-build $(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 "$(DOCKER_DOCS_IMAGE)" bash docs-release: docs-build - $(DOCKER_RUN_DOCS) -e OPTIONS -e BUILD_ROOT "$(DOCKER_DOCS_IMAGE)" ./release.sh + $(DOCKER_RUN_DOCS) -e OPTIONS -e BUILD_ROOT -e DISTRIBUTION_ID "$(DOCKER_DOCS_IMAGE)" ./release.sh docs-test: docs-build $(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)" ./test.sh @@ -83,6 +83,7 @@ build: bundles docker build -t "$(DOCKER_IMAGE)" . docs-build: + git diff --name-status upstream/release..upstream/docs docs/ > docs/changed-files cp ./VERSION docs/VERSION echo "$(GIT_BRANCH)" > docs/GIT_BRANCH echo "$(AWS_S3_BUCKET)" > docs/AWS_S3_BUCKET diff --git a/docs/README.md b/docs/README.md index b3e9b32306..b730982e3c 100755 --- a/docs/README.md +++ b/docs/README.md @@ -145,11 +145,13 @@ to view your results and make sure what you published is what you wanted. When you're happy with it, publish the docs to our live site: - make AWS_S3_BUCKET=docs.docker.com BUILD_ROOT=yes docs-release + make AWS_S3_BUCKET=docs.docker.com BUILD_ROOT=yes DISTRIBUTION_ID=C2K6......FL2F docs-release Test the uncached version of the live docs at http://docs.docker.com.s3-website-us-east-1.amazonaws.com/ Note that the new docs will not appear live on the site until the cache (a complex, -distributed CDN system) is flushed. This requires someone with S3 keys. Contact Docker -(Sven Dowideit or John Costa) for assistance. +distributed CDN system) is flushed. The `make docs-release` command will do this +_if_ the `DISTRIBUTION_ID` is set to the Cloudfront distribution ID (ask the meta +team) - this will take at least 15 minutes to run and you can check its progress +with the CDN Cloudfront Chrome addin. diff --git a/docs/release.sh b/docs/release.sh index 8df8960c75..f4f6c552f9 100755 --- a/docs/release.sh +++ b/docs/release.sh @@ -97,6 +97,50 @@ upload_current_documentation() { $run } +invalidate_cache() { + if [ "" == "$DISTRIBUTION_ID" ]; then + echo "Skipping Cloudfront cache invalidation" + return + fi + + dst=$1 + + #aws cloudfront create-invalidation --profile docs.docker.com --distribution-id $DISTRIBUTION_ID --invalidation-batch '{"Paths":{"Quantity":1, "Items":["'+$file+'"]},"CallerReference":"19dec2014sventest1"}' + aws configure set preview.cloudfront true + + files=($(cat changed-files | grep 'sources/.*$' | sed -E 's#.*docs/sources##' | sed -E 's#index\.md#index.html#' | sed -E 's#\.md#/index.html#')) + files[${#files[@]}]="/index.html" + files[${#files[@]}]="/versions.html_fragment" + + len=${#files[@]} + + echo "aws cloudfront create-invalidation --profile docs.docker.com --distribution-id $DISTRIBUTION_ID --invalidation-batch '" > batchfile + echo "{\"Paths\":{\"Quantity\":$len," >> batchfile + echo "\"Items\": [" >> batchfile + + #for file in $(cat changed-files | grep 'sources/.*$' | sed -E 's#.*docs/sources##' | sed -E 's#index\.md#index.html#' | sed -E 's#\.md#/index.html#') + for file in "${files[@]}" + do + if [ "$file" == "${files[${#files[@]}-1]}" ]; then + comma="" + else + comma="," + fi + echo "\"$dst$file\"$comma" >> batchfile + done + + echo "]}, \"CallerReference\":" >> batchfile + echo "\"$(date)\"}'" >> batchfile + + + echo "-----" + cat batchfile + echo "-----" + sh batchfile + echo "-----" +} + + if [ "$OPTIONS" != "--dryrun" ]; then setup_s3 fi @@ -106,6 +150,7 @@ if [ "$BUILD_ROOT" == "yes" ]; then echo "Building root documentation" build_current_documentation upload_current_documentation + invalidate_cache fi #build again with /v1.0/ prefix @@ -113,3 +158,4 @@ sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml echo "Building the /$MAJOR_MINOR/ documentation" build_current_documentation upload_current_documentation "/$MAJOR_MINOR/" +invalidate_cache "/$MAJOR_MINOR" diff --git a/project/RELEASE-CHECKLIST.md b/project/RELEASE-CHECKLIST.md index 61b0c2b076..7eeaae8cee 100644 --- a/project/RELEASE-CHECKLIST.md +++ b/project/RELEASE-CHECKLIST.md @@ -267,14 +267,17 @@ git checkout -b docs release || git checkout docs git fetch git reset --hard origin/release git push -f origin docs -make AWS_S3_BUCKET=docs.docker.com BUILD_ROOT=yes docs-release +make AWS_S3_BUCKET=docs.docker.com BUILD_ROOT=yes DISTRIBUTION_ID=C2K6......FL2F docs-release ``` The docs will appear on http://docs.docker.com/ (though there may be cached versions, so its worth checking http://docs.docker.com.s3-website-us-east-1.amazonaws.com/). For more information about documentation releases, see `docs/README.md`. -Ask Sven, or JohnC to invalidate the cloudfront cache using the CND Planet chrome applet. +Note that the new docs will not appear live on the site until the cache (a complex, +distributed CDN system) is flushed. The `make docs-release` command will do this +_if_ the `DISTRIBUTION_ID` is set correctly - this will take at least 15 minutes to run +and you can check its progress with the CDN Cloudfront Chrome addin. ### 12. Create a new pull request to merge release back into master