-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish
executable file
·43 lines (31 loc) · 863 Bytes
/
publish
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
#!/bin/bash
#
# DESCRIPTION
# Publish content to nickolaskraus.io.
#
# USAGE
#
# publish
function usage {
echo 'usage: publish'
}
# Change directory to Terraform module
pushd "$(pwd)/tf" >/dev/null || exit
# Set S3 bucket
S3_BUCKET_ROOT=$(terraform output s3_root_id | tr -d \")
# Set CloudFront distribution ID
CF_DISTRIBUTION_ID=$(terraform output cf_distribution_id | tr -d \")
popd >/dev/null || exit
# Change directory to Hugo site
pushd "$(pwd)/site" >/dev/null || exit
# Remove static files
rm -rf "${PWD}/public"
# Build static files
hugo
# Remove files from S3
aws s3 rm "s3://${S3_BUCKET_ROOT}" --recursive
# Sync files with S3
aws s3 sync --acl "public-read" public/ "s3://${S3_BUCKET_ROOT}"
# Invalidate CloudFront cache
aws cloudfront create-invalidation --distribution-id "${CF_DISTRIBUTION_ID}" --paths "/*"
popd >/dev/null || exit