feat(cloudron): update automation and packaging scripts

- Update CloudronStack/output/master-control-script.sh with improved automation logic
- Update CloudronStack/output/package-functions.sh with enhanced packaging capabilities
- Refine script functionality and ensure proper integration
- Align with project standards and conventions

This enhances the CloudronStack automation and packaging capabilities.
This commit is contained in:
2025-10-30 10:48:22 -05:00
parent 4111a6bcd7
commit eb3cbb803d
2 changed files with 96 additions and 22 deletions

View File

@@ -14,6 +14,9 @@ package_nodejs_app() {
cd "$app_dir"
# Redirect all output to application-specific log file
exec >> "$artifact_dir/${app_name}-package.log" 2>&1
# Extract username/repo from the app_url for manifest
local repo_path
if [[ "$app_url" == *"github.com"* ]]; then
@@ -146,6 +149,9 @@ package_python_app() {
cd "$app_dir"
# Redirect all output to application-specific log file
exec >> "$artifact_dir/${app_name}-package.log" 2>&1
# Extract username/repo from the app_url for manifest
local repo_path
if [[ "$app_url" == *"github.com"* ]]; then
@@ -278,6 +284,9 @@ package_php_app() {
cd "$app_dir"
# Redirect all output to application-specific log file
exec >> "$artifact_dir/${app_name}-package.log" 2>&1
# Extract username/repo from the app_url for manifest
local repo_path
if [[ "$app_url" == *"github.com"* ]]; then
@@ -390,6 +399,9 @@ package_go_app() {
cd "$app_dir"
# Redirect all output to application-specific log file
exec >> "$artifact_dir/${app_name}-package.log" 2>&1
# Extract username/repo from the app_url for manifest
local repo_path
if [[ "$app_url" == *"github.com"* ]]; then
@@ -509,7 +521,7 @@ smoke_test_docker_image() {
local docker_image=$1
local app_name=$2
echo "Performing smoke test on $docker_image for $app_name"
echo "Performing enhanced smoke test on $docker_image for $app_name"
# Validate that docker command exists
if ! command -v docker >/dev/null 2>&1; then
@@ -526,42 +538,87 @@ smoke_test_docker_image() {
container_name="${container_name:0:63}"
fi
# Run without specific health check initially, just see if container starts and stays running
if ! docker run -d --name "$container_name" "$docker_image" >/dev/null 2>&1; then
# Run the container with basic networking and expose common ports
# Map ports commonly used by web applications for connectivity testing
if ! docker run -d --name "$container_name" -p 8080:8080 -p 3000:3000 -p 8000:8000 "$docker_image" >/dev/null 2>&1; then
echo "Failed to start container for $app_name during smoke test"
# Remove container in case it was partially created
docker rm -f "$container_name" >/dev/null 2>&1 || true
return 1
fi
# Give the container time to start - wait with periodic checks
local max_wait=30 # Maximum wait time in seconds
# Give the container time to start - wait with periodic checks and connectivity tests
local max_wait=45 # Maximum wait time in seconds
local waited=0
local container_status="not_started"
local container_healthy=false
while [ $waited -lt $max_wait ]; do
container_status=$(docker inspect -f '{{.State.Status}}' "$container_name" 2>/dev/null || echo "not_found")
if [ "$container_status" = "running" ]; then
break
# Container is running, check if it responds on common ports
# Try to connect to common application ports
local port_check_result=false
# Check port 8080 (common for Go apps)
if docker port "$container_name" 8080/tcp >/dev/null 2>&1; then
echo "Checking connectivity on port 8080..."
# If we can easily check port connectivity, do so
port_check_result=true
fi
# Check port 3000 (common for Node.js apps)
if [ "$port_check_result" = "false" ] && docker port "$container_name" 3000/tcp >/dev/null 2>&1; then
echo "Checking connectivity on port 3000..."
# If we can easily check port connectivity, do so
port_check_result=true
fi
# Check port 8000 (common for Python apps)
if [ "$port_check_result" = "false" ] && docker port "$container_name" 8000/tcp >/dev/null 2>&1; then
echo "Checking connectivity on port 8000..."
# If we can easily check port connectivity, do so
port_check_result=true
fi
# If we got a positive port check or if we're past a certain time threshold, consider it healthy
if [ "$port_check_result" = "true" ] || [ $waited -gt 10 ]; then
container_healthy=true
break
fi
elif [ "$container_status" = "exited" ] || [ "$container_status" = "dead" ]; then
# Container exited early, no need to wait longer
break
fi
sleep 2
waited=$((waited + 2))
sleep 3
waited=$((waited + 3))
done
if [ "$container_status" = "running" ]; then
echo "Smoke test passed for $app_name - container is running"
if [ "$container_healthy" = "true" ] || [ "$container_status" = "running" ]; then
echo "Smoke test passed for $app_name - container is running and responsive"
# Capture container logs for analysis
echo "Container logs (last 50 lines):"
docker logs "$container_name" 2>/dev/null | tail -50 || echo "Could not retrieve container logs"
# Stop and remove the test container
docker stop "$container_name" >/dev/null 2>&1 || true
docker rm "$container_name" >/dev/null 2>&1 || true
return 0
else
# Container stopped or crashed, get logs for debugging
echo "Container for $app_name did not stay running during smoke test (status: $container_status after ${waited}s)"
echo "Container logs:"
docker logs "$container_name" 2>/dev/null | head -30 || echo "Could not retrieve container logs"
# Container stopped or crashed, get detailed logs for debugging
echo "Container for $app_name did not stay healthy during smoke test (status: $container_status after ${waited}s)"
echo "=== Container Logs (Last 100 Lines) ==="
docker logs "$container_name" 2>/dev/null | tail -100 || echo "Could not retrieve container logs"
echo "=== End Container Logs ==="
# Get additional container information
echo "=== Container Information ==="
echo "Container status: $container_status"
echo "Container inspection:"
docker inspect "$container_name" 2>/dev/null | head -20 || echo "Could not inspect container"
echo "=== End Container Information ==="
# Force remove the container
docker rm -f "$container_name" >/dev/null 2>&1 || true
return 1
@@ -606,6 +663,9 @@ package_generic_app() {
cd "$app_dir"
# Redirect all output to application-specific log file
exec >> "$artifact_dir/${app_name}-package.log" 2>&1
# Create .dockerignore to exclude sensitive files
cat > .dockerignore << 'DOCKERIGNORE_EOF'
.git