Skip to content

Commit

Permalink
修复 nodedb 环境变量被覆盖
Browse files Browse the repository at this point in the history
Signed-off-by: Meng Sen <[email protected]>
  • Loading branch information
QYG2297248353 committed Jan 13, 2025
1 parent 3b99a7d commit e388efc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
24 changes: 6 additions & 18 deletions apps/nodebb/3.12.2/conf/setup.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
{
"defaults": {
"mongo": {
"host": "mongo",
"port": 27017,
"database": "nodebb",
"username": "nodebb",
"password": "nodebb"
},
"redis": {
"host": "redis",
"port": 6379,
"database": 0
},
"postgres": {
"host": "postgres",
"port": 5432,
"database": "nodebb",
"username": "nodebb",
"password": "nodebb"
"$NODEBB_DB": {
"host": "$NODEBB_DB_HOST",
"port": $NODEBB_DB_PORT,
"database": "$NODEBB_DB_NAME",
"username": "$NODEBB_DB_USER",
"password": "$NODEBB_DB_PASSWORD"
}
}
}
9 changes: 0 additions & 9 deletions apps/nodebb/3.12.2/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,3 @@ services:
- ${NODEBB_ROOT_PATH}/setup.json:/usr/src/app/setup.json
environment:
- TZ=Asia/Shanghai
- url=${NODEBB_URL}
- port=4567
- database=${NODEBB_DB}
- ${NODEBB_DB}_host=${NODEBB_DB_HOST}
- ${NODEBB_DB}_port=${NODEBB_DB_PORT}
- ${NODEBB_DB}_username=${NODEBB_DB_USERNAME}
- ${NODEBB_DB}_password=${NODEBB_DB_PASSWORD}
- ${NODEBB_DB}_database=${NODEBB_DB_DATABASE}
- ${NODEBB_DB}_ssl=${NODEBB_DB_SSL:-false}
26 changes: 25 additions & 1 deletion apps/nodebb/3.12.2/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,32 @@ if [ -f .env ]; then
mkdir -p "$NODEBB_ROOT_PATH/uploads"
mkdir -p "$NODEBB_ROOT_PATH/config"

cp ./conf/setup.json "$NODEBB_ROOT_PATH/setup.json"
# setup-3 初始化参数配置
if [ -z "$NODEBB_DB_NAME" ]; then
NODEBB_DB_NAME="nodebb"
fi

if [ -z "$NODEBB_DB_USER" ]; then
NODEBB_DB_USER=""
fi

if [ -z "$NODEBB_DB_PASSWORD" ]; then
NODEBB_DB_PASSWORD=""
fi

SETUP_JSON_PATH="$NODEBB_ROOT_PATH/setup.json"
cp ./conf/setup.json "$SETUP_JSON_PATH"
sed -i "
s|\$NODEBB_DB_HOST|$NODEBB_DB_HOST|g;
s|\$NODEBB_DB_PORT|$NODEBB_DB_PORT|g;
s|\$NODEBB_DB_NAME|$NODEBB_DB_NAME|g;
s|\$NODEBB_DB_USER|$NODEBB_DB_USER|g;
s|\$NODEBB_DB_PASSWORD|$NODEBB_DB_PASSWORD|g;
s|\$NODEBB_DB|$NODEBB_DB|g
" "$SETUP_JSON_PATH"


# setup-4 update dir permissions
chown -R 1001:1001 "$NODEBB_ROOT_PATH"
chown -R 1001:1001 "$NODEBB_ROOT_PATH/node_modules"
chown -R 1001:1001 "$NODEBB_ROOT_PATH/build"
Expand Down
12 changes: 11 additions & 1 deletion apps/nodebb/3.12.2/scripts/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ if [ -f .env ]; then
mkdir -p "$NODEBB_ROOT_PATH/config"

if [ ! -f "$NODEBB_ROOT_PATH/setup.json" ]; then
cp ./conf/setup.json "$NODEBB_ROOT_PATH/setup.json"
SETUP_JSON_PATH="$NODEBB_ROOT_PATH/setup.json"
cp ./conf/setup.json "$SETUP_JSON_PATH"
sed -i "
s|\$NODEBB_DB_HOST|$NODEBB_DB_HOST|g;
s|\$NODEBB_DB_PORT|$NODEBB_DB_PORT|g;
s|\$NODEBB_DB_NAME|$NODEBB_DB_NAME|g;
s|\$NODEBB_DB_USER|$NODEBB_DB_USER|g;
s|\$NODEBB_DB_PASSWORD|$NODEBB_DB_PASSWORD|g;
s|\$NODEBB_DB|$NODEBB_DB|g
" "$SETUP_JSON_PATH"
fi

# setup-3 update dir permissions
chown -R 1001:1001 "$NODEBB_ROOT_PATH"
chown -R 1001:1001 "$NODEBB_ROOT_PATH/node_modules"
chown -R 1001:1001 "$NODEBB_ROOT_PATH/build"
Expand Down

0 comments on commit e388efc

Please sign in to comment.