Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (70 sloc) 2.18 KB
before_all do
ensure_git_status_clean
ENV["IP_VERSION"] = "4"
end
desc "Rebuild the static HTML"
lane :build do
require 'digest'
before = Dir["../public/**/*"].map do |f|
[f, File.file?(f) ? Digest::SHA2.hexdigest(File.read(f)) : nil]
end.to_h
sh "cd .. && hugo"
# Return changed files
Dir["../public/**/*"].select do |f|
File.file?(f) && Digest::SHA2.hexdigest(File.read(f)) != before[f]
end
end
desc "Build the required infrastructure on AWS using terraform"
lane :infra do
`cd ../infrastructure && zip -u cloudfront_lambda.zip cloudfront_lambda.js || true`
terraform(
infrastructure_folder: "infrastructure"
)
end
desc "Renew SSL certificates with certbot"
lane :ssl do
sh "cd .. && cp deps/dehytrated-config deps/dehydrated/config"
sh "mkdir -p ../public/challenge"
sh "mkdir -p ../infrastructure/letsencrypt"
sh "cd .. && deps/dehydrated/dehydrated --accept-terms --cron"
end
lane :upload do |opts|
if opts[:upload_challenge].nil?
local_folder = "public/"
remote_path = "public"
else
local_folder = "public/challenge/"
remote_path = "public/.well-known/acme-challenge"
end
bucket_name = sh "cd ../infrastructure && terraform output s3-bucket-name"
bucket_name = bucket_name.strip
upload_folder_to_s3(
region: "us-east-1",
bucket: bucket_name,
local_path: local_folder,
remote_path: remote_path,
)
end
desc "Create a Cloudfront invalidation for the distribution"
lane :invalidate_cache do |opts|
changed_files = opts[:changed].map { |f| f.sub(/^..\/public/, "") }
distribution_id = `cd ../infrastructure && terraform output distribution-id`.strip
paths = if changed_files.empty?
"/*"
else
# Need to add the base paths separately, because to cloudfront /<page>/ != /<page>/index.html
base_paths = changed_files.select { |c| c.end_with? "index.html" }.map { |i| i.sub("index.html", "") }
all_paths = changed_files + base_paths
all_paths.join(" ")
end
`aws configure set preview.cloudfront true`
`aws cloudfront create-invalidation --distribution-id #{distribution_id} --paths #{paths}`
end
desc "Publish a new version of the website"
lane :publish_site do
infra
changed = build
ssl
upload
invalidate_cache changed: changed
end
You can’t perform that action at this time.