diff --git a/Makefile b/Makefile index 5c2ec67..65cbfbc 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,8 @@ # Website hostname, used to set: # - image and container names # - path to web root (in /tmp directory) -WEBSITE=bdebyl.net +WEB_BUCKET=bdebyl.net +STATIC_BUCKET=bdebyl.static STATIC_DIR=static HUGO_IMAGE_NAME=bdebyl/hugo @@ -25,41 +26,55 @@ DOCKER_RUN=docker run --rm ${RUN_USER} ${RUN_VOL} # Look up CloudFront distribution ID based on website alias DISTRIBUTION_ID=$(shell docker run --rm ${AWS_ENV} ${AWS_IMAGE} cloudfront list-distributions \ - --query 'DistributionList.Items[].{id:Id,a:Aliases.Items}[?contains(a,`${WEBSITE}`)].id' \ + --query 'DistributionList.Items[].{id:Id,a:Aliases.Items}[?contains(a,`${WEB_BUCKET}`)].id' \ --output text) -S3_CMD=s3 sync --acl "public-read" --sse "AES256" public/ s3://${WEBSITE} +S3_CMD=s3 sync --acl "public-read" --sse "AES256" public/ s3://${WEB_BUCKET} CLOUDFRONT_CMD=cloudfront create-invalidation --distribution-id ${DISTRIBUTION_ID} --paths '/*' +all: build + build: $(DOCKER_RUN) ${HUGO_IMAGE} +.PHONY: build -mount: - if [ ! -d "${STATIC_DIR}/static" ]; then aws s3 sync s3://bdebyl.static static/; fi +static-pull: + if [ ! -d "${STATIC_DIR}/static" ]; then aws s3 sync s3://${STATIC_BUCKET} ${STATIC_DIR}/; fi +.PHONY: static-pull -unmount: - if [ -d "${STATIC_DIR}/static" ]; then rm -rfv static/ +static-push: + aws s3 sync --acl "public-read" --sse "AES256" s3://${STATIC_BUCKET} ${STATIC_DIR}/ +.PHONY: static-push -run: +run: static-pull -$(DOCKER_RUN) -it ${DOCKER_PORT} ${HUGO_IMAGE} -D server --bind=0.0.0.0 +.PHONY: run version: $(DOCKER_RUN) ${HUGO_IMAGE} version +.PHONY: version new: $(DOCKER_RUN) ${HUGO_IMAGE} new post/$(shell read -p "Post Name (i.e. my_post.md): " pn; echo $$pn) +.PHONY: new clean: @# Clean up existing generated site rm -rf public/ resources/ +.PHONY: clean + +static-clean: + if [ -d "${STATIC_DIR}/static" ]; then rm -rfv static/ +.PHONY: static-clean deploy: clean build @# Upload files to S3 @$(DOCKER_RUN) ${AWS_ENV} ${AWS_IMAGE} ${S3_CMD} +.PHONY: deploy cache: @# Invalidate caches @$(DOCKER_RUN) ${AWS_ENV} ${AWS_IMAGE} ${CLOUDFRONT_CMD} +.PHONY: cache # Default target for make (<=3.80) -.PHONY: static mount unmount build _run run version new clean deploy cache default: build