Browse code

Merge pull request #11328 from jfrazelle/fix-docs-release-script

Fix clear cache docs release.

Jessie Frazelle authored on 2015/03/19 08:06:27
Showing 3 changed files
... ...
@@ -86,7 +86,6 @@ build: bundles
86 86
 	docker build -t "$(DOCKER_IMAGE)" .
87 87
 
88 88
 docs-build:
89
-	git fetch https://github.com/docker/docker.git docs && git diff --name-status FETCH_HEAD...HEAD -- docs > docs/changed-files
90 89
 	cp ./VERSION docs/VERSION
91 90
 	echo "$(GIT_BRANCH)" > docs/GIT_BRANCH
92 91
 #	echo "$(AWS_S3_BUCKET)" > docs/AWS_S3_BUCKET
... ...
@@ -21,6 +21,7 @@ COPY ./VERSION VERSION
21 21
 # TODO: don't do this - look at merging the yml file in build.sh
22 22
 COPY ./mkdocs.yml mkdocs.yml
23 23
 COPY ./s3_website.json s3_website.json
24
+COPY ./release.sh release.sh
24 25
 
25 26
 # Docker Swarm
26 27
 #ADD https://raw.githubusercontent.com/docker/swarm/master/docs/mkdocs.yml /docs/mkdocs-swarm.yml
27 28
new file mode 100644
... ...
@@ -0,0 +1,166 @@
0
+#!/usr/bin/env bash
1
+set -e
2
+
3
+set -o pipefail
4
+
5
+usage() {
6
+	cat >&2 <<'EOF'
7
+To publish the Docker documentation you need to set your access_key and secret_key in the docs/awsconfig file 
8
+(with the keys in a [profile $AWS_S3_BUCKET] section - so you can have more than one set of keys in your file)
9
+and set the AWS_S3_BUCKET env var to the name of your bucket.
10
+
11
+If you're publishing the current release's documentation, also set `BUILD_ROOT=yes`
12
+
13
+make AWS_S3_BUCKET=docs-stage.docker.com docs-release
14
+
15
+will then push the documentation site to your s3 bucket.
16
+
17
+ Note: you can add `OPTIONS=--dryrun` to see what will be done without sending to the server
18
+EOF
19
+	exit 1
20
+}
21
+
22
+[ "$AWS_S3_BUCKET" ] || usage
23
+
24
+VERSION=$(cat VERSION)
25
+
26
+if [ "$AWS_S3_BUCKET" == "docs.docker.com" ]; then
27
+	if [ "${VERSION%-dev}" != "$VERSION" ]; then
28
+		echo "Please do not push '-dev' documentation to docs.docker.com ($VERSION)"
29
+		exit 1
30
+	fi
31
+	cat > ./sources/robots.txt <<'EOF'
32
+User-agent: *
33
+Allow: /
34
+EOF
35
+
36
+else
37
+	cat > ./sources/robots.txt <<'EOF'
38
+User-agent: *
39
+Disallow: /
40
+EOF
41
+fi
42
+
43
+# Remove the last version - 1.0.2-dev -> 1.0
44
+MAJOR_MINOR="v${VERSION%.*}"
45
+export MAJOR_MINOR
46
+
47
+export BUCKET=$AWS_S3_BUCKET
48
+
49
+export AWS_CONFIG_FILE=$(pwd)/awsconfig
50
+[ -e "$AWS_CONFIG_FILE" ] || usage
51
+export AWS_DEFAULT_PROFILE=$BUCKET
52
+
53
+echo "cfg file: $AWS_CONFIG_FILE ; profile: $AWS_DEFAULT_PROFILE"
54
+
55
+setup_s3() {
56
+	echo "Create $BUCKET"
57
+	# Try creating the bucket. Ignore errors (it might already exist).
58
+	aws s3 mb --profile $BUCKET s3://$BUCKET 2>/dev/null || true
59
+	# Check access to the bucket.
60
+	echo "test $BUCKET exists"
61
+	aws s3 --profile $BUCKET ls s3://$BUCKET
62
+	# Make the bucket accessible through website endpoints.
63
+	echo "make $BUCKET accessible as a website"
64
+	#aws s3 website s3://$BUCKET --index-document index.html --error-document jsearch/index.html
65
+	s3conf=$(cat s3_website.json | envsubst)
66
+	echo
67
+	echo $s3conf
68
+	echo
69
+	aws s3api --profile $BUCKET put-bucket-website --bucket $BUCKET --website-configuration "$s3conf"
70
+}
71
+
72
+build_current_documentation() {
73
+	mkdocs build
74
+	cd site/
75
+	gzip -9k -f search_content.json
76
+	cd ..
77
+}
78
+
79
+upload_current_documentation() {
80
+	src=site/
81
+	dst=s3://$BUCKET$1
82
+
83
+	cache=max-age=3600
84
+	if [ "$NOCACHE" ]; then
85
+		cache=no-cache
86
+	fi
87
+
88
+	echo
89
+	echo "Uploading $src"
90
+	echo "  to $dst"
91
+	echo
92
+
93
+	# a really complicated way to send only the files we want
94
+	# if there are too many in any one set, aws s3 sync seems to fall over with 2 files to go
95
+	#  versions.html_fragment
96
+		include="--recursive --include \"*.$i\" "
97
+		echo "uploading *.$i"
98
+		run="aws s3 cp $src $dst $OPTIONS --profile $BUCKET --cache-control $cache --acl public-read $include"
99
+		echo "======================="
100
+		echo "$run"
101
+		echo "======================="
102
+		$run
103
+
104
+	# Make sure the search_content.json.gz file has the right content-encoding
105
+	aws s3 cp --profile $BUCKET --cache-control $cache --content-encoding="gzip" --acl public-read "site/search_content.json.gz" "$dst"
106
+}
107
+
108
+invalidate_cache() {
109
+	if [ "" == "$DISTRIBUTION_ID" ]; then
110
+		echo "Skipping Cloudfront cache invalidation"
111
+		return
112
+	fi
113
+
114
+	dst=$1
115
+
116
+	aws configure set preview.cloudfront true
117
+
118
+	files=$(find site/ -not -name "*.md*" -type f | sed 's/site\///g')
119
+
120
+	len=${#files[@]}
121
+
122
+	echo "aws cloudfront  create-invalidation --profile $AWS_S3_BUCKET --distribution-id $DISTRIBUTION_ID --invalidation-batch '" > batchfile
123
+	echo "{\"Paths\":{\"Quantity\":$len," >> batchfile
124
+	echo "\"Items\": [" >> batchfile
125
+
126
+	for file in "${files[@]}"
127
+	do
128
+		if [ "$file" == "${files[${#files[@]}-1]}" ]; then
129
+			comma=""
130
+		else
131
+			comma=","
132
+		fi
133
+		echo "\"$dst$file\"$comma" >> batchfile
134
+	done
135
+
136
+	echo "]}, \"CallerReference\":" >> batchfile
137
+	echo "\"$(date)\"}'" >> batchfile
138
+
139
+
140
+	echo "-----"
141
+	cat batchfile
142
+	echo "-----"
143
+	sh batchfile
144
+	echo "-----"
145
+}
146
+
147
+
148
+if [ "$OPTIONS" != "--dryrun" ]; then
149
+	setup_s3
150
+fi
151
+
152
+# Default to only building the version specific docs so we don't clober the latest by accident with old versions
153
+if [ "$BUILD_ROOT" == "yes" ]; then
154
+	echo "Building root documentation"
155
+	build_current_documentation
156
+	upload_current_documentation
157
+	[ "$NOCACHE" ] || invalidate_cache
158
+fi
159
+
160
+#build again with /v1.0/ prefix
161
+sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml
162
+echo "Building the /$MAJOR_MINOR/ documentation"
163
+build_current_documentation
164
+upload_current_documentation "/$MAJOR_MINOR/"
165
+[ "$NOCACHE" ] || invalidate_cache "/$MAJOR_MINOR"