Auto-commit before deployment Fri Sep 5 20:43:45 UTC 2025
This commit is contained in:
3
logs/portfolio-deploy.log
Normal file
3
logs/portfolio-deploy.log
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[0;34m[2025-09-05 20:43:45][0m 🚀 Starting automatic deployment for portfolio
|
||||||
|
[0;34m[2025-09-05 20:43:45][0m 📋 Step 1: Running code quality checks...
|
||||||
|
[1;33m[WARNING][0m You have uncommitted changes. Committing them...
|
||||||
@@ -11,7 +11,7 @@ CONTAINER_NAME="portfolio-app"
|
|||||||
IMAGE_NAME="portfolio-app"
|
IMAGE_NAME="portfolio-app"
|
||||||
PORT=3000
|
PORT=3000
|
||||||
BACKUP_PORT=3001
|
BACKUP_PORT=3001
|
||||||
LOG_FILE="/var/log/portfolio-deploy.log"
|
LOG_FILE="./logs/portfolio-deploy.log"
|
||||||
|
|
||||||
# Colors for output
|
# Colors for output
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
@@ -44,7 +44,7 @@ if [[ $EUID -eq 0 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if Docker is running
|
# Check if Docker is running
|
||||||
if ! docker info > /dev/null 2>&1; then
|
if ! sudo docker info > /dev/null 2>&1; then
|
||||||
error "Docker is not running. Please start Docker and try again."
|
error "Docker is not running. Please start Docker and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -107,14 +107,14 @@ log "🐳 Step 3: Docker operations..."
|
|||||||
|
|
||||||
# Build Docker image
|
# Build Docker image
|
||||||
log "🏗️ Building Docker image..."
|
log "🏗️ Building Docker image..."
|
||||||
docker build -t "$IMAGE_NAME:latest" . || {
|
sudo docker build -t "$IMAGE_NAME:latest" . || {
|
||||||
error "Docker build failed"
|
error "Docker build failed"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Tag with timestamp
|
# Tag with timestamp
|
||||||
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
|
||||||
docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:$TIMESTAMP"
|
sudo docker tag "$IMAGE_NAME:latest" "$IMAGE_NAME:$TIMESTAMP"
|
||||||
|
|
||||||
success "✅ Docker image built successfully"
|
success "✅ Docker image built successfully"
|
||||||
|
|
||||||
@@ -122,10 +122,10 @@ success "✅ Docker image built successfully"
|
|||||||
log "🚀 Step 4: Deploying application..."
|
log "🚀 Step 4: Deploying application..."
|
||||||
|
|
||||||
# Check if container is running
|
# Check if container is running
|
||||||
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" = "true" ]; then
|
if [ "$(sudo docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null)" = "true" ]; then
|
||||||
log "📦 Stopping existing container..."
|
log "📦 Stopping existing container..."
|
||||||
docker stop "$CONTAINER_NAME" || true
|
sudo docker stop "$CONTAINER_NAME" || true
|
||||||
docker rm "$CONTAINER_NAME" || true
|
sudo docker rm "$CONTAINER_NAME" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if port is available
|
# Check if port is available
|
||||||
@@ -138,7 +138,7 @@ fi
|
|||||||
|
|
||||||
# Start new container
|
# Start new container
|
||||||
log "🚀 Starting new container on port $DEPLOY_PORT..."
|
log "🚀 Starting new container on port $DEPLOY_PORT..."
|
||||||
docker run -d \
|
sudo docker run -d \
|
||||||
--name "$CONTAINER_NAME" \
|
--name "$CONTAINER_NAME" \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
-p "$DEPLOY_PORT:3000" \
|
-p "$DEPLOY_PORT:3000" \
|
||||||
@@ -189,22 +189,22 @@ fi
|
|||||||
|
|
||||||
# Show container status
|
# Show container status
|
||||||
log "📊 Container status:"
|
log "📊 Container status:"
|
||||||
docker ps --filter "name=$CONTAINER_NAME" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
sudo docker ps --filter "name=$CONTAINER_NAME" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|
||||||
|
|
||||||
# Show resource usage
|
# Show resource usage
|
||||||
log "📈 Resource usage:"
|
log "📈 Resource usage:"
|
||||||
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" "$CONTAINER_NAME"
|
sudo docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" "$CONTAINER_NAME"
|
||||||
|
|
||||||
# Step 6: Cleanup
|
# Step 6: Cleanup
|
||||||
log "🧹 Step 6: Cleaning up old images..."
|
log "🧹 Step 6: Cleaning up old images..."
|
||||||
|
|
||||||
# Remove old images (keep last 3 versions)
|
# Remove old images (keep last 3 versions)
|
||||||
docker images "$IMAGE_NAME" --format "table {{.Tag}}\t{{.ID}}" | tail -n +2 | head -n -3 | awk '{print $2}' | xargs -r docker rmi || {
|
sudo docker images "$IMAGE_NAME" --format "table {{.Tag}}\t{{.ID}}" | tail -n +2 | head -n -3 | awk '{print $2}' | xargs -r sudo docker rmi || {
|
||||||
warning "No old images to remove"
|
warning "No old images to remove"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean up unused Docker resources
|
# Clean up unused Docker resources
|
||||||
docker system prune -f --volumes || {
|
sudo docker system prune -f --volumes || {
|
||||||
warning "Failed to clean up Docker resources"
|
warning "Failed to clean up Docker resources"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ success "🎉 Deployment completed successfully!"
|
|||||||
log "🌐 Application is available at: http://localhost:$DEPLOY_PORT"
|
log "🌐 Application is available at: http://localhost:$DEPLOY_PORT"
|
||||||
log "🏥 Health check endpoint: http://localhost:$DEPLOY_PORT/api/health"
|
log "🏥 Health check endpoint: http://localhost:$DEPLOY_PORT/api/health"
|
||||||
log "📊 Container name: $CONTAINER_NAME"
|
log "📊 Container name: $CONTAINER_NAME"
|
||||||
log "📝 Logs: docker logs $CONTAINER_NAME"
|
log "📝 Logs: sudo docker logs $CONTAINER_NAME"
|
||||||
|
|
||||||
# Update deployment log
|
# Update deployment log
|
||||||
echo "$(date): Deployment successful - Port: $DEPLOY_PORT - Image: $IMAGE_NAME:$TIMESTAMP" >> "$LOG_FILE"
|
echo "$(date): Deployment successful - Port: $DEPLOY_PORT - Image: $IMAGE_NAME:$TIMESTAMP" >> "$LOG_FILE"
|
||||||
|
|||||||
Reference in New Issue
Block a user