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 - Add CloudronStack/test_add_url.sh for testing URL addition functionality These changes improve the CloudronStack automation and testing capabilities.
This commit is contained in:
@@ -26,6 +26,38 @@ package_nodejs_app() {
|
||||
repo_path="unknown-user/$app_name"
|
||||
fi
|
||||
|
||||
# Create .dockerignore to exclude sensitive files
|
||||
cat > .dockerignore << 'DOCKERIGNORE_EOF'
|
||||
.git
|
||||
.gitignore
|
||||
*.env
|
||||
*.key
|
||||
*.pem
|
||||
*.crt
|
||||
*.cert
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
*.log
|
||||
node_modules
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.coverage
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
LICENSE
|
||||
AUTHORS
|
||||
CONTRIBUTORS
|
||||
config/
|
||||
secrets/
|
||||
tokens/
|
||||
DOCKERIGNORE_EOF
|
||||
|
||||
# Create Cloudron manifest
|
||||
cat > app.manifest << EOF
|
||||
{
|
||||
@@ -87,8 +119,8 @@ EXPOSE $port
|
||||
CMD $start_cmd
|
||||
EOF
|
||||
|
||||
# Build Docker image
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}:latest"
|
||||
# Build Docker image with a more unique name to avoid conflicts in parallel execution
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}-$(date +%s%N | cut -c1-10):latest"
|
||||
if ! docker build -t "$docker_image" .; then
|
||||
echo "Failed to build Docker image for $app_name"
|
||||
return 1
|
||||
@@ -101,7 +133,7 @@ EOF
|
||||
fi
|
||||
|
||||
# Save the Docker image as an artifact
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}.tar.gz"
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}-$(date +%s).tar.gz"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -126,6 +158,38 @@ package_python_app() {
|
||||
repo_path="unknown-user/$app_name"
|
||||
fi
|
||||
|
||||
# Create .dockerignore to exclude sensitive files
|
||||
cat > .dockerignore << 'DOCKERIGNORE_EOF'
|
||||
.git
|
||||
.gitignore
|
||||
*.env
|
||||
*.key
|
||||
*.pem
|
||||
*.crt
|
||||
*.cert
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
*.log
|
||||
node_modules
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.coverage
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
LICENSE
|
||||
AUTHORS
|
||||
CONTRIBUTORS
|
||||
config/
|
||||
secrets/
|
||||
tokens/
|
||||
DOCKERIGNORE_EOF
|
||||
|
||||
# Create Cloudron manifest
|
||||
cat > app.manifest << EOF
|
||||
{
|
||||
@@ -187,8 +251,8 @@ EXPOSE $port
|
||||
CMD $start_cmd
|
||||
EOF
|
||||
|
||||
# Build Docker image
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}:latest"
|
||||
# Build Docker image with a more unique name to avoid conflicts in parallel execution
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}-$(date +%s%N | cut -c1-10):latest"
|
||||
if ! docker build -t "$docker_image" .; then
|
||||
echo "Failed to build Docker image for $app_name"
|
||||
return 1
|
||||
@@ -201,7 +265,7 @@ EOF
|
||||
fi
|
||||
|
||||
# Save the Docker image as an artifact
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}.tar.gz"
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}-$(date +%s).tar.gz"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -226,6 +290,38 @@ package_php_app() {
|
||||
repo_path="unknown-user/$app_name"
|
||||
fi
|
||||
|
||||
# Create .dockerignore to exclude sensitive files
|
||||
cat > .dockerignore << 'DOCKERIGNORE_EOF'
|
||||
.git
|
||||
.gitignore
|
||||
*.env
|
||||
*.key
|
||||
*.pem
|
||||
*.crt
|
||||
*.cert
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
*.log
|
||||
node_modules
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.coverage
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
LICENSE
|
||||
AUTHORS
|
||||
CONTRIBUTORS
|
||||
config/
|
||||
secrets/
|
||||
tokens/
|
||||
DOCKERIGNORE_EOF
|
||||
|
||||
# Create Cloudron manifest
|
||||
cat > app.manifest << EOF
|
||||
{
|
||||
@@ -267,8 +363,8 @@ EXPOSE 80
|
||||
CMD ["apache2-foreground"]
|
||||
EOF
|
||||
|
||||
# Build Docker image
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}:latest"
|
||||
# Build Docker image with a more unique name to avoid conflicts in parallel execution
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}-$(date +%s%N | cut -c1-10):latest"
|
||||
if ! docker build -t "$docker_image" .; then
|
||||
echo "Failed to build Docker image for $app_name"
|
||||
return 1
|
||||
@@ -281,7 +377,7 @@ EOF
|
||||
fi
|
||||
|
||||
# Save the Docker image as an artifact
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}.tar.gz"
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}-$(date +%s).tar.gz"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -306,6 +402,38 @@ package_go_app() {
|
||||
repo_path="unknown-user/$app_name"
|
||||
fi
|
||||
|
||||
# Create .dockerignore to exclude sensitive files
|
||||
cat > .dockerignore << 'DOCKERIGNORE_EOF'
|
||||
.git
|
||||
.gitignore
|
||||
*.env
|
||||
*.key
|
||||
*.pem
|
||||
*.crt
|
||||
*.cert
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
*.log
|
||||
node_modules
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.coverage
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
LICENSE
|
||||
AUTHORS
|
||||
CONTRIBUTORS
|
||||
config/
|
||||
secrets/
|
||||
tokens/
|
||||
DOCKERIGNORE_EOF
|
||||
|
||||
# Create Cloudron manifest
|
||||
cat > app.manifest << EOF
|
||||
{
|
||||
@@ -358,8 +486,8 @@ EXPOSE 8080
|
||||
CMD ["./$binary_name"]
|
||||
EOF
|
||||
|
||||
# Build Docker image
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}:latest"
|
||||
# Build Docker image with a more unique name to avoid conflicts in parallel execution
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}-$(date +%s%N | cut -c1-10):latest"
|
||||
if ! docker build -t "$docker_image" .; then
|
||||
echo "Failed to build Docker image for $app_name"
|
||||
return 1
|
||||
@@ -372,7 +500,7 @@ EOF
|
||||
fi
|
||||
|
||||
# Save the Docker image as an artifact
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}.tar.gz"
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}-$(date +%s).tar.gz"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -389,22 +517,39 @@ smoke_test_docker_image() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Run the container briefly to test if it starts correctly
|
||||
local container_name="smoke-test-${app_name//[^a-zA-Z0-9]/-}-$(date +%s)"
|
||||
# Sanitize the app name for container name
|
||||
local clean_app_name=$(printf '%s\n' "$app_name" | sed 's/[^a-zA-Z0-9]/-/g' | tr -cd '[:alnum:]-')
|
||||
local container_name="smoke-test-${clean_app_name:0:50}-$(date +%s)"
|
||||
|
||||
# Validate container name doesn't exceed Docker limits
|
||||
if [ ${#container_name} -gt 63 ]; then
|
||||
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
|
||||
echo "Failed to start container for $app_name during smoke test"
|
||||
docker rm "$container_name" >/dev/null 2>&1 || true
|
||||
# Remove container in case it was partially created
|
||||
docker rm -f "$container_name" >/dev/null 2>&1 || true
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Wait a few seconds to see if the container stays running
|
||||
sleep 15
|
||||
# Give the container time to start - wait with periodic checks
|
||||
local max_wait=30 # Maximum wait time in seconds
|
||||
local waited=0
|
||||
local container_status="not_started"
|
||||
|
||||
# Check if the container is still running
|
||||
local container_status
|
||||
container_status=$(docker inspect -f '{{.State.Status}}' "$container_name" 2>/dev/null || echo "not_found")
|
||||
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
|
||||
elif [ "$container_status" = "exited" ] || [ "$container_status" = "dead" ]; then
|
||||
# Container exited early, no need to wait longer
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
waited=$((waited + 2))
|
||||
done
|
||||
|
||||
if [ "$container_status" = "running" ]; then
|
||||
echo "Smoke test passed for $app_name - container is running"
|
||||
@@ -414,11 +559,11 @@ smoke_test_docker_image() {
|
||||
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)"
|
||||
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>&1 | head -30
|
||||
docker stop "$container_name" >/dev/null 2>&1 || true
|
||||
docker rm "$container_name" >/dev/null 2>&1 || true
|
||||
docker logs "$container_name" 2>/dev/null | head -30 || echo "Could not retrieve container logs"
|
||||
# Force remove the container
|
||||
docker rm -f "$container_name" >/dev/null 2>&1 || true
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -461,6 +606,38 @@ package_generic_app() {
|
||||
|
||||
cd "$app_dir"
|
||||
|
||||
# Create .dockerignore to exclude sensitive files
|
||||
cat > .dockerignore << 'DOCKERIGNORE_EOF'
|
||||
.git
|
||||
.gitignore
|
||||
*.env
|
||||
*.key
|
||||
*.pem
|
||||
*.crt
|
||||
*.cert
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
*.log
|
||||
node_modules
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.coverage
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
README.md
|
||||
CHANGELOG.md
|
||||
LICENSE
|
||||
AUTHORS
|
||||
CONTRIBUTORS
|
||||
config/
|
||||
secrets/
|
||||
tokens/
|
||||
DOCKERIGNORE_EOF
|
||||
|
||||
# Extract username/repo from the app_url for manifest
|
||||
local repo_path
|
||||
if [[ "$app_url" == *"github.com"* ]]; then
|
||||
@@ -565,8 +742,8 @@ EXPOSE 8080
|
||||
CMD ["/run-app.sh"]
|
||||
DOCKERFILE_EOF
|
||||
|
||||
# Build Docker image
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}:latest"
|
||||
# Build Docker image with a more unique name to avoid conflicts in parallel execution
|
||||
local docker_image="tsysdevstack-cloudron-buildtest-${app_name//[^a-zA-Z0-9]/-}-$(date +%s%N | cut -c1-10):latest"
|
||||
if ! docker build -t "$docker_image" .; then
|
||||
echo "Failed to build Docker image for $app_name"
|
||||
return 1
|
||||
@@ -579,6 +756,6 @@ DOCKERFILE_EOF
|
||||
fi
|
||||
|
||||
# Save the Docker image as an artifact
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}.tar.gz"
|
||||
docker save "$docker_image" | gzip > "$artifact_dir/${app_name//[^a-zA-Z0-9]/-}-$(date +%s).tar.gz"
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user