forked from linode/docs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy_to_object_storage.sh
executable file
·44 lines (36 loc) · 2.68 KB
/
deploy_to_object_storage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Usage:
# OBJ_ACCESS_KEY=<an OBJ access key> OBJ_SECRET_KEY=<an OBJ secret key> DEPLOY_SUFFIX=-suffix-for-obj-bucket-name ./deploy_to_object_storage.sh
#
# This script builds the site into `public/`, and then syncs the contents of that
# folder to the `/docs/` directory of an object storage bucket.
#
# The name of the bucket will be of the form `linodedocs$DEPLOY_SUFFIX`, where
# `DEPLOY_SUFFIX` is passed as an environment variable.
# For example, setting `DEPLOY_SUFFIX=-latestrelease` will deploy to our production
# Object Storage bucket, which is `linodedocs-latestrelease`, in the us-east cluster.
#
# Lastly, it calls the `generate_permanent_redirects.sh` script to set 301 redirects
# for each page generated by Hugo's `aliases` frontmatter.
#
# A future iteration of this will use Terraform to create the bucket if it doesn't
# exist already. Until then, you will need to create the bucket ahead of time.
set -euo pipefail
[[ -z "${OBJ_ACCESS_KEY}" ]] && { echo "Please specify OBJ_ACCESS_KEY env variable"; exit 1; }
[[ -z "${OBJ_SECRET_KEY}" ]] && { echo "Please specify OBJ_SECRET_KEY env variable"; exit 1; }
[[ -z "${DEPLOY_SUFFIX}" ]] && { echo "Please specify DEPLOY_SUFFIX env variable"; exit 1; }
cd ..
rm -rf public/
hugo
# Configure the bucket as a website, just in case it isn't already
s3cmd --config=$(pwd)/scripts/.s3cfg --access_key=$OBJ_ACCESS_KEY --secret_key=$OBJ_SECRET_KEY ws-create --ws-index=index.html --ws-error=404.html s3://linodedocs$DEPLOY_SUFFIX
# Sync these first, but don't delete the previous files, because there will be pages that rely on them
s3cmd --config=$(pwd)/scripts/.s3cfg --access_key=$OBJ_ACCESS_KEY --secret_key=$OBJ_SECRET_KEY --no-mime-magic --acl-public sync public/css/ s3://linodedocs$DEPLOY_SUFFIX/docs/css/
s3cmd --config=$(pwd)/scripts/.s3cfg --access_key=$OBJ_ACCESS_KEY --secret_key=$OBJ_SECRET_KEY --no-mime-magic --acl-public sync public/js/ s3://linodedocs$DEPLOY_SUFFIX/docs/js/
s3cmd --config=$(pwd)/scripts/.s3cfg --access_key=$OBJ_ACCESS_KEY --secret_key=$OBJ_SECRET_KEY --no-mime-magic --acl-public sync public/jslibs/ s3://linodedocs$DEPLOY_SUFFIX/docs/jslibs/
s3cmd --config=$(pwd)/scripts/.s3cfg --access_key=$OBJ_ACCESS_KEY --secret_key=$OBJ_SECRET_KEY --no-mime-magic --acl-public sync public/images/ s3://linodedocs$DEPLOY_SUFFIX/docs/images/
# Sync the other pages
s3cmd --config=$(pwd)/scripts/.s3cfg --access_key=$OBJ_ACCESS_KEY --secret_key=$OBJ_SECRET_KEY --no-mime-magic --acl-public --exclude 'public/css/*' --exclude 'public/js/*' --exclude 'public/jslibs/*' --exclude 'public/images/*' sync public/ s3://linodedocs$DEPLOY_SUFFIX/docs/
# Generate the 301 permanent redirectscd scripts
cd scripts
./generate_permanent_redirects.sh