Barazo Docker Compose templates for self-hosting
barazo.forum
1#!/bin/sh
2# install-plugins.sh -- Install plugins declared in plugins.json on container startup.
3#
4# Expected to run inside the barazo-api container before the main process starts.
5# Reads /app/plugins.json (bind-mounted from the host) and installs each plugin
6# into /app/plugins/ (a named Docker volume that persists across restarts).
7#
8# If plugins.json does not exist or is empty, this script exits silently.
9# If a plugin is already installed at the requested version, it is skipped.
10
11set -e
12
13PLUGINS_FILE="/app/plugins.json"
14PLUGINS_DIR="/app/plugins"
15
16if [ ! -f "$PLUGINS_FILE" ]; then
17 echo "[install-plugins] No plugins.json found, skipping plugin installation."
18 exit 0
19fi
20
21PLUGIN_COUNT=$(node -e "
22 const fs = require('fs');
23 try {
24 const data = JSON.parse(fs.readFileSync('$PLUGINS_FILE', 'utf8'));
25 const plugins = data.plugins || [];
26 console.log(plugins.length);
27 } catch {
28 console.log('0');
29 }
30")
31
32if [ "$PLUGIN_COUNT" = "0" ]; then
33 echo "[install-plugins] plugins.json has no plugins declared, skipping."
34 exit 0
35fi
36
37echo "[install-plugins] Installing $PLUGIN_COUNT plugin(s) from plugins.json..."
38
39# Ensure plugins directory has a package.json for npm install
40if [ ! -f "$PLUGINS_DIR/package.json" ]; then
41 echo '{"name":"barazo-plugins","private":true,"dependencies":{}}' > "$PLUGINS_DIR/package.json"
42fi
43
44# Parse plugins.json and install each plugin
45node -e "
46 const fs = require('fs');
47 const { execSync } = require('child_process');
48 const data = JSON.parse(fs.readFileSync('$PLUGINS_FILE', 'utf8'));
49 const plugins = data.plugins || [];
50
51 for (const plugin of plugins) {
52 const spec = plugin.version ? plugin.name + '@' + plugin.version : plugin.name;
53 console.log('[install-plugins] Installing ' + spec + '...');
54 try {
55 execSync('npm install --prefix $PLUGINS_DIR ' + spec, {
56 stdio: 'inherit',
57 timeout: 120000,
58 });
59 console.log('[install-plugins] Installed ' + spec);
60 } catch (err) {
61 console.error('[install-plugins] Failed to install ' + spec + ': ' + err.message);
62 process.exit(1);
63 }
64 }
65 console.log('[install-plugins] All plugins installed successfully.');
66"