silserv/scripts/test-demo.sh
2025-08-08 15:55:55 +07:00

93 lines
No EOL
2.7 KiB
Bash
Executable file

#!/bin/bash
# Test script to demonstrate the update manager functionality
set -e
echo "🧪 Testing Rust Update Manager with Demo Application"
# Create a simple demo application
mkdir -p demo-app
cat > demo-app/Dockerfile << 'EOF'
FROM node:18-alpine
WORKDIR /app
RUN echo -e 'const express = require("express");\nconst app = express();\nconst PORT = process.env.PORT || 3000;\nconst VERSION = process.env.APP_VERSION || "1.0.0";\n\napp.get("/health", (req, res) => {\nres.json({ status: "healthy", version: VERSION });\n});\napp.get("/", (req, res) => {\nres.json({\nmessage: "Demo App",\nversion: VERSION,\ntimestamp: new Date().toISOString()\n});\n});\n\napp.listen(PORT, () => {\nconsole.log(`Demo app v${VERSION} running on port ${PORT}`);\n});' > app.js
RUN npm init -y && npm install express
ENV APP_VERSION=1.0.0
EXPOSE 3000
CMD ["node", "app.js"]
EOF
cat > demo-app/package.json << 'EOF'
{
"name": "demo-app",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"express": "^4.18.2"
}
}
EOF
# Build initial version
echo "📦 Building demo app v1.0.0..."
cd demo-app
docker build -t pakin-inspiron-15-3530.tail110d9.ts.net/pakin/demo-app:1.0.0 .
docker push pakin-inspiron-15-3530.tail110d9.ts.net/pakin/demo-app:1.0.0
cd ..
# Deploy the update manager
echo "🚀 Deploying update manager..."
./scripts/deploy.sh
# Wait for everything to start
echo "⏳ Waiting for services to initialize..."
sleep 30
# Check status
echo "📊 Checking system status..."
curl -s http://localhost:36530/api/status | jq .
echo "📋 Checking discovered containers..."
curl -s http://localhost:36530/api/containers | jq .
# Build and push v1.1.0
echo "📦 Building demo app v1.1.0..."
cd demo-app
# Update the version in Dockerfile
# sed -i 's/APP_VERSION=1.0.0/APP_VERSION=1.1.0/' Dockerfile
docker build -f ./Dockerfile.next -t pakin-inspiron-15-3530.tail110d9.ts.net/pakin/demo-app:1.1.0 .
docker push pakin-inspiron-15-3530.tail110d9.ts.net/pakin/demo-app:1.1.0
cd ..
echo "🔄 Triggering update check..."
curl -X POST http://localhost:36530/api/discovery/scan
# Wait a bit for the update to be detected and processed
sleep 60
# Check if update happened
echo "✅ Checking if update was applied..."
curl -s http://localhost:3000/ | jq .
echo "📊 Final system status..."
curl -s http://localhost:36530/api/stats | jq .
echo "🎉 Demo completed!"
echo ""
echo "What happened:"
echo "1. Built and deployed demo app v1.0.0"
echo "2. Update manager discovered the container"
echo "3. Built and pushed demo app v1.1.0 to registry"
echo "4. Update manager detected the new version"
echo "5. Automatically updated the container"
echo ""
echo "🌐 Check the API at: http://localhost:36530"
echo "🔍 View logs with: docker-compose logs -f"