Browse Source

gen random APP_KEY on first startup

Fabian Peter Hammerle 5 years ago
parent
commit
388be1e3b6
3 changed files with 21 additions and 4 deletions
  1. 2 3
      Dockerfile
  2. 1 0
      README.md
  3. 18 1
      run-koel.sh

+ 2 - 3
Dockerfile

@@ -21,9 +21,8 @@ WORKDIR /koel
 
 # In Encrypter.php line 43:
 # The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.
-RUN sed 's/^APP_KEY=$/APP_KEY=WORKAROUND_000000000000000000000/' .env.example >.env
-RUN composer install --no-interaction
-# TODO revert workaround
+RUN APP_KEY="WORKAROUND_EXACTLY_32_CHARS_LONG" \
+    composer install --no-interaction
 
 RUN yarn install
 

+ 1 - 0
README.md

@@ -19,6 +19,7 @@ $ sudo docker run --rm --interactive --tty \
     --network koel --publish=8080:8080 \
     --security-opt=no-new-privileges --cap-drop=all \
     koel
+generated random APP_KEY
 + php artisan koel:init
 ...
 App key exists -- skipping

+ 18 - 1
run-koel.sh

@@ -1,5 +1,22 @@
-set -ex
+set -e
 
+# WORKAROUND for koel:init crashing with
+# > In EncryptionServiceProvider.php line 42:
+# > No application encryption key has been specified.
+# 'php artisan key:generate' crashes the same way.
+APP_KEY_PATH=/etc/koel-app-key
+if [ ! -f $APP_KEY_PATH ]; then
+    tr -dc '0-9a-zA-Z' </dev/urandom \
+        | head -c32 >$APP_KEY_PATH
+    chmod u=rw,g=,o= $APP_KEY_PATH
+    echo generated random APP_KEY
+fi
+export APP_KEY="$(cat $APP_KEY_PATH)"
+
+set -x
+
+# TODO run non-interactively
+# TODO do not run yarn install (part of build)
 php artisan koel:init
 
 # TODO use apache or nginx https://koel.phanan.net/docs/#/?id=manually