Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
src/extensions
npm-debug.log
.env.local
.env.development.local
Expand All @@ -21,3 +22,12 @@ build
# ignore test files
**/*.test.ts
**/*.spec.ts

# Local secrets and runtime/test artifacts never belong in the build context.
.env
.env.*
.data
.data-dev
test-results
playwright-report
tests
24 changes: 24 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Server Configuration
PORT=3000
CONSOLE_HOST=127.0.0.1
CONSOLE_USERNAME=admin
CONSOLE_PASSWORD=
# Set a strong unique CONSOLE_PASSWORD. For a TLS reverse proxy, set its public origin:
# CONSOLE_ORIGIN=https://console.example.com

# M3ter Manager login (separate from console access; required to unlock the app)
M3TER_MANAGER_USERNAME=admin
M3TER_MANAGER_PASSWORD=

# Module Configuration
BACKEND_MODULES="core/arweave,core/is_on,core/prover,core/streamr"
Expand All @@ -9,6 +18,21 @@ UI_MODULES="streamr:core/streamr/ui"
API_TOKEN=...
APPLICATION_ID=...
CHIRPSTACK_HOST=localhost
# Optional web UI origin; defaults to http://CHIRPSTACK_HOST:8080.
# Browsers access it through the console's /chirpstack/ proxy.
# CHIRPSTACK_WEB_URL=http://localhost:8080
# M3ter Manager uses the existing ChirpStack v4 REST proxy and the same API_TOKEN.
# This is the REST proxy's port, NOT the ChirpStack web UI port.
# CHIRPSTACK_REST_URL=http://localhost:8090
# Optional MQTT URL and broker credentials (kept on the server).
# MQTT_URL=mqtt://localhost:1883
# MQTT_USERNAME=
# MQTT_PASSWORD=
# Activity is observational; a quiet meter is not necessarily offline.
# M3TER_INACTIVE_SECONDS=300
# Optional: start the console for monitoring/control without loading billing,
# blockchain or delivery extensions. Default false preserves existing behavior.
# CONSOLE_MONITOR_ONLY=true

# Contract & Network Configuration
CONTRACT_LABEL=M3ters
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
- name: Run tests
run: npm test

- name: Install browser for desktop UI tests
run: npx playwright install --with-deps chromium

- name: Test desktop themes and responsive interactions
run: npm run test:ui

build-platform:
needs: [test]
strategy:
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ dist
.yarn/install-state.gz
.pnp.*
cache/
db/
db/
# Browser test artifacts
playwright-report/
test-results/

# Downloaded external extensions
src/extensions/
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ RUN apk add --no-cache cmake make g++ python3 openssl-dev py3-setuptools git
# Copy and install dependencies
COPY package*.json ./

RUN npm install --include=dev && npm cache clean --force
RUN npm ci --include=dev && npm cache clean --force

# Copy application files
COPY babel.config.js .
COPY tsconfig.json .
COPY src ./src
COPY scripts ./scripts

# Build project
RUN npm run build
Expand Down
386 changes: 384 additions & 2 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ services:
- .env
volumes:
- ./.data-dev:/opt/app/.data
- console_dev_src_modules:/opt/app/src/lib
- console_dev_dist_modules:/opt/app/dist/lib
- console_dev_extension_sources:/opt/app/src/extensions
- console_dev_extension_builds:/opt/app/dist/extensions

volumes:
console_dev_src_modules:
console_dev_dist_modules:
console_dev_extension_sources:
console_dev_extension_builds:
13 changes: 13 additions & 0 deletions compose.local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Used by ./install.sh to deploy the current checkout with production data volumes.
services:
console:
image: m3tering-console:local
build:
context: .
dockerfile: Dockerfile
healthcheck:
test: ["CMD", "node", "scripts/healthcheck.cjs"]
interval: 5s
timeout: 4s
start_period: 30s
retries: 24
8 changes: 4 additions & 4 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ services:
- "3000:3000"
volumes:
- ./.data:/opt/app/.data
- console_src_modules:/opt/app/src/lib
- console_dist_modules:/opt/app/dist/lib
- console_extension_sources:/opt/app/src/extensions
- console_extension_builds:/opt/app/dist/extensions

volumes:
console_db:
console_src_modules:
console_dist_modules:
console_extension_sources:
console_extension_builds:
84 changes: 2 additions & 82 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,85 +1,5 @@
#!/usr/bin/env sh
set -e

APP_DIR="/opt/app"
SRC_LIB="$APP_DIR/src/lib"
DIST_LIB="$APP_DIR/dist/lib"

mkdir -p "$SRC_LIB"
mkdir -p "$DIST_LIB"

if [ -n "$MODULES" ]; then
echo "Requested modules: $MODULES"
IFS=','

for repo in $MODULES; do
CLEAN_REPO=$(echo "$repo" | cut -d'#' -f1)
NAME=$(basename "$CLEAN_REPO")
VERSION=$(echo "$repo" | grep -o '#.*' | sed 's/#//')

SRC_DEST="$SRC_LIB/$NAME"
DIST_DEST="$DIST_LIB/$NAME"

# -----------------------------
# 1️⃣ Download source if missing
# -----------------------------
if [ -d "$SRC_DEST" ]; then
echo "✔ Module $NAME already downloaded"
else
echo "⬇ Downloading module: $NAME"
git clone --depth=1 "https://github.com/$CLEAN_REPO.git" "$SRC_DEST"

if [ -n "$VERSION" ]; then
git -C "$SRC_DEST" fetch --tags
git -C "$SRC_DEST" checkout "$VERSION"
fi
fi

# -----------------------------
# 2️⃣ Install plugin dependencies (isolated)
# -----------------------------
if [ -f "$SRC_DEST/package.json" ] && [ ! -d "$SRC_DEST/node_modules" ]; then
echo "📦 Installing dependencies for $NAME (isolated)"
cd "$SRC_DEST"
npm install --production
cd "$APP_DIR"
fi

# -----------------------------
# 3️⃣ Build or copy plugin
# -----------------------------
if [ -f "$DIST_DEST/.built" ]; then
echo "🏁 Plugin $NAME already built"
continue
fi

echo "🔧 Building plugin: $NAME"
mkdir -p "$DIST_DEST"

# TypeScript project
if [ -f "$SRC_DEST/tsconfig.json" ]; then
npx tsc --project "$SRC_DEST/tsconfig.json" --outDir "$DIST_DEST"

# Single TS file
elif [ -f "$SRC_DEST/index.ts" ]; then
npx tsc "$SRC_DEST/index.ts" --outDir "$DIST_DEST"

# Plain JS project
else
cp -r "$SRC_DEST"/* "$DIST_DEST/"
fi

# -----------------------------
# 4️⃣ Copy plugin's node_modules to dist
# -----------------------------
if [ -d "$SRC_DEST/node_modules" ]; then
echo "📦 Copying isolated dependencies for $NAME"
cp -r "$SRC_DEST/node_modules" "$DIST_DEST/"
fi

# Mark as built to avoid rebuilding every restart
touch "$DIST_DEST/.built"
done
fi

cd /opt/app
node scripts/install-modules.cjs
exec "$@"
35 changes: 35 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Build first; replace only this Compose project's console service. Keep all data.
set -euo pipefail
project_args=()
case "${1:-}" in
--help|-h)
printf '%s\n' 'Usage: ./install.sh [--project-name NAME]' 'Builds this checkout, recreates the console container, and waits for readiness.' 'Use the existing Compose project name to update a deployment with a custom name.'
exit 0 ;;
--project-name)
if [[ $# != 2 || ! $2 =~ ^[a-z0-9][a-z0-9_-]*$ ]]; then
printf '%s\n' 'Provide a valid Compose project name.' >&2; exit 2
fi
project_args=(--project-name "$2") ;;
'') ;;
*) printf '%s\n' 'Unknown option. Run ./install.sh --help.' >&2; exit 2 ;;
esac
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
if [[ ! -f .env ]]; then
printf '%s\n' 'Missing .env. Copy .env.example to .env and configure your credentials and services first.' >&2
exit 1
fi
command -v docker >/dev/null || { printf '%s\n' 'Docker with the Compose plugin is required.' >&2; exit 1; }
docker compose version >/dev/null
docker info >/dev/null
compose=(docker compose "${project_args[@]}" -f compose.yaml -f compose.local.yaml)
"${compose[@]}" config --quiet
printf '%s\n' 'Building the current checkout. The running console stays available during the build.'
"${compose[@]}" build console
printf '%s\n' 'Replacing the console container and waiting for the new build to become ready…'
if ! "${compose[@]}" up --detach --no-deps --no-build --pull never --force-recreate --wait --wait-timeout 240 console; then
printf '%s\n' 'The replacement did not become ready. Data volumes were preserved.' 'Inspect the console logs with docker compose -f compose.yaml -f compose.local.yaml logs console (include your project name if set).' >&2
exit 1
fi
printf '%s\n' 'The current build is running. Your .env, database, and extension volumes are preserved.'
"${compose[@]}" ps console
3 changes: 3 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testPathIgnorePatterns: ['/node_modules/', '/tests/ui/.*\\.spec\\.cjs$'],
};
64 changes: 64 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"start": "node dist/index.js",
"build": "tsc",
"dev": "nodemon --exec ts-node src/index.ts",
"test": "tsc --noEmit && jest"
"test": "tsc --noEmit && jest",
"test:ui": "npm run build && playwright test",
"preview:ui": "npm run build && node tests/ui/serve.cjs",
"modules:install": "npm run build && node scripts/install-modules.cjs"
},
"author": "Emmo00",
"license": "MIT",
Expand All @@ -31,6 +34,7 @@
"devDependencies": {
"@babel/preset-env": "^7.28.3",
"@babel/preset-typescript": "^7.27.1",
"@playwright/test": "1.61.1",
"@types/better-sqlite3": "^7.6.13",
"@types/express": "^4.17.21",
"@types/jest": "^30.0.0",
Expand Down
16 changes: 16 additions & 0 deletions playwright.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { defineConfig } = require('@playwright/test');
module.exports = defineConfig({
testDir: './tests/ui', testMatch: '**/*.spec.cjs', timeout: 60000,
fullyParallel: false, workers: 1,
use: {
baseURL: 'http://127.0.0.1:4173', headless: true,
viewport: { width: 1440, height: 900 },
launchOptions: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE ? { executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE } : {},
screenshot: 'only-on-failure', trace: 'retain-on-failure',
},
webServer: [
{ command: 'node tests/ui/serve.cjs', url: 'http://127.0.0.1:4173', reuseExistingServer: !process.env.CI },
// Always own this fixture; reusing an interrupted run can lose its server mid-test.
{ command: 'node tests/ui/serve-auth.cjs', url: 'http://127.0.0.1:4174', reuseExistingServer: false },
],
});
9 changes: 9 additions & 0 deletions scripts/healthcheck.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// An authenticated HTTP boundary proves that the console listener has started.
const http = require('node:http');
const host = process.env.CONSOLE_HOST;
const request = http.get({ hostname: !host || host === '0.0.0.0' ? '127.0.0.1' : host === '::' ? '::1' : host,
port: Number(process.env.PORT || 3000), path: '/', timeout: 2500 }, response => {
response.resume(); process.exitCode = response.statusCode === 401 && /^Basic /i.test(response.headers['www-authenticate'] || '') ? 0 : 1;
});
request.on('timeout', () => request.destroy(new Error('timeout')));
request.on('error', () => { process.exitCode = 1; });
Loading
Loading