aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/hook/deploy.rb34
1 files changed, 24 insertions, 10 deletions
diff --git a/bin/hook/deploy.rb b/bin/hook/deploy.rb
index ed63770..237bd1e 100755
--- a/bin/hook/deploy.rb
+++ b/bin/hook/deploy.rb
@@ -17,8 +17,6 @@
#
# Configuration is handled with the following environment variables:
#
-# * `DEPLOY_HTDOCS_PATH`: Required. Absolute path to `htdocs` symlink.
-# Must be in the `builds` directory to handle `webhook` permissions.
# * `DEPLOY_REPO_DIR`: Required. Absolute path to clone of upstream Git
# repository
# * `DEPLOY_BUILDS_DIR`: Required. Absolute path to directory for site
@@ -36,15 +34,19 @@ require 'json'
require 'time'
require 'fileutils'
-# pass to htdocs symlink
-HTDOCS_PATH = ENV.fetch('DEPLOY_HTDOCS_PATH')
-
# absolute path to source directory (e.g., git repo clone)
SRC_DIR = ENV.fetch('DEPLOY_REPO_DIR')
# get absolute path to builds directory from environment
BUILDS_DIR = ENV.fetch('DEPLOY_BUILDS_DIR')
+# build path to htdocs
+#
+# note: used to be pulled from DEPLOY_HTDOCS_PATH, but newer versions of
+# git are pickier about permissions so now we require this to be
+# "builds/current"
+HTDOCS_PATH = File.join('BUILDS_DIR', 'current')
+
# verify that the timestamp from the command-line is within the given
# amount of time of the current system timestamp
NUM_SECONDS = ENV.fetch('DEPLOY_SKEW_THRESHOLD', '300').to_i
@@ -52,6 +54,11 @@ NUM_SECONDS = ENV.fetch('DEPLOY_SKEW_THRESHOLD', '300').to_i
# number of site builds to keep in builds directory
BUILD_CACHE_SIZE = ENV.fetch('DEPLOY_BUILD_CACHE_SIZE', '5').to_i
+# command paths (optional)
+FLOCK = ENV.fetch('DEPLOY_FLOCK_PATH', '/usr/bin/flock')
+GIT = ENV.fetch('DEPLOY_GIT_PATH', '/usr/bin/git')
+HUGO = ENV.fetch('DEPLOY_HUGO_PATH', '/usr/bin/hugo')
+
# get current timestamp
NOW = Time.now
NOW_S = NOW.strftime('%Y%m%d-%H%M%S')
@@ -104,28 +111,34 @@ if delta > NUM_SECONDS
})
end
+# get lock, update git clone
Dir.chdir(SRC_DIR)
pull_time = timed do
# update git clone with lock
+ #
# note: we don't technically need '--rebase', but it silences a git
# default merge strategy warning
- run('/usr/bin/flock', SRC_DIR, '/usr/bin/git', 'pull', '--rebase')
+ run(FLOCK, SRC_DIR, GIT, 'pull', '--rebase')
end
# build site
hugo_time = timed do
- run('/usr/bin/hugo', '--minify', '-d', DST_DIR)
+ run(HUGO, '--minify', '-d', DST_DIR)
end
+# update htdocs symlink
+#
+# (note: HTDOCS_PATH is now always "builds/current" because recent
+# git updates are pickier about repo permissions)
link_time = timed do
- # update htdocs symlink
- # (note: this is now always "builds/current")
File.unlink(HTDOCS_PATH) if File.symlink?(HTDOCS_PATH)
File.symlink(DST_DIR, HTDOCS_PATH)
end
+# clean up builds directory
rm_time = timed do
- # get sorted list of builds, excluding the "current" symlink
+ # get sorted list of builds, excluding hidden directories and the
+ # "current" symlink
builds = Dir.entries(BUILDS_DIR).select do |name|
name !~ /\A\./ && name != 'current'
end.sort
@@ -136,6 +149,7 @@ rm_time = timed do
rms = builds.take(builds.size - BUILD_CACHE_SIZE)
puts 'rms: ' + JSON(rms)
+ # remove older builds in parallel
rms.map do |name|
Thread.new (name) do
# build absolute path to old build