From fcec58441f91bf050e12630892313a87a5da3c8c Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 13 Jan 2025 09:22:00 +1100 Subject: [PATCH] Autocreate our encryption key when container starts if it isnt already set --- docker/Dockerfile | 9 +++++---- docker/init-docker | 9 ++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index b5717d5..1a877d1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,6 +8,10 @@ RUN install-php-extensions \ ldap \ memcached +RUN sed -i -e 's/^{$CADDY_EXTRA_CONFIG}$/{$CADDY_EXTRA_CONFIG} /' /etc/caddy/Caddyfile +RUN sed -i -e 's/^memory_limit = 128M/memory_limit = 1G/' /usr/local/etc/php/php.ini-production +RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini + RUN curl -4 https://getcomposer.org/installer|php -- --install-dir=/usr/local/bin --filename=composer ENV COMPOSER_HOME=/var/cache/composer @@ -23,13 +27,10 @@ RUN mkdir -p ${COMPOSER_HOME} \ && ([ -r auth.json ] && mv auth.json ${COMPOSER_HOME}) || true \ && touch .composer.refresh \ && mv .env.example .env \ - && FORCE_PERMS=1 /sbin/init-docker \ + && FORCE_PERMS=1 BUILD=1 /sbin/init-docker \ && rm -rf ${COMPOSER_HOME}/* composer.lock # Fix start up items -RUN sed -i -e 's/^{$CADDY_EXTRA_CONFIG}$/{$CADDY_EXTRA_CONFIG} /' /etc/caddy/Caddyfile -RUN sed -i -e 's/^memory_limit = 128M/memory_limit = 1G/' /usr/local/etc/php/php.ini-production -RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini RUN chown ${SITE_USER} /config/caddy /data/caddy USER ${SITE_USER} diff --git a/docker/init-docker b/docker/init-docker index 4732c72..a334d60 100755 --- a/docker/init-docker +++ b/docker/init-docker @@ -50,10 +50,11 @@ fi if [ -r artisan -a -e ${php}/.env ]; then echo "* Laravel Setup..." mp=$(mp ${php}) - echo " - [${php}] is a mount point [${mp}]" # Only adjust perms if this is an external mountpoint if [ -n "${FORCE_PERMS}" -o ${mp} -eq 0 ]; then + echo " - ${mp} is an external mount point" + if [ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ]; then echo " - Setting Permissions..." # Make sure our permissions are appropraite @@ -96,6 +97,12 @@ if [ -r artisan -a -e ${php}/.env ]; then [ -n "${FORCE_PERMS}" -o "${env}" != "local" -a -z "${SKIP_PERM}" ] && [ ${mp} -eq 0 ] && chmod g-w ${php} fi + # Generate our Encryption Key + [ -z ${BUILD} ] && [ -z ${APP_KEY} ] \ + && grep -qe '^APP_KEY=$' .env \ + && echo ' + Encryption Key auto created, replace with with "artisan key:generate --force"' \ + && ./artisan key:generate + # We only check for non mount points, in case this container has the app inside mp=$(mp ${php}) if [ ${mp} -eq 1 ]; then