From 8fa3f93c734ea9305e9bd5b3100816eb373b64a0 Mon Sep 17 00:00:00 2001 From: thursday Date: Mon, 23 Aug 2021 18:09:33 +0000 Subject: Update entrypoint.sh Fixed error causing Ferdi-server's Adonis APP_KEY not to be read from FERDI_APP_KEY.txt on container restart, which was causing the following error: ``` RuntimeException: E_MISSING_APP_KEY: Make sure to define appKey inside config/app.js file before using Encryption provider > More details: https://err.sh/adonisjs/errors/E_MISSING_APP_KEY RuntimeException: E_MISSING_APP_KEY: Make sure to define appKey inside config/app.js file before using Encryption provider > More details: https://err.sh/adonisjs/errors/E_MISSING_APP_KEY at Function.missingAppKey (/app/node_modules/@adonisjs/generic-exceptions/src/RuntimeException.js:54:12) at new Encryption (/app/node_modules/@adonisjs/framework/src/Encryption/index.js:33:33) at Object.closure (/app/node_modules/@adonisjs/framework/providers/AppProvider.js:257:14) at Ioc._resolveBinding (/app/node_modules/@adonisjs/fold/src/Ioc/index.js:231:68) at Ioc.make (/app/node_modules/@adonisjs/fold/src/Ioc/index.js:807:19) at /app/node_modules/@adonisjs/fold/src/Ioc/index.js:318:19 at Array.map () at Ioc._makeInstanceOf (/app/node_modules/@adonisjs/fold/src/Ioc/index.js:317:44) at Ioc.make (/app/node_modules/@adonisjs/fold/src/Ioc/index.js:799:19) at AuthManager.getScheme (/app/node_modules/@adonisjs/auth/src/Auth/Manager.js:86:16) at Auth.authenticator (/app/node_modules/@adonisjs/auth/src/Auth/index.js:118:40) at new Auth (/app/node_modules/@adonisjs/auth/src/Auth/index.js:68:39) at Context. (/app/node_modules/@adonisjs/auth/providers/AuthProvider.js:151:14) at Context.wrappedCallback [as auth] (/app/node_modules/macroable/index.js:132:61) at Server._handleException (/app/node_modules/@adonisjs/framework/src/Server/index.js:253:63) at /app/node_modules/@adonisjs/framework/src/Server/index.js:441:14 ``` --- docker/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/entrypoint.sh') diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 0679530..2d1fd89 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -18,7 +18,7 @@ EOL if [[ -f "${DATA_DIR}/FERDI_APP_KEY.txt" ]]; then echo " " echo "**** App Key found ****" - APP_KEY=$(echo "${APP_KEY}") + APP_KEY=$(cat /data/FERDI_APP_KEY.txt) echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" elif [[ -z "${APP_KEY}" ]]; then echo "**** Generating Ferdi-server app key for first run ****" -- cgit v1.2.3-70-g09d2 From d3ad6f43b9e15df91020576a042621089db2ca2f Mon Sep 17 00:00:00 2001 From: thursday Date: Thu, 16 Sep 2021 17:32:28 -0400 Subject: Update entrypoint.sh --- docker/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docker/entrypoint.sh') diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 2d1fd89..abd0ed3 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -18,7 +18,7 @@ EOL if [[ -f "${DATA_DIR}/FERDI_APP_KEY.txt" ]]; then echo " " echo "**** App Key found ****" - APP_KEY=$(cat /data/FERDI_APP_KEY.txt) + APP_KEY=$(cat "${DATA_DIR}/FERDI_APP_KEY.txt") echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" elif [[ -z "${APP_KEY}" ]]; then echo "**** Generating Ferdi-server app key for first run ****" -- cgit v1.2.3-70-g09d2 From 1122af152e71d4d353ff8de36807f8f8d1393244 Mon Sep 17 00:00:00 2001 From: thursday Date: Fri, 17 Sep 2021 08:28:46 +0000 Subject: Fixed shebang and simplfied if statement. --- docker/entrypoint.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'docker/entrypoint.sh') diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index abd0ed3..2a91839 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,6 +1,6 @@ -#!/bin/sh +#!/bin/bash -echo << EOL +cat << EOL ------------------------------------- ____ ___ / __/__ _______/ (_) @@ -15,23 +15,20 @@ https://opencollective.com/getferdi/ EOL # Create APP key if needed -if [[ -f "${DATA_DIR}/FERDI_APP_KEY.txt" ]]; then - echo " " - echo "**** App Key found ****" - APP_KEY=$(cat "${DATA_DIR}/FERDI_APP_KEY.txt") - echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" -elif [[ -z "${APP_KEY}" ]]; then +if [[ -z ${APP_KEY} && ! -f "${DATA_DIR}/FERDI_APP_KEY.txt" ]]; then echo "**** Generating Ferdi-server app key for first run ****" adonis key:generate APP_KEY=$(grep APP_KEY .env | cut -d '=' -f2) echo "${APP_KEY}" > "${DATA_DIR}/FERDI_APP_KEY.txt" echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" +else APP_KEY=$(cat "${DATA_DIR}/FERDI_APP_KEY.txt") + echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" fi export APP_KEY node ace migration:run --force -chown -R ${PUID:-1000}:${PGID:-1000} $DATA_DIR /app +chown -R "${PUID:-1000}":"${PGID:-1000}" "$DATA_DIR" /app -su-exec ${PUID:-1000}:${PGID:-1000} node server.js +su-exec "${PUID:-1000}":"${PGID:-1000}" node server.js#!/bin/bash -- cgit v1.2.3-70-g09d2 From 085916c33d28408739e0cf886d2ae4316cb92ee4 Mon Sep 17 00:00:00 2001 From: Edgars Date: Wed, 6 Oct 2021 10:52:09 +0300 Subject: Fix `docker/entrypoint.sh` `docker/entrypoint.sh` was updated to fix errors that results in a container that runs on a locally built Ferdi Server image. Fixes that were made: - shebang was changed to `#!/bin/sh` as the Node Alpine image does not have `bash`, therefore the container cannot start because of the error "/usr/local/bin/docker-entrypoint.sh: exec: line 8: /entrypoint.sh: not found"; - `if` condition was updated to make it more portable so it works with non-Bash shells; - `su-exec` command was updated to remove the redundant `#!/bin/bash` from the end of the line as it was causing the error "Error: Cannot find module '/app/server.js#!/bin/bash'". Additional code optimization changes: - tabs were replaced with spaces; - optimizations to avoid code duplication: - new variable `key_file` was added to hold the path to the Ferdi app key file; - the function `print_app_key_message` was added to print the informational message about the app key. --- docker/entrypoint.sh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'docker/entrypoint.sh') diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 2a91839..2e58abc 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh cat << EOL ------------------------------------- @@ -14,21 +14,31 @@ Support our Open Collective at: https://opencollective.com/getferdi/ EOL +key_file="${DATA_DIR}/FERDI_APP_KEY.txt" + +print_app_key_message() { + app_key=$1 + printf '**** App key is %s. ' ${app_key} + printf 'You can modify `%s` to update the app key ****\n' ${key_file} +} + # Create APP key if needed -if [[ -z ${APP_KEY} && ! -f "${DATA_DIR}/FERDI_APP_KEY.txt" ]]; then - echo "**** Generating Ferdi-server app key for first run ****" - adonis key:generate - APP_KEY=$(grep APP_KEY .env | cut -d '=' -f2) - echo "${APP_KEY}" > "${DATA_DIR}/FERDI_APP_KEY.txt" - echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" -else APP_KEY=$(cat "${DATA_DIR}/FERDI_APP_KEY.txt") - echo "**** App Key set to $APP_KEY you can modify FERDI_APP_KEY.txt to update your key ****" +if [ -z ${APP_KEY} ] && [ ! -f ${key_file} ] +then + echo '**** Generating Ferdi-server app key for first run ****' + adonis key:generate + APP_KEY=$(grep APP_KEY .env | cut -d '=' -f2) + echo ${APP_KEY} > ${key_file} + print_app_key_message ${APP_KEY} +else + APP_KEY=$(cat ${key_file}) + print_app_key_message ${APP_KEY} fi export APP_KEY node ace migration:run --force -chown -R "${PUID:-1000}":"${PGID:-1000}" "$DATA_DIR" /app +chown -R "${PUID:-1000}":"${PGID:-1000}" "${DATA_DIR}" /app -su-exec "${PUID:-1000}":"${PGID:-1000}" node server.js#!/bin/bash +su-exec "${PUID:-1000}":"${PGID:-1000}" node server.js -- cgit v1.2.3-70-g09d2