From efdb3ff9cf5af6ae86797c9eab71b1287f0d6168 Mon Sep 17 00:00:00 2001
From: Radon Rosborough <69264599+raxod502-plaid@users.noreply.github.com>
Date: Mon, 16 May 2022 09:46:29 -0700
Subject: [PATCH] Implement runWithUser/fsGroup within entrypoint (#1326)

Addresses https://github.com/runatlantis/helm-charts/issues/14
---
 docker-entrypoint.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 5936a09a19..240560f2ff 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -3,6 +3,14 @@ set -e
 
 # Modified: https://github.com/hashicorp/docker-consul/blob/2c2873f9d619220d1eef0bc46ec78443f55a10b5/0.X/docker-entrypoint.sh
 
+# https://github.com/runatlantis/helm-charts/issues/14
+if [ -d /atlantis-data -a "$(stat -c %U:%G /atlantis-data 2>/dev/null)" != atlantis:atlantis ]; then
+    echo "docker-entrypoint.sh: detected /atlantis-data wrong filesystem permissions" >&2
+    echo "currently owned by $(stat -c %U:%G /atlantis-data 2>/dev/null), changing to atlantis:atlantis..." >&2
+    chown -R atlantis:atlantis /atlantis-data
+    echo "docker-entrypoint.sh: finished changing /atlantis-data filesystem permissions" >&2
+fi
+
 # If the user is trying to run atlantis directly with some arguments, then
 # pass them to atlantis.
 if [ "${1:0:1}" = '-' ]; then