Update site script and hookup hakyll static file deploy

Signed-off-by: Collin J. Doering <collin@rekahsoft.ca>
This commit is contained in:
Collin J. Doering 2018-12-08 22:46:54 -05:00
parent c053c6a3ed
commit 44094948cf
Signed by: rekahsoft
GPG Key ID: 7B4DEB93212B3022
4 changed files with 133 additions and 20 deletions

40
infra/Makefile Normal file
View File

@ -0,0 +1,40 @@
# Set default target for make > 3.80
.DEFAULT_GOAL := default
# Default make to the deploy target
.PHONY: default
default: deploy
SELECTED_WORKSPACE := $(shell terraform workspace show)
ENV := $(if $(ENV),$(ENV),$(SELECTED_WORKSPACE))
.PHONY: setup
setup:
ifneq ($(SELECTED_WORKSPACE),$(ENV))
ifndef CI
@terraform workspace select $(ENV)
endif
endif
.PHONY: init
init:
@terraform init
.PHONY: plan
plan: setup
@terraform plan \
$(if $(PLAN),--out $(PLAN)) \
$(if $(ENV),--var-file=$(ENV).tfvars) \
$(ARGS)
.PHONY: deploy
deploy: setup
@terraform apply \
$(if $(PLAN),$(PLAN)) \
$(ARGS)
.PHONY: destroy
destroy: setup
@terraform destroy \
$(if $(ENV),--var-file=$(ENV).tfvars) \
$(ARGS)

View File

@ -0,0 +1,3 @@
output "s3_bucket_static" {
value = "${aws_s3_bucket.static.id}"
}

105
site
View File

@ -1,13 +1,28 @@
#!/bin/bash
CONFIGURE_SITE="configure --enable-tests"
BUILD_SITE="build"
RUN_SITE="run --verbose=0 blog-rekahsoft-ca"
TEST_SITE="test --show-details=always --test-option=--color"
function run_site_only() {
[ "$SITE_ONLY" == "true" ]
}
function run_override_only() {
[ "$OVERRIDE_ONLY" == "true" ]
}
case "$1" in
-)
OVERRIDE_ONLY=true
shift
;;
--)
SITE_ONLY=true
shift
;;
esac
case "$1" in
test)
if [ "$2" == "-s" ] || [ "$2" == "--run-selenium" ]; then
if [[ "$2" == "-s" || "$2" == "--run-selenium" ]]; then
if ! type selenium &> /dev/null; then
echo "Failed to run Selenium. It must not be installed or not accessible on \$PATH!"
exit 1
@ -19,22 +34,76 @@ case "$1" in
fi
# Test site
cabal $TEST_SITE
stack test
;;
clear)
cabal clean
;;
configure)
cabal $CONFIGURE_SITE
;;
make)
cabal $BUILD_SITE
;;
init-env)
gencss)
shift
./init-env.sh "$@"
stack exec gencss -- "$@"
;;
# Override of hakyll site commands
-h|--help)
run_override_only || ! run_site_only && cat << EOF
Wraps hakyll's provided site tool to augment certain commands.
Usage:
./site [-|--] COMMAND
Available commands:
build*
clean*
deploy*
gencss
test
Hakyll site commands:
build
check
clean
deploy
preview
rebuild
server
watch
Starred (*) commands indicate a overridden hakyll site command. However once the override is
run, the corresponding hakyll command is then run. This can be disabled with by specifying '--'
as the first argument, which will then pass all remaining arguments to the hakyll site command.
Similarily, to only run the override, specify '-' as the first argument.
For more details about hakyll site commands and options, see './site -- --help'.
EOF
# Only run hakyll site --help command if override was not run
run_override_only && exit
# Only run hakyll site --help command if -- site only
run_site_only && stack exec blog-rekahsoft-ca -- --help | sed 's/\(Usage: \)blog-rekahsoft-ca/\1.\/site -/g'
;;
build)
run_override_only || ! run_site_only && stack build
run_override_only && exit $?
;;&
clean)
run_override_only || ! run_site_only && stack clean
run_override_only && exit $?
;;&
deploy)
pushd infra > /dev/null
# Only run hakyll site deploy command when site-only is given. Additionally, when
# neither site-only or override-only are given, run only the override. The deploy
# override uses terraform which is also setup to deploy the hakyll site static files
run_override_only || ! run_site_only && (
export PLAN=".plans/local-$(date +%F_%R).plan"
[ ! -d .plans ] && mkdir .plans
make plan deploy
) && exit $?
run_site_only && export S3_BUCKET="$(terraform output s3_bucket_static)"
popd > /dev/null
;;&
*)
cabal $RUN_SITE "--" "$@"
stack exec blog-rekahsoft-ca -- "$@"
;;
esac

View File

@ -89,8 +89,9 @@ pandocWriterOptions = defaultHakyllWriterOptions
myConfig :: Configuration
myConfig = defaultConfiguration
{ deployCommand = "echo '\nDeploying website...' && " ++
"aws s3 sync _site/ s3://$S3_BUCKET"
{ deployCommand = "echo 'Deploying website...' && " ++
"aws s3 sync _site/ s3://$S3_BUCKET &&" ++
"echo 'Done!'"
, previewPort = 3000
}