Skip to content

Commit

Permalink
feat: add default value for external Z-Wave JS config database path (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Dec 9, 2024
1 parent 9a22a9e commit 4b446b9
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 11 deletions.
2 changes: 2 additions & 0 deletions api/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const backupsDir: string =
export const nvmBackupsDir: string = joinPath(backupsDir, 'nvm')
export const storeBackupsDir: string = joinPath(backupsDir, 'store')

export const configDbDir: string = joinPath(storeDir, '.config-db')

export const defaultUser: string = process.env.DEFAULT_USERNAME || 'admin'
export const defaultPsw: string = process.env.DEFAULT_PASSWORD || 'zwave'
// lgtm [js/hardcoded-credentials]
Expand Down
8 changes: 7 additions & 1 deletion api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import {
LinkReliabilityCheckResult,
} from 'zwave-js'
import { getEnumMemberName, parseQRCodeString } from 'zwave-js/Utils'
import { logsDir, nvmBackupsDir, storeDir } from '../config/app'
import { configDbDir, logsDir, nvmBackupsDir, storeDir } from '../config/app'
import store from '../config/store'
import jsonStore from './jsonStore'
import * as LogManager from './logger'
Expand Down Expand Up @@ -2197,6 +2197,12 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
},
}

// when no env is specified copy config db to store dir
// fixes issues with pkg (and no more need to set this env on docker)
if (!process.env.ZWAVEJS_EXTERNAL_CONFIG) {
zwaveOptions.storage.deviceConfigExternalDir = configDbDir
}

if (this.cfg.rf) {
const { region, txPower } = this.cfg.rf

Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ FROM base AS runtime
# Copy files from previous build stage
COPY --from=build-zui /usr/src/app /usr/src/app

ENV ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db

ENV TAG_NAME=${image_name}

ENV NODE_ENV=production
Expand Down
1 change: 0 additions & 1 deletion docker/Dockerfile.contrib
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ RUN mkdir my_dist \
FROM node:18.14.2-bullseye
LABEL maintainer="robertsLando"

ENV ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db
ENV NODE_ENV=production

RUN \
Expand Down
2 changes: 0 additions & 2 deletions docker/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ RUN apt-get update && apt-get install -y \
# Copy files from the previous build stage
COPY --from=build-zui /usr/src/app /usr/src/app

ENV ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db

ENV TAG_NAME=${image_name}

ENV NODE_ENV=production
Expand Down
1 change: 0 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ services:
stop_signal: SIGINT
environment:
- SESSION_SECRET=mysupersecretkey
- ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db
# Uncomment if you want logs time and dates to match your timezone instead of UTC
# Available at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
#- TZ=America/New_York
Expand Down
1 change: 0 additions & 1 deletion docs/getting-started/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ services:
stop_signal: SIGINT
environment:
- SESSION_SECRET=mysupersecretkey
- ZWAVEJS_EXTERNAL_CONFIG=/usr/src/app/store/.config-db
# Uncomment if you want log times and dates to match your timezone instead of UTC
# Available at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
#- TZ=America/New_York
Expand Down
2 changes: 0 additions & 2 deletions docs/getting-started/other-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Run with custom storage path:

```bash
STORE_DIR=~/.zwave-js-ui \
ZWAVEJS_EXTERNAL_CONFIG=~/.zwave-js-ui/.config-db \
zwave-js-ui
```

Expand All @@ -77,7 +76,6 @@ module.exports = {
script: "zwave-js-ui",
env: {
STORE_DIR: "~/.zwave-js-ui",
ZWAVEJS_EXTERNAL_CONFIG: "~/.zwave-js-ui/.config-db",
},
},
]
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/env-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This is the list of the supported environment variables:
- `HOST`: The host address to bind to. Keep it empty to bind to all interfaces both IPv4 and IPv6
- `STORE_DIR`: The absolute path to the directory where all files will be stored. Default is `<path to your zui dir>/store`
- `BACKUPS_DIR`: The absolute path to the directory where all backups files will be stored. Default is `<path to your zui dir>/store/backups`
- `ZWAVEJS_EXTERNAL_CONFIG`: Mostly needed for docker users, it's the path to the folder used by Z-Wave JS to [store config database](https://zwave-js.github.io/node-zwave-js/#/usage/external-config?id=specifying-an-external-config-db-location), by default on docker it is `/usr/src/app/store/.config-db`. For users that are using a custom `STORE_DIR` this must be changed too.
- `ZWAVEJS_EXTERNAL_CONFIG`: It's the path to the folder used by Z-Wave JS to [store config database](https://zwave-js.github.io/node-zwave-js/#/usage/external-config?id=specifying-an-external-config-db-location), by default it is `<store_dir>/.config-db`.
- `ZWAVEJS_LOGS_DIR`: The folder used to store Z-Wave JS logs if `Log to file` is selected in the Z-Wave settings. By default, this is the `store` folder.
- `MQTT_NAME`: The name used as client name when connecting to the mqtt server. Overrides `mqtt.name` in `settings.json`
- `DISABLE_LOG_ROTATION`: Set this env var to `'true'` to disable application log rotation management
Expand Down

0 comments on commit 4b446b9

Please sign in to comment.