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-54-g00ecf