github.com/stchris/docker@v1.4.2-0.20150106053530-1510a324dbd5/docs/release.sh (about) 1 #!/usr/bin/env bash 2 set -e 3 4 set -o pipefail 5 6 usage() { 7 cat >&2 <<'EOF' 8 To publish the Docker documentation you need to set your access_key and secret_key in the docs/awsconfig file 9 (with the keys in a [profile $AWS_S3_BUCKET] section - so you can have more than one set of keys in your file) 10 and set the AWS_S3_BUCKET env var to the name of your bucket. 11 12 If you're publishing the current release's documentation, also set `BUILD_ROOT=yes` 13 14 make AWS_S3_BUCKET=docs-stage.docker.com docs-release 15 16 will then push the documentation site to your s3 bucket. 17 18 Note: you can add `OPTIONS=--dryrun` to see what will be done without sending to the server 19 EOF 20 exit 1 21 } 22 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 38 cat > ./sources/robots.txt <<'EOF' 39 User-agent: * 40 Disallow: / 41 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" 55 56 setup_s3() { 57 echo "Create $BUCKET" 58 # Try creating the bucket. Ignore errors (it might already exist). 59 aws s3 mb --profile $BUCKET s3://$BUCKET 2>/dev/null || true 60 # Check access to the bucket. 61 echo "test $BUCKET exists" 62 aws s3 --profile $BUCKET ls s3://$BUCKET 63 # Make the bucket accessible through website endpoints. 64 echo "make $BUCKET accessible as a website" 65 #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 70 aws s3api --profile $BUCKET put-bucket-website --bucket $BUCKET --website-configuration "$s3conf" 71 } 72 73 build_current_documentation() { 74 mkdocs build 75 } 76 77 upload_current_documentation() { 78 src=site/ 79 dst=s3://$BUCKET$1 80 81 echo 82 echo "Uploading $src" 83 echo " to $dst" 84 echo 85 #s3cmd --recursive --follow-symlinks --preserve --acl-public sync "$src" "$dst" 86 #aws s3 cp --profile $BUCKET --cache-control "max-age=3600" --acl public-read "site/search_content.json" "$dst" 87 88 # a really complicated way to send only the files we want 89 # if there are too many in any one set, aws s3 sync seems to fall over with 2 files to go 90 # versions.html_fragment 91 include="--recursive --include \"*.$i\" " 92 echo "uploading *.$i" 93 run="aws s3 cp $src $dst $OPTIONS --profile $BUCKET --cache-control \"max-age=3600\" --acl public-read $include" 94 echo "=======================" 95 echo "$run" 96 echo "=======================" 97 $run 98 } 99 100 invalidate_cache() { 101 if [ "" == "$DISTRIBUTION_ID" ]; then 102 echo "Skipping Cloudfront cache invalidation" 103 return 104 fi 105 106 dst=$1 107 108 #aws cloudfront create-invalidation --profile docs.docker.com --distribution-id $DISTRIBUTION_ID --invalidation-batch '{"Paths":{"Quantity":1, "Items":["'+$file+'"]},"CallerReference":"19dec2014sventest1"}' 109 aws configure set preview.cloudfront true 110 111 files=($(cat changed-files | grep 'sources/.*$' | sed -E 's#.*docs/sources##' | sed -E 's#index\.md#index.html#' | sed -E 's#\.md#/index.html#')) 112 files[${#files[@]}]="/index.html" 113 files[${#files[@]}]="/versions.html_fragment" 114 115 len=${#files[@]} 116 117 echo "aws cloudfront create-invalidation --profile docs.docker.com --distribution-id $DISTRIBUTION_ID --invalidation-batch '" > batchfile 118 echo "{\"Paths\":{\"Quantity\":$len," >> batchfile 119 echo "\"Items\": [" >> batchfile 120 121 #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#') 122 for file in "${files[@]}" 123 do 124 if [ "$file" == "${files[${#files[@]}-1]}" ]; then 125 comma="" 126 else 127 comma="," 128 fi 129 echo "\"$dst$file\"$comma" >> batchfile 130 done 131 132 echo "]}, \"CallerReference\":" >> batchfile 133 echo "\"$(date)\"}'" >> batchfile 134 135 136 echo "-----" 137 cat batchfile 138 echo "-----" 139 sh batchfile 140 echo "-----" 141 } 142 143 144 if [ "$OPTIONS" != "--dryrun" ]; then 145 setup_s3 146 fi 147 148 # Default to only building the version specific docs so we don't clober the latest by accident with old versions 149 if [ "$BUILD_ROOT" == "yes" ]; then 150 echo "Building root documentation" 151 build_current_documentation 152 upload_current_documentation 153 invalidate_cache 154 fi 155 156 #build again with /v1.0/ prefix 157 sed -i "s/^site_url:.*/site_url: \/$MAJOR_MINOR\//" mkdocs.yml 158 echo "Building the /$MAJOR_MINOR/ documentation" 159 build_current_documentation 160 upload_current_documentation "/$MAJOR_MINOR/" 161 invalidate_cache "/$MAJOR_MINOR"