aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docker-entrypoint.sh
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-05-06 15:44:59 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-05-06 16:21:53 +0300
commitb05b07345084c415e6da431a5e247ac9afa09065 (patch)
tree8e1b98cef39de780e07fd0108e8f3aebdfd39d04 /docker-entrypoint.sh
parentset up GitHub Actions (diff)
downloadjekyll-docker-b05b07345084c415e6da431a5e247ac9afa09065.tar.gz
jekyll-docker-b05b07345084c415e6da431a5e247ac9afa09065.zip
fix GitHub action tests
That's a messy commit, but it required a lot of changes to get everything right. * Docker: create user jekyll with UID/GID that match the user that built the image (for seamless writes to /project). * Docker: run the container by the current user for the same purpose. * Docker: add an ENTRYPOINT to drop root privileges & check if the running user is the same as the one who built the image. * Jekyll: use --drafts. * Makefile: add docker/logs. As a side note, Docker + non-root users + bind mounts are a pain, I even wrote a blog post to make sense of it all: https://egor-tensin.github.io/blog/2020/05/06/docker-bind-mounts.html
Diffstat (limited to 'docker-entrypoint.sh')
-rwxr-xr-xdocker-entrypoint.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
new file mode 100755
index 0000000..4b4fb4d
--- /dev/null
+++ b/docker-entrypoint.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+# We make sure that the container is run by the same user as the one who built
+# the image (so that /project is seamlessly writable).
+# Unless, of course, the image was built by root, in which case we fall back
+# to a custom user with UID 999.
+
+set -o errexit -o nounset -o pipefail
+
+echo 'User info:'
+id
+uid="$( id -u )"
+gid="$( id -g )"
+
+if [ "$uid" = 0 ]; then
+ echo 'Going to run as jekyll instead of root, fixing /project permissions...'
+ chown -R -- jekyll:jekyll /project
+ exec gosu jekyll "$0" "$@"
+fi
+
+if [ "$uid" != "$JEKYLL_UID" ] && [ "$JEKYLL_UID" != 0 ]; then
+ echo "User jekyll was created with ID $JEKYLL_UID, are you sure you want to run the container with UID $uid?"
+ exit 1
+fi
+
+if [ "$gid" != "$JEKYLL_GID" ] && [ "$JEKYLL_GID" != 0 ]; then
+ echo "Group jekyll was created with ID $JEKYLL_GID, are you sure you want to run the container with GID $gid?"
+ exit 1
+fi
+
+echo "The container is running with UID $uid and GID $gid, just as planned..."
+exec "$@"