fix(version): make version programmatic by reading from deno.json
- Replace hardcoded version in 00_commitinfo_data.ts - Now dynamically imports deno.json and reads version - Version will auto-update when deno.json is changed - Fixes version showing 3.1.2 instead of 4.0.0 test: add Docker test scripts for v3→v4 migration - 01-setup-v3-container.sh: Creates systemd container with v3 - 02-test-v3-to-v4-migration.sh: Tests migration (now fixed) - 03-cleanup.sh: Removes test container - README.md: Complete documentation Tested: Version now correctly shows 4.0.0
This commit is contained in:
124
test/manualdocker/01-setup-v3-container.sh
Executable file
124
test/manualdocker/01-setup-v3-container.sh
Executable file
@@ -0,0 +1,124 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Setup Docker container with systemd and install NUPST v3
|
||||||
|
# This creates a container from commit 806f81c6a057a2a5da586b96a231d391f12eb1bb (v3)
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CONTAINER_NAME="nupst-test-v3"
|
||||||
|
V3_COMMIT="806f81c6a057a2a5da586b96a231d391f12eb1bb"
|
||||||
|
|
||||||
|
echo "================================================"
|
||||||
|
echo " NUPST v3 Test Container Setup"
|
||||||
|
echo "================================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if container already exists
|
||||||
|
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
|
echo "⚠️ Container ${CONTAINER_NAME} already exists"
|
||||||
|
read -p "Remove and recreate? (y/N): " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
echo "→ Stopping and removing existing container..."
|
||||||
|
docker stop ${CONTAINER_NAME} 2>/dev/null || true
|
||||||
|
docker rm ${CONTAINER_NAME} 2>/dev/null || true
|
||||||
|
else
|
||||||
|
echo "Exiting. Remove manually with: docker rm -f ${CONTAINER_NAME}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "→ Creating Docker container (will install systemd)..."
|
||||||
|
docker run -d \
|
||||||
|
--name ${CONTAINER_NAME} \
|
||||||
|
--privileged \
|
||||||
|
--cgroupns=host \
|
||||||
|
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
|
||||||
|
ubuntu:22.04 \
|
||||||
|
/bin/bash -c "apt-get update && apt-get install -y systemd systemd-sysv && exec /sbin/init"
|
||||||
|
|
||||||
|
echo "→ Waiting for systemd to initialize..."
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
echo "→ Waiting for dpkg lock to be released..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
while fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do
|
||||||
|
echo ' Waiting for dpkg lock...'
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
echo ' dpkg lock released'
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Installing prerequisites in container..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq git curl sudo
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Cloning NUPST v3 (commit ${V3_COMMIT})..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
cd /opt
|
||||||
|
git clone https://code.foss.global/serve.zone/nupst.git
|
||||||
|
cd nupst
|
||||||
|
git checkout ${V3_COMMIT}
|
||||||
|
echo 'Checked out commit:'
|
||||||
|
git log -1 --oneline
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Running NUPST v3 installation script..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
cd /opt/nupst
|
||||||
|
bash install.sh -y
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Creating dummy NUPST configuration for testing..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
mkdir -p /etc/nupst
|
||||||
|
cat > /etc/nupst/config.json << 'EOF'
|
||||||
|
{
|
||||||
|
\"upsList\": [
|
||||||
|
{
|
||||||
|
\"id\": \"test-ups\",
|
||||||
|
\"name\": \"Test UPS\",
|
||||||
|
\"host\": \"127.0.0.1\",
|
||||||
|
\"port\": 161,
|
||||||
|
\"community\": \"public\",
|
||||||
|
\"version\": \"2c\",
|
||||||
|
\"batteryLowOID\": \"1.3.6.1.4.1.935.1.1.1.3.3.1.0\",
|
||||||
|
\"onBatteryOID\": \"1.3.6.1.4.1.935.1.1.1.3.3.2.0\",
|
||||||
|
\"shutdownCommand\": \"echo 'Shutdown triggered'\"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
\"groups\": []
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
echo 'Dummy config created at /etc/nupst/config.json'
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Enabling NUPST systemd service..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
nupst enable
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Starting NUPST service..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
nupst start
|
||||||
|
"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "================================================"
|
||||||
|
echo " ✓ NUPST v3 Container Ready"
|
||||||
|
echo "================================================"
|
||||||
|
echo ""
|
||||||
|
echo "Container name: ${CONTAINER_NAME}"
|
||||||
|
echo "NUPST version: v3 (commit ${V3_COMMIT})"
|
||||||
|
echo ""
|
||||||
|
echo "Useful commands:"
|
||||||
|
echo " docker exec -it ${CONTAINER_NAME} bash"
|
||||||
|
echo " docker exec ${CONTAINER_NAME} systemctl status nupst"
|
||||||
|
echo " docker exec ${CONTAINER_NAME} nupst --version"
|
||||||
|
echo " docker stop ${CONTAINER_NAME}"
|
||||||
|
echo " docker start ${CONTAINER_NAME}"
|
||||||
|
echo " docker rm -f ${CONTAINER_NAME}"
|
||||||
|
echo ""
|
72
test/manualdocker/02-test-v3-to-v4-migration.sh
Executable file
72
test/manualdocker/02-test-v3-to-v4-migration.sh
Executable file
@@ -0,0 +1,72 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Test migration from v3 to v4
|
||||||
|
# Run this after 01-setup-v3-container.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CONTAINER_NAME="nupst-test-v3"
|
||||||
|
|
||||||
|
echo "================================================"
|
||||||
|
echo " NUPST v3 → v4 Migration Test"
|
||||||
|
echo "================================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check if container exists
|
||||||
|
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
|
echo "❌ Container ${CONTAINER_NAME} is not running"
|
||||||
|
echo "Run ./01-setup-v3-container.sh first"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "→ Checking current NUPST status..."
|
||||||
|
docker exec ${CONTAINER_NAME} systemctl status nupst --no-pager || true
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "→ Checking current version..."
|
||||||
|
docker exec ${CONTAINER_NAME} nupst --version
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "→ Stopping v3 service..."
|
||||||
|
docker exec ${CONTAINER_NAME} systemctl stop nupst
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "→ Pulling latest v4 code from migration/deno-v4 branch..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
cd /opt/nupst
|
||||||
|
git fetch origin
|
||||||
|
# Reset any local changes made by install.sh
|
||||||
|
git reset --hard HEAD
|
||||||
|
git clean -fd
|
||||||
|
git checkout migration/deno-v4
|
||||||
|
git pull origin migration/deno-v4
|
||||||
|
echo 'Now on:'
|
||||||
|
git log -1 --oneline
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Running install.sh (should auto-detect v3 and migrate)..."
|
||||||
|
docker exec ${CONTAINER_NAME} bash -c "
|
||||||
|
cd /opt/nupst
|
||||||
|
bash install.sh -y
|
||||||
|
"
|
||||||
|
|
||||||
|
echo "→ Checking service status after migration..."
|
||||||
|
docker exec ${CONTAINER_NAME} systemctl status nupst --no-pager || true
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "→ Checking new version..."
|
||||||
|
docker exec ${CONTAINER_NAME} nupst --version
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "→ Testing service commands..."
|
||||||
|
docker exec ${CONTAINER_NAME} nupst service status || true
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "================================================"
|
||||||
|
echo " ✓ Migration Test Complete"
|
||||||
|
echo "================================================"
|
||||||
|
echo ""
|
||||||
|
echo "Check logs with:"
|
||||||
|
echo " docker exec ${CONTAINER_NAME} nupst service logs"
|
||||||
|
echo ""
|
28
test/manualdocker/03-cleanup.sh
Executable file
28
test/manualdocker/03-cleanup.sh
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Cleanup test container
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CONTAINER_NAME="nupst-test-v3"
|
||||||
|
|
||||||
|
echo "================================================"
|
||||||
|
echo " Cleanup NUPST Test Container"
|
||||||
|
echo "================================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
|
echo "→ Stopping container..."
|
||||||
|
docker stop ${CONTAINER_NAME} 2>/dev/null || true
|
||||||
|
|
||||||
|
echo "→ Removing container..."
|
||||||
|
docker rm ${CONTAINER_NAME} 2>/dev/null || true
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "✓ Container ${CONTAINER_NAME} removed"
|
||||||
|
else
|
||||||
|
echo "Container ${CONTAINER_NAME} not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
149
test/manualdocker/README.md
Normal file
149
test/manualdocker/README.md
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
# Manual Docker Testing Scripts
|
||||||
|
|
||||||
|
This directory contains scripts for manually testing NUPST installation and migration in Docker containers with systemd support.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Docker installed and running
|
||||||
|
- Privileged access (for systemd in container)
|
||||||
|
- Linux host (systemd container requirements)
|
||||||
|
|
||||||
|
## Test Scripts
|
||||||
|
|
||||||
|
### 1. `01-setup-v3-container.sh`
|
||||||
|
|
||||||
|
Creates a Docker container with systemd and installs NUPST v3.
|
||||||
|
|
||||||
|
**What it does:**
|
||||||
|
- Creates Ubuntu 22.04 container with systemd enabled
|
||||||
|
- Installs NUPST v3 from commit `806f81c6` (last v3 version)
|
||||||
|
- Enables and starts the systemd service
|
||||||
|
- Leaves container running for testing
|
||||||
|
|
||||||
|
**Usage:**
|
||||||
|
```bash
|
||||||
|
chmod +x 01-setup-v3-container.sh
|
||||||
|
./01-setup-v3-container.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Container name:** `nupst-test-v3`
|
||||||
|
|
||||||
|
### 2. `02-test-v3-to-v4-migration.sh`
|
||||||
|
|
||||||
|
Tests the migration from v3 to v4.
|
||||||
|
|
||||||
|
**What it does:**
|
||||||
|
- Checks current v3 installation
|
||||||
|
- Pulls v4 code from `migration/deno-v4` branch
|
||||||
|
- Runs install.sh (should auto-detect and migrate)
|
||||||
|
- Verifies service is running with v4
|
||||||
|
- Tests basic commands
|
||||||
|
|
||||||
|
**Usage:**
|
||||||
|
```bash
|
||||||
|
chmod +x 02-test-v3-to-v4-migration.sh
|
||||||
|
./02-test-v3-to-v4-migration.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Prerequisites:** Must run `01-setup-v3-container.sh` first
|
||||||
|
|
||||||
|
### 3. `03-cleanup.sh`
|
||||||
|
|
||||||
|
Removes the test container.
|
||||||
|
|
||||||
|
**Usage:**
|
||||||
|
```bash
|
||||||
|
chmod +x 03-cleanup.sh
|
||||||
|
./03-cleanup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Manual Testing Workflow
|
||||||
|
|
||||||
|
### Full Migration Test
|
||||||
|
|
||||||
|
1. **Set up v3 environment:**
|
||||||
|
```bash
|
||||||
|
./01-setup-v3-container.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Verify v3 is working:**
|
||||||
|
```bash
|
||||||
|
docker exec nupst-test-v3 nupst --version
|
||||||
|
docker exec nupst-test-v3 systemctl status nupst
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Test migration to v4:**
|
||||||
|
```bash
|
||||||
|
./02-test-v3-to-v4-migration.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Manual verification:**
|
||||||
|
```bash
|
||||||
|
# Enter container
|
||||||
|
docker exec -it nupst-test-v3 bash
|
||||||
|
|
||||||
|
# Inside container:
|
||||||
|
nupst --version # Should show v4.0.0
|
||||||
|
nupst service status # Should show running service
|
||||||
|
cat /etc/nupst/config.json # Config should be preserved
|
||||||
|
systemctl status nupst # Service should be active
|
||||||
|
```
|
||||||
|
|
||||||
|
5. **Cleanup:**
|
||||||
|
```bash
|
||||||
|
./03-cleanup.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Useful Docker Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Enter container shell
|
||||||
|
docker exec -it nupst-test-v3 bash
|
||||||
|
|
||||||
|
# Check service status
|
||||||
|
docker exec nupst-test-v3 systemctl status nupst
|
||||||
|
|
||||||
|
# View service logs
|
||||||
|
docker exec nupst-test-v3 journalctl -u nupst -n 50
|
||||||
|
|
||||||
|
# Check NUPST version
|
||||||
|
docker exec nupst-test-v3 nupst --version
|
||||||
|
|
||||||
|
# Run NUPST commands
|
||||||
|
docker exec nupst-test-v3 nupst service status
|
||||||
|
docker exec nupst-test-v3 nupst ups list
|
||||||
|
|
||||||
|
# Stop container
|
||||||
|
docker stop nupst-test-v3
|
||||||
|
|
||||||
|
# Start container
|
||||||
|
docker start nupst-test-v3
|
||||||
|
|
||||||
|
# Remove container
|
||||||
|
docker rm -f nupst-test-v3
|
||||||
|
```
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- The container runs with `--privileged` flag for systemd support
|
||||||
|
- Container uses Ubuntu 22.04 as base image
|
||||||
|
- v3 installation is from commit `806f81c6a057a2a5da586b96a231d391f12eb1bb`
|
||||||
|
- v4 migration pulls from `migration/deno-v4` branch
|
||||||
|
- All scripts are designed to be idempotent where possible
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Container won't start
|
||||||
|
- Ensure Docker daemon is running
|
||||||
|
- Check you have privileged access
|
||||||
|
- Try: `docker logs nupst-test-v3`
|
||||||
|
|
||||||
|
### Systemd not working in container
|
||||||
|
- Requires Linux host (not macOS/Windows)
|
||||||
|
- Needs `--privileged` and cgroup volume mounts
|
||||||
|
- Check: `docker exec nupst-test-v3 systemctl --version`
|
||||||
|
|
||||||
|
### Migration fails
|
||||||
|
- Check logs: `docker exec nupst-test-v3 journalctl -xe`
|
||||||
|
- Verify install.sh ran: `docker exec nupst-test-v3 ls -la /opt/nupst/`
|
||||||
|
- Check service: `docker exec nupst-test-v3 systemctl status nupst`
|
@@ -1,8 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @push.rocks/commitinfo
|
* commitinfo - reads version from deno.json
|
||||||
*/
|
*/
|
||||||
|
import denoConfig from '../deno.json' with { type: 'json' };
|
||||||
|
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@serve.zone/nupst',
|
name: denoConfig.name,
|
||||||
version: '3.1.2',
|
version: denoConfig.version,
|
||||||
description: 'Node.js UPS Shutdown Tool for SNMP-enabled UPS devices',
|
description: 'Deno-powered UPS monitoring tool for SNMP-enabled UPS devices',
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user