Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (59 sloc) 2.22 KB
# Website hostname, used to set:
# - image and container names
# - path to web root (in /tmp directory)
# S3 bucket name
# Look up CloudFront distribution ID based on website alias
DISTRIBUTION_ID=$(shell aws cloudfront list-distributions \
--query 'DistributionList.Items[].{id:Id,a:Aliases.Items}[?contains(a,`$(WEBSITE)`)].id' \
--output text)
# Look up latest release of Hugo
# will automatically redirect
# Get Location header, and extract the version number at the end of the URL
HUGO_VERSION=$(shell curl -Is \
| grep -Fi Location \
| sed -E 's/.*tag\/v(.*)/\1/g;')
default: serve
docker build -t $(WEBSITE) . \
--build-arg HUGO=$(HUGO_VERSION) \
--build-arg WEB_DIR=/tmp/$(WEBSITE)
serve: build
@# Look up IDs of any running containers and dispose of them
@# Prepend command with a dash to ignore errors (for example, when container doesn't exist)
-docker ps --filter="name=$(WEBSITE)" -aq | xargs -n1 docker rm -f
@# --bind <- you have to set this because the default (
@# won't work and you will cry
docker run -d \
--volume `pwd`:/tmp/$(WEBSITE) \
--publish 1313:1313 \
--name $(WEBSITE) \
hugo server --bind
@# Open website in the default browser
open http://localhost:1313
@# Open local directory in VS Code
code-insiders .
@# Delete .DS_Store files, they are the bane of existence
find . -name "*.DS_Store" -type f -delete
@# Remove existing public/ directory
rm -rf public/
@# Build site
docker run --rm -it --volume `pwd`:/tmp/$(WEBSITE) $(WEBSITE) hugo
@# Upload files to S3
aws s3 sync --acl "public-read" --sse "AES256" public/ s3://$(S3_BUCKET) --exclude 'post'
@# Invalidate caches
aws cloudfront create-invalidation --distribution-id $(DISTRIBUTION_ID) --paths '/*'
@# Stop and remove container
docker stop $(WEBSITE)
docker rm $(WEBSITE)
@# Remove stopped containers
docker ps -aq -f status=exited --no-trunc | xargs docker rm
@# Remove dangling/untagged images
docker images -q -f dangling=true --no-trunc | xargs docker rmi
.PHONY: build serve edit deploy clean clean-all