import { store } from './fileModels/store' import { i18n } from './i18n' import { sdk } from './sdk' import { uiPort } from './utils' export const main = sdk.setupMain(async ({ effects }) => { console.info(i18n('Starting Premier Gunner!')) // The login password lives in store.json. Reading it with `.const` makes the // daemon restart whenever it changes (e.g. via the "Set Login Password" action), // so PG_PASSWORD stays authoritative on every boot. const password = await store.read((s) => s.password).const(effects) return sdk.Daemons.of(effects).addDaemon('primary', { subcontainer: await sdk.SubContainer.of( effects, { imageId: 'premier-gunner' }, sdk.Mounts.of().mountVolume({ volumeId: 'main', subpath: null, mountpoint: '/data', readonly: false, }), 'premier-gunner-sub', ), exec: { command: ['node', 'src/server.js'], cwd: '/app', env: { NODE_ENV: 'production', PG_HOST: '0.0.0.0', PG_PORT: String(uiPort), PG_DATA_DIR: '/data', ...(password ? { PG_PASSWORD: password } : {}), }, }, ready: { display: i18n('Web Interface'), fn: () => sdk.healthCheck.checkPortListening(effects, uiPort, { successMessage: i18n('The web interface is ready'), errorMessage: i18n('The web interface is not ready'), }), }, requires: [], }) })