2014-04-15 02:01:25 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat >&2 <<'EOF'
|
|
|
|
To publish the Docker documentation you need to set your access_key and secret_key in the docs/awsconfig file
|
|
|
|
(with the keys in a [profile $AWS_S3_BUCKET] section - so you can have more than one set of keys in your file)
|
|
|
|
and set the AWS_S3_BUCKET env var to the name of your bucket.
|
|
|
|
|
2014-10-12 23:53:16 -04:00
|
|
|
If you're publishing the current release's documentation, also set `BUILD_ROOT=yes`
|
|
|
|
|
2014-07-01 20:30:25 -04:00
|
|
|
make AWS_S3_BUCKET=docs-stage.docker.com docs-release
|
2014-04-15 02:01:25 -04:00
|
|
|
|
|
|
|
will then push the documentation site to your s3 bucket.
|
2014-10-22 21:45:21 -04:00
|
|
|
|
|
|
|
Note: you can add `OPTIONS=--dryrun` to see what will be done without sending to the server
|
2014-04-15 02:01:25 -04:00
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "$AWS_S3_BUCKET" ] || usage
|
|
|
|
|
2014-06-22 23:10:00 -04:00
|
|
|
VERSION=$(cat VERSION)
|
|
|
|
|
2014-10-22 21:45:21 -04:00
|
|
|
if [ "$AWS_S3_BUCKET" == "docs.docker.com" ]; then
|
2014-06-22 23:10:00 -04:00
|
|
|
if [ "${VERSION%-dev}" != "$VERSION" ]; then
|
|
|
|
echo "Please do not push '-dev' documentation to docs.docker.com ($VERSION)"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-10-12 23:53:16 -04:00
|
|
|
cat > ./sources/robots.txt <<'EOF'
|
|
|
|
User-agent: *
|
|
|
|
Allow: /
|
|
|
|
EOF
|
|
|
|
|
|
|
|
else
|
|
|
|
cat > ./sources/robots.txt <<'EOF'
|
|
|
|
User-agent: *
|
|
|
|
Disallow: /
|
|
|
|
EOF
|
2014-06-22 23:10:00 -04:00
|
|
|
fi
|
|
|
|
|
2014-07-21 01:51:14 -04:00
|
|
|
# Remove the last version - 1.0.2-dev -> 1.0
|
|
|
|
MAJOR_MINOR="v${VERSION%.*}"
|
|
|
|
export MAJOR_MINOR
|
|
|
|
|
2014-05-11 20:31:27 -04:00
|
|
|
export BUCKET=$AWS_S3_BUCKET
|
2014-04-15 02:01:25 -04:00
|
|
|
|
|
|
|
export AWS_CONFIG_FILE=$(pwd)/awsconfig
|
|
|
|
[ -e "$AWS_CONFIG_FILE" ] || usage
|
|
|
|
export AWS_DEFAULT_PROFILE=$BUCKET
|
|
|
|
|
|
|
|
echo "cfg file: $AWS_CONFIG_FILE ; profile: $AWS_DEFAULT_PROFILE"
|
|
|
|
|
|
|
|
setup_s3() {
|
|
|
|
echo "Create $BUCKET"
|
|
|
|
# Try creating the bucket. Ignore errors (it might already exist).
|
2014-06-17 22:38:45 -04:00
|
|
|
aws s3 mb --profile $BUCKET s3://$BUCKET 2>/dev/null || true
|
2014-04-15 02:01:25 -04:00
|
|
|
# Check access to the bucket.
|
|
|
|
echo "test $BUCKET exists"
|
2014-06-17 22:38:45 -04:00
|
|
|
aws s3 --profile $BUCKET ls s3://$BUCKET
|
2014-04-15 02:01:25 -04:00
|
|
|
# Make the bucket accessible through website endpoints.
|
|
|
|
echo "make $BUCKET accessible as a website"
|
|
|
|
#aws s3 website s3://$BUCKET --index-document index.html --error-document jsearch/index.html
|
2014-05-11 20:31:27 -04:00
|
|
|
s3conf=$(cat s3_website.json | envsubst)
|
|
|
|
echo
|
|
|
|
echo $s3conf
|
|
|
|
echo
|
2014-06-17 22:38:45 -04:00
|
|
|
aws s3api --profile $BUCKET put-bucket-website --bucket $BUCKET --website-configuration "$s3conf"
|
2014-04-15 02:01:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
build_current_documentation() {
|
|
|
|
mkdocs build
|
2015-01-24 01:35:03 -05:00
|
|
|
cd site/
|
2015-01-26 01:37:03 -05:00
|
|
|
gzip -9k -f search_content.json
|
|
|
|
cd ..
|
2014-04-15 02:01:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
upload_current_documentation() {
|
|
|
|
src=site/
|
2014-06-22 23:10:00 -04:00
|
|
|
dst=s3://$BUCKET$1
|
2014-04-15 02:01:25 -04:00
|
|
|
|
2015-01-09 15:10:54 -05:00
|
|
|
cache=max-age=3600
|
|
|
|
if [ "$NOCACHE" ]; then
|
|
|
|
cache=no-cache
|
|
|
|
fi
|
|
|
|
|
2014-04-15 02:01:25 -04:00
|
|
|
echo
|
|
|
|
echo "Uploading $src"
|
|
|
|
echo " to $dst"
|
|
|
|
echo
|
2014-06-17 22:38:45 -04:00
|
|
|
|
|
|
|
# a really complicated way to send only the files we want
|
|
|
|
# if there are too many in any one set, aws s3 sync seems to fall over with 2 files to go
|
2014-07-21 01:51:14 -04:00
|
|
|
# versions.html_fragment
|
2014-12-04 01:05:45 -05:00
|
|
|
include="--recursive --include \"*.$i\" "
|
2014-06-17 22:38:45 -04:00
|
|
|
echo "uploading *.$i"
|
2015-01-09 15:10:54 -05:00
|
|
|
run="aws s3 cp $src $dst $OPTIONS --profile $BUCKET --cache-control $cache --acl public-read $include"
|
2014-12-04 01:05:45 -05:00
|
|
|
echo "======================="
|
|
|
|
echo "$run"
|
2014-06-17 22:38:45 -04:00
|
|
|
echo "======================="
|
|
|
|
$run
|
2015-01-26 06:26:38 -05:00
|
|
|
|
|
|
|
# Make sure the search_content.json.gz file has the right content-encoding
|
2015-01-26 06:44:17 -05:00
|
|
|
aws s3 cp --profile $BUCKET --cache-control $cache --content-encoding="gzip" --acl public-read "site/search_content.json.gz" "$dst"
|
2014-04-15 02:01:25 -04:00
|
|
|
}
|
|
|
|
|
2014-12-18 01:46:43 -05:00
|
|
|
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[@]}
|
|
|
|
|
2015-01-09 15:10:54 -05:00
|
|
|
echo "aws cloudfront create-invalidation --profile $AWS_S3_BUCKET --distribution-id $DISTRIBUTION_ID --invalidation-batch '" > batchfile
|
2014-12-18 01:46:43 -05:00
|
|
|
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 "-----"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-22 21:45:21 -04:00
|
|
|
if [ "$OPTIONS" != "--dryrun" ]; then
|
|
|
|
setup_s3
|
|
|
|
fi
|
2014-07-22 05:05:18 -04:00
|
|
|
|
|
|
|
# Default to only building the version specific docs so we don't clober the latest by accident with old versions
|
|
|
|
if [ "$BUILD_ROOT" == "yes" ]; then
|
|
|
|
echo "Building root documentation"
|
|
|
|
build_current_documentation
|
|
|
|
upload_current_documentation
|
2015-01-09 15:10:54 -05:00
|
|
|
[ "$NOCACHE" ] || invalidate_cache
|
2014-07-22 05:05:18 -04:00
|
|
|
fi
|
2014-04-15 02:01:25 -04:00
|
|
|
|
2014-06-22 23:10:00 -04:00
|
|
|
#build again with /v1.0/ prefix
|
|
|
|
sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml
|
2014-07-22 05:05:18 -04:00
|
|
|
echo "Building the /$MAJOR_MINOR/ documentation"
|
2014-06-22 23:10:00 -04:00
|
|
|
build_current_documentation
|
|
|
|
upload_current_documentation "/$MAJOR_MINOR/"
|
2015-01-09 15:10:54 -05:00
|
|
|
[ "$NOCACHE" ] || invalidate_cache "/$MAJOR_MINOR"
|