Browse Source

Merge pull request #9721 from SvenDowideit/add-cloudfront-invalidation-to-docs

Add docs Cloudfront cache invalidation
Michael Crosby 10 years ago
parent
commit
4235e2796b
4 changed files with 58 additions and 6 deletions
  1. 2 1
      Makefile
  2. 5 3
      docs/README.md
  3. 46 0
      docs/release.sh
  4. 5 2
      project/RELEASE-CHECKLIST.md

+ 2 - 1
Makefile

@@ -53,7 +53,7 @@ docs-shell: docs-build
 	$(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 "$(DOCKER_DOCS_IMAGE)" bash
 	$(DOCKER_RUN_DOCS) -p $(if $(DOCSPORT),$(DOCSPORT):)8000 "$(DOCKER_DOCS_IMAGE)" bash
 
 
 docs-release: docs-build
 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
 docs-test: docs-build
 	$(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)" ./test.sh
 	$(DOCKER_RUN_DOCS) "$(DOCKER_DOCS_IMAGE)" ./test.sh
@@ -83,6 +83,7 @@ build: bundles
 	docker build -t "$(DOCKER_IMAGE)" .
 	docker build -t "$(DOCKER_IMAGE)" .
 
 
 docs-build:
 docs-build:
+	git diff --name-status upstream/release..upstream/docs docs/ > docs/changed-files
 	cp ./VERSION docs/VERSION
 	cp ./VERSION docs/VERSION
 	echo "$(GIT_BRANCH)" > docs/GIT_BRANCH
 	echo "$(GIT_BRANCH)" > docs/GIT_BRANCH
 	echo "$(AWS_S3_BUCKET)" > docs/AWS_S3_BUCKET
 	echo "$(AWS_S3_BUCKET)" > docs/AWS_S3_BUCKET

+ 5 - 3
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:
 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/
 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,
 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.
 
 

+ 46 - 0
docs/release.sh

@@ -97,6 +97,50 @@ upload_current_documentation() {
 		$run
 		$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
 if [ "$OPTIONS" != "--dryrun" ]; then
 	setup_s3
 	setup_s3
 fi
 fi
@@ -106,6 +150,7 @@ if [ "$BUILD_ROOT" == "yes" ]; then
 	echo "Building root documentation"
 	echo "Building root documentation"
 	build_current_documentation
 	build_current_documentation
 	upload_current_documentation
 	upload_current_documentation
+	invalidate_cache
 fi
 fi
 
 
 #build again with /v1.0/ prefix
 #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"
 echo "Building the /$MAJOR_MINOR/ documentation"
 build_current_documentation
 build_current_documentation
 upload_current_documentation "/$MAJOR_MINOR/"
 upload_current_documentation "/$MAJOR_MINOR/"
+invalidate_cache "/$MAJOR_MINOR"

+ 5 - 2
project/RELEASE-CHECKLIST.md

@@ -267,14 +267,17 @@ git checkout -b docs release || git checkout docs
 git fetch
 git fetch
 git reset --hard origin/release
 git reset --hard origin/release
 git push -f origin docs
 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
 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/).
 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`.
 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
 ### 12. Create a new pull request to merge release back into master