Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <hugs@docker.com> (github: jfrazelle)
Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <princess@docker.com> (github: jfrazelle)
Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <jess@docker.com> (github: jfrazelle)
Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
| 1 | 1 |
old mode 100644 |
| 2 | 2 |
new mode 100755 |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-#!/usr/bin/env bash |
|
| 1 |
+#!/bin/bash |
|
| 2 | 2 |
set -e |
| 3 | 3 |
|
| 4 | 4 |
set -o pipefail |
| ... | ... |
@@ -16,57 +16,31 @@ make AWS_S3_BUCKET=docs-stage.docker.com docs-release |
| 16 | 16 |
will then push the documentation site to your s3 bucket. |
| 17 | 17 |
|
| 18 | 18 |
Note: you can add `OPTIONS=--dryrun` to see what will be done without sending to the server |
| 19 |
+ You can also add NOCACHE=1 to publish without a cache, which is what we do for the master docs. |
|
| 19 | 20 |
EOF |
| 20 | 21 |
exit 1 |
| 21 | 22 |
} |
| 22 | 23 |
|
| 23 |
-[ "$AWS_S3_BUCKET" ] || usage |
|
| 24 |
- |
|
| 25 |
-VERSION=$(cat VERSION) |
|
| 26 |
- |
|
| 27 |
-if [ "$AWS_S3_BUCKET" == "docs.docker.com" ]; then |
|
| 28 |
- if [ "${VERSION%-dev}" != "$VERSION" ]; then
|
|
| 29 |
- echo "Please do not push '-dev' documentation to docs.docker.com ($VERSION)" |
|
| 30 |
- exit 1 |
|
| 31 |
- fi |
|
| 32 |
- cat > ./sources/robots.txt <<'EOF' |
|
| 33 |
-User-agent: * |
|
| 34 |
-Allow: / |
|
| 35 |
-EOF |
|
| 36 |
- |
|
| 37 |
-else |
|
| 24 |
+create_robots_txt() {
|
|
| 38 | 25 |
cat > ./sources/robots.txt <<'EOF' |
| 39 | 26 |
User-agent: * |
| 40 | 27 |
Disallow: / |
| 41 | 28 |
EOF |
| 42 |
-fi |
|
| 43 |
- |
|
| 44 |
-# Remove the last version - 1.0.2-dev -> 1.0 |
|
| 45 |
-MAJOR_MINOR="v${VERSION%.*}"
|
|
| 46 |
-export MAJOR_MINOR |
|
| 47 |
- |
|
| 48 |
-export BUCKET=$AWS_S3_BUCKET |
|
| 49 |
- |
|
| 50 |
-export AWS_CONFIG_FILE=$(pwd)/awsconfig |
|
| 51 |
-[ -e "$AWS_CONFIG_FILE" ] || usage |
|
| 52 |
-export AWS_DEFAULT_PROFILE=$BUCKET |
|
| 53 |
- |
|
| 54 |
-echo "cfg file: $AWS_CONFIG_FILE ; profile: $AWS_DEFAULT_PROFILE" |
|
| 29 |
+} |
|
| 55 | 30 |
|
| 56 | 31 |
setup_s3() {
|
| 57 |
- echo "Create $BUCKET" |
|
| 58 | 32 |
# Try creating the bucket. Ignore errors (it might already exist). |
| 33 |
+ echo "create $BUCKET if it does not exist" |
|
| 59 | 34 |
aws s3 mb --profile $BUCKET s3://$BUCKET 2>/dev/null || true |
| 35 |
+ |
|
| 60 | 36 |
# Check access to the bucket. |
| 61 | 37 |
echo "test $BUCKET exists" |
| 62 | 38 |
aws s3 --profile $BUCKET ls s3://$BUCKET |
| 39 |
+ |
|
| 63 | 40 |
# Make the bucket accessible through website endpoints. |
| 64 | 41 |
echo "make $BUCKET accessible as a website" |
| 65 | 42 |
#aws s3 website s3://$BUCKET --index-document index.html --error-document jsearch/index.html |
| 66 |
- s3conf=$(cat s3_website.json | envsubst) |
|
| 67 |
- echo |
|
| 68 |
- echo $s3conf |
|
| 69 |
- echo |
|
| 43 |
+ local s3conf=$(cat s3_website.json | envsubst) |
|
| 70 | 44 |
aws s3api --profile $BUCKET put-bucket-website --bucket $BUCKET --website-configuration "$s3conf" |
| 71 | 45 |
} |
| 72 | 46 |
|
| ... | ... |
@@ -86,28 +60,22 @@ upload_current_documentation() {
|
| 86 | 86 |
cache=no-cache |
| 87 | 87 |
fi |
| 88 | 88 |
|
| 89 |
- echo |
|
| 90 |
- echo "Uploading $src" |
|
| 91 |
- echo " to $dst" |
|
| 92 |
- echo |
|
| 89 |
+ printf "\nUploading $src to $dst\n" |
|
| 93 | 90 |
|
| 94 | 91 |
# a really complicated way to send only the files we want |
| 95 | 92 |
# if there are too many in any one set, aws s3 sync seems to fall over with 2 files to go |
| 96 | 93 |
# versions.html_fragment |
| 97 |
- include="--recursive --include \"*.$i\" " |
|
| 98 |
- echo "uploading *.$i" |
|
| 99 |
- run="aws s3 cp $src $dst $OPTIONS --profile $BUCKET --cache-control $cache --acl public-read $include" |
|
| 100 |
- echo "=======================" |
|
| 101 |
- echo "$run" |
|
| 102 |
- echo "=======================" |
|
| 103 |
- $run |
|
| 94 |
+ include="--recursive --include \"*.$i\" " |
|
| 95 |
+ run="aws s3 cp $src $dst $OPTIONS --profile $BUCKET --cache-control $cache --acl public-read $include" |
|
| 96 |
+ printf "\n=====\n$run\n=====\n" |
|
| 97 |
+ $run |
|
| 104 | 98 |
|
| 105 | 99 |
# Make sure the search_content.json.gz file has the right content-encoding |
| 106 | 100 |
aws s3 cp --profile $BUCKET --cache-control $cache --content-encoding="gzip" --acl public-read "site/search_content.json.gz" "$dst" |
| 107 | 101 |
} |
| 108 | 102 |
|
| 109 | 103 |
invalidate_cache() {
|
| 110 |
- if [ "" == "$DISTRIBUTION_ID" ]; then |
|
| 104 |
+ if [[ -z "$DISTRIBUTION_ID" ]]; then |
|
| 111 | 105 |
echo "Skipping Cloudfront cache invalidation" |
| 112 | 106 |
return |
| 113 | 107 |
fi |
| ... | ... |
@@ -116,17 +84,20 @@ invalidate_cache() {
|
| 116 | 116 |
|
| 117 | 117 |
aws configure set preview.cloudfront true |
| 118 | 118 |
|
| 119 |
- files=$(find site/ -not -name "*.md*" -type f | sed 's/site\///g') |
|
| 119 |
+ # Get all the files |
|
| 120 |
+ # not .md~ files |
|
| 121 |
+ # replace spaces w %20 so urlencoded |
|
| 122 |
+ files=( $(find site/ -not -name "*.md*" -type f | sed 's/site//g' | sed 's/ /%20/g') ) |
|
| 120 | 123 |
|
| 121 | 124 |
len=${#files[@]}
|
| 125 |
+ last_file=${files[$((len-1))]}
|
|
| 122 | 126 |
|
| 123 | 127 |
echo "aws cloudfront create-invalidation --profile $AWS_S3_BUCKET --distribution-id $DISTRIBUTION_ID --invalidation-batch '" > batchfile |
| 124 | 128 |
echo "{\"Paths\":{\"Quantity\":$len," >> batchfile
|
| 125 | 129 |
echo "\"Items\": [" >> batchfile |
| 126 | 130 |
|
| 127 |
- for file in "${files[@]}"
|
|
| 128 |
- do |
|
| 129 |
- if [ "$file" == "${files[${#files[@]}-1]}" ]; then
|
|
| 131 |
+ for file in "${files[@]}" ; do
|
|
| 132 |
+ if [[ $file == $last_file ]]; then |
|
| 130 | 133 |
comma="" |
| 131 | 134 |
else |
| 132 | 135 |
comma="," |
| ... | ... |
@@ -134,33 +105,65 @@ invalidate_cache() {
|
| 134 | 134 |
echo "\"$dst$file\"$comma" >> batchfile |
| 135 | 135 |
done |
| 136 | 136 |
|
| 137 |
- echo "]}, \"CallerReference\":" >> batchfile |
|
| 138 |
- echo "\"$(date)\"}'" >> batchfile |
|
| 137 |
+ echo "]}, \"CallerReference\":\"$(date)\"}'" >> batchfile |
|
| 139 | 138 |
|
| 140 |
- |
|
| 141 |
- echo "-----" |
|
| 142 |
- cat batchfile |
|
| 143 |
- echo "-----" |
|
| 144 | 139 |
sh batchfile |
| 145 |
- echo "-----" |
|
| 146 | 140 |
} |
| 147 | 141 |
|
| 142 |
+main() {
|
|
| 143 |
+ [ "$AWS_S3_BUCKET" ] || usage |
|
| 144 |
+ |
|
| 145 |
+ # Make sure there is an awsconfig file |
|
| 146 |
+ export AWS_CONFIG_FILE=$(pwd)/awsconfig |
|
| 147 |
+ [ -f "$AWS_CONFIG_FILE" ] || usage |
|
| 148 | 148 |
|
| 149 |
-if [ "$OPTIONS" != "--dryrun" ]; then |
|
| 150 |
- setup_s3 |
|
| 151 |
-fi |
|
| 149 |
+ # Get the version |
|
| 150 |
+ VERSION=$(cat VERSION) |
|
| 152 | 151 |
|
| 153 |
-# Default to only building the version specific docs so we don't clober the latest by accident with old versions |
|
| 154 |
-if [ "$BUILD_ROOT" == "yes" ]; then |
|
| 155 |
- echo "Building root documentation" |
|
| 152 |
+ # Disallow pushing dev docs to master |
|
| 153 |
+ if [ "$AWS_S3_BUCKET" == "docs.docker.com" ] && [ "${VERSION%-dev}" != "$VERSION" ]; then
|
|
| 154 |
+ echo "Please do not push '-dev' documentation to docs.docker.com ($VERSION)" |
|
| 155 |
+ exit 1 |
|
| 156 |
+ fi |
|
| 157 |
+ |
|
| 158 |
+ # Clean version - 1.0.2-dev -> 1.0 |
|
| 159 |
+ export MAJOR_MINOR="v${VERSION%.*}"
|
|
| 160 |
+ |
|
| 161 |
+ export BUCKET=$AWS_S3_BUCKET |
|
| 162 |
+ export AWS_DEFAULT_PROFILE=$BUCKET |
|
| 163 |
+ |
|
| 164 |
+ # debug variables |
|
| 165 |
+ echo "bucket: $BUCKET, full version: $VERSION, major-minor: $MAJOR_MINOR" |
|
| 166 |
+ echo "cfg file: $AWS_CONFIG_FILE ; profile: $AWS_DEFAULT_PROFILE" |
|
| 167 |
+ |
|
| 168 |
+ # create the robots.txt |
|
| 169 |
+ create_robots_txt |
|
| 170 |
+ |
|
| 171 |
+ if [ "$OPTIONS" != "--dryrun" ]; then |
|
| 172 |
+ setup_s3 |
|
| 173 |
+ fi |
|
| 174 |
+ |
|
| 175 |
+ # Default to only building the version specific docs |
|
| 176 |
+ # so we don't clober the latest by accident with old versions |
|
| 177 |
+ if [ "$BUILD_ROOT" == "yes" ]; then |
|
| 178 |
+ echo "Building root documentation" |
|
| 179 |
+ build_current_documentation |
|
| 180 |
+ |
|
| 181 |
+ echo "Uploading root documentation" |
|
| 182 |
+ upload_current_documentation |
|
| 183 |
+ [ "$NOCACHE" ] || invalidate_cache |
|
| 184 |
+ fi |
|
| 185 |
+ |
|
| 186 |
+ #build again with /v1.0/ prefix |
|
| 187 |
+ sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml |
|
| 188 |
+ echo "Building the /$MAJOR_MINOR/ documentation" |
|
| 156 | 189 |
build_current_documentation |
| 157 |
- upload_current_documentation |
|
| 158 |
- [ "$NOCACHE" ] || invalidate_cache |
|
| 159 |
-fi |
|
| 160 |
- |
|
| 161 |
-#build again with /v1.0/ prefix |
|
| 162 |
-sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml |
|
| 163 |
-echo "Building the /$MAJOR_MINOR/ documentation" |
|
| 164 |
-build_current_documentation |
|
| 165 |
-upload_current_documentation "/$MAJOR_MINOR/" |
|
| 166 |
-[ "$NOCACHE" ] || invalidate_cache "/$MAJOR_MINOR" |
|
| 190 |
+ |
|
| 191 |
+ echo "Uploading the documentation" |
|
| 192 |
+ upload_current_documentation "/$MAJOR_MINOR/" |
|
| 193 |
+ |
|
| 194 |
+ # Invalidating cache |
|
| 195 |
+ [ "$NOCACHE" ] || invalidate_cache "/$MAJOR_MINOR" |
|
| 196 |
+} |
|
| 197 |
+ |
|
| 198 |
+main |