Skip to content

Commit 889ac24

Browse files
committed
prompt for APP_KEY if not set
1 parent cd9ff39 commit 889ac24

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

Diff for: docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ services:
2525
- DB_USERNAME=postgres
2626
- DB_PASSWORD=postgres
2727
- DB_PREFIX=chq_
28+
- APP_KEY=${APP_KEY:-null}
2829
- DEBUG=true
2930
depends_on:
3031
- postgres

Diff for: entrypoint.sh

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
[[ $DEBUG == true ]] && set -x
4+
[[ "${DEBUG}" == true ]] && set -x
55

66
check_database_connection() {
77
echo "Attempting to connect to database ..."
8-
case ${DB_DRIVER} in
8+
case "${DB_DRIVER}" in
99
mysql)
1010
prog="mysqladmin -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD:+-p$DB_PASSWORD} status"
1111
;;
@@ -18,7 +18,7 @@ check_database_connection() {
1818
while ! ${prog} >/dev/null 2>&1
1919
do
2020
timeout=$(( $timeout - 1 ))
21-
if [[ $timeout -eq 0 ]]; then
21+
if [[ "$timeout" -eq 0 ]]; then
2222
echo
2323
echo "Could not connect to database server! Aborting..."
2424
exit 1
@@ -31,9 +31,9 @@ check_database_connection() {
3131

3232
checkdbinitmysql() {
3333
table=sessions
34-
if [ "$(mysql -N -s -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD:+-p$DB_PASSWORD} ${DB_DATABASE} -e \
34+
if [[ "$(mysql -N -s -h ${DB_HOST} -u ${DB_USERNAME} ${DB_PASSWORD:+-p$DB_PASSWORD} ${DB_DATABASE} -e \
3535
"select count(*) from information_schema.tables where \
36-
table_schema='${DB_DATABASE}' and table_name='${DB_PREFIX}${table}';")" -eq 1 ]; then
36+
table_schema='${DB_DATABASE}' and table_name='${DB_PREFIX}${table}';")" -eq 1 ]]; then
3737
echo "Table ${DB_PREFIX}${table} exists! ..."
3838
else
3939
echo "Table ${DB_PREFIX}${table} does not exist! ..."
@@ -45,7 +45,7 @@ checkdbinitmysql() {
4545
checkdbinitpsql() {
4646
table=sessions
4747
export PGPASSWORD=${DB_PASSWORD}
48-
if [ "$(psql -h ${DB_HOST} -U ${DB_USERNAME} -d ${DB_DATABASE} -c "SELECT to_regclass('${DB_PREFIX}${table}');" | grep -c "${DB_PREFIX}${table}")" -eq 1 ]; then
48+
if [[ "$(psql -h ${DB_HOST} -U ${DB_USERNAME} -d ${DB_DATABASE} -c "SELECT to_regclass('${DB_PREFIX}${table}');" | grep -c "${DB_PREFIX}${table}")" -eq 1 ]]; then
4949
echo "Table ${DB_PREFIX}${table} exists! ..."
5050
else
5151
echo "Table ${DB_PREFIX}${table} does not exist! ..."
@@ -55,7 +55,7 @@ checkdbinitpsql() {
5555
}
5656

5757
check_configured() {
58-
case ${DB_DRIVER} in
58+
case "${DB_DRIVER}" in
5959
mysql)
6060
checkdbinitmysql
6161
;;
@@ -68,6 +68,7 @@ check_configured() {
6868
initialize_system() {
6969
echo "Initializing Cachet container ..."
7070

71+
APP_KEY=${APP_KEY:-null}
7172
APP_ENV=${APP_ENV:-development}
7273
APP_DEBUG=${APP_DEBUG:-true}
7374
APP_URL=${APP_URL:-http://localhost}
@@ -79,11 +80,11 @@ initialize_system() {
7980
DB_USERNAME=${DB_USERNAME:-postgres}
8081
DB_PASSWORD=${DB_PASSWORD:-postgres}
8182

82-
if [ ${DB_DRIVER} = "pgsql" ]; then
83+
if [[ "${DB_DRIVER}" = "pgsql" ]]; then
8384
DB_PORT=${DB_PORT:-5432}
8485
fi
8586

86-
if [ ${DB_DRIVER} = "mysql" ]; then
87+
if [[ "${DB_DRIVER}" = "mysql" ]]; then
8788
DB_PORT=${DB_PORT:-3306}
8889
fi
8990

@@ -119,10 +120,15 @@ initialize_system() {
119120
PHP_MAX_CHILDREN=${PHP_MAX_CHILDREN:-5}
120121

121122
# configure env file
122-
keygen="$(sudo php artisan key:generate)"
123-
echo ${keygen}
124-
appkey=$(echo ${keygen} | grep -oP '(?<=\[).*(?=\])')
125-
sed 's,{{APP_KEY}},'${appkey}',g' -i /var/www/html/.env
123+
if [[ "${APP_KEY}" == null ]]; then
124+
keygen="$(sudo php artisan key:generate)"
125+
echo "${keygen}"
126+
appkey=$(echo ${keygen} | grep -oP '(?<=\[).*(?=\])')
127+
echo "Please set ${appkey} as your APP_KEY variable in the environment or docker-compose.yml and re-launch"
128+
exit 1
129+
fi
130+
131+
sed 's,{{APP_KEY}},'${APP_KEY}',g' -i /var/www/html/.env
126132

127133
sed 's,{{APP_ENV}},'"${APP_ENV}"',g' -i /var/www/html/.env
128134
sed 's,{{APP_DEBUG}},'"${APP_DEBUG}"',g' -i /var/www/html/.env

Diff for: test/test.full.bats

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ load docker_helpers
44
load "lib/batslib"
55
load "lib/output"
66

7+
export APP_KEY="base64:v2LwHrdgnE+RavEXdnF8LgWIibjvEcFkU2qaX5Ji708="
8+
79
@test "[$TEST_FILE] testing Cachet Docker image build" {
810
command docker-compose build --no-cache cachet
911
}

Diff for: test/test.mysql.bats

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ load docker_helpers
44
load "lib/batslib"
55
load "lib/output"
66

7+
export APP_KEY="base64:v2LwHrdgnE+RavEXdnF8LgWIibjvEcFkU2qaX5Ji708="
8+
79
@test "[$TEST_FILE] docker-compose up" {
810
command docker-compose -f test/docker-compose-mysql.yml up -d
911
}

0 commit comments

Comments
 (0)