Files

90 lines
2.6 KiB
Bash

#!/usr/bin/env bash
set -eu
export COUCHDB_PASSWORD=$(cat /run/secrets/db_password)
cd /opt/inventaire
# Overwrites the local config with environment variables every time the container is restarted
# This file can be itself overwritten either by ./dist/config/local-production.js (assuming NODE_ENV=production) or by NODE_CONFIG
# See https://github.com/node-config/node-config/wiki/Configuration-Files#file-load-order
# and https://github.com/node-config/node-config/wiki/Environment-Variables#node_config
cat > "./dist/config/local.js" << 'EOF'
// Built by the recipe's entrypoint
import { readFileSync } from 'node:fs'
const env = process.env
const readSecret = name => readFileSync(`/run/secrets/${name}`, 'utf8').trim()
export default {
hostname: '0.0.0.0',
port: env.INVENTAIRE_PORT,
publicHostname: env.PUBLIC_HOSTNAME,
instanceName: env.INSTANCE_NAME,
orgName: env.ORG_NAME,
orgUrl: env.ORG_URL,
contactAddress: env.CONTACT_ADDRESS,
defaultLandingPageMapPosition: [ Number(env.MAP_LANG), Number(env.MAP_LONG) ],
db: {
username: env.COUCHDB_USER,
password: readSecret('db_password'),
hostname: 'couchdb',
backupDirectory: '/opt/inventaire_backups',
},
leveldb: {
directory: '/opt/inventaire_leveldb',
suffixDirectoryPathWithDbSuffix: false,
},
elasticsearch: {
origin: 'http://elasticsearch:9200',
},
mailer: {
disabled: false,
nodemailer: {
host: env.MAILER_SMTP_HOST,
port: Number(env.MAILER_SMTP_PORT),
auth: {
user: env.MAILER_SMTP_USERNAME,
pass: readSecret('smtp_password'),
},
},
},
matomo: {
enabled: env.MOTOMO_ENABLED === 'true',
endpoint: env.MOTOMO_ENDPOINT,
idsite: Number(env.MOTOMO_IDSITE),
rec: Number(env.MOTOMO_REC),
},
mediaStorage: {
mode: env.MEDIA_STORAGE_MODE,
swift: {
username: env.SWIFT_USERNAME,
password: env.SWIFT_PASSWORD,
authUrl: env.SWIFT_AUTH_URL,
publicURL: env.SWIFT_PUBLIC_URL,
tenantName: env.SWIFT_TENANT_NAME,
region: env.SWIFT_REGION,
},
local: {
directory: '/opt/inventaire_local_media_storage',
},
federation: {
// Set to 'https://inventaire.io' in ./local-dev.ts
// in order to use inventaire.io entities in development
remoteEntitiesOrigin: 'https://inventaire.io',
},
},
}
EOF
# The built server started here after will only care for dist/config/local.js
# but config/local.ts is kept in sync for consistency
cp ./dist/config/local.js ./config/local.ts
rm -rf /opt/inventaire/client-web/*
cp -r /opt/inventaire/client/. /opt/inventaire/client-web
./scripts/typescript/start_built_server.sh