Something went wrong. Try again.
Barazo Docker Compose templates for self-hosting barazo.forum
Something went wrong. Try again.
2.2 kB · 66 lines
Shell
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667#!/bin/sh# install-plugins.sh -- Install plugins declared in plugins.json on container startup.## Expected to run inside the barazo-api container before the main process starts.# Reads /app/plugins.json (bind-mounted from the host) and installs each plugin# into /app/plugins/ (a named Docker volume that persists across restarts).## If plugins.json does not exist or is empty, this script exits silently.# If a plugin is already installed at the requested version, it is skipped.
set -e
PLUGINS_FILE="/app/plugins.json"PLUGINS_DIR="/app/plugins"
if [ ! -f "$PLUGINS_FILE" ]; then echo "[install-plugins] No plugins.json found, skipping plugin installation." exit 0fi
PLUGIN_COUNT=$(node -e " const fs = require('fs'); try { const data = JSON.parse(fs.readFileSync('$PLUGINS_FILE', 'utf8')); const plugins = data.plugins || []; console.log(plugins.length); } catch { console.log('0'); }")
if [ "$PLUGIN_COUNT" = "0" ]; then echo "[install-plugins] plugins.json has no plugins declared, skipping." exit 0fi
echo "[install-plugins] Installing $PLUGIN_COUNT plugin(s) from plugins.json..."
# Ensure plugins directory has a package.json for npm installif [ ! -f "$PLUGINS_DIR/package.json" ]; then echo '{"name":"barazo-plugins","private":true,"dependencies":{}}' > "$PLUGINS_DIR/package.json"fi
# Parse plugins.json and install each pluginnode -e " const fs = require('fs'); const { execSync } = require('child_process'); const data = JSON.parse(fs.readFileSync('$PLUGINS_FILE', 'utf8')); const plugins = data.plugins || [];
for (const plugin of plugins) { const spec = plugin.version ? plugin.name + '@' + plugin.version : plugin.name; console.log('[install-plugins] Installing ' + spec + '...'); try { execSync('npm install --prefix $PLUGINS_DIR ' + spec, { stdio: 'inherit', timeout: 120000, }); console.log('[install-plugins] Installed ' + spec); } catch (err) { console.error('[install-plugins] Failed to install ' + spec + ': ' + err.message); process.exit(1); } } console.log('[install-plugins] All plugins installed successfully.');"