diff --git a/logs/portfolio-deploy.log b/logs/portfolio-deploy.log new file mode 100644 index 0000000..c24d0a5 --- /dev/null +++ b/logs/portfolio-deploy.log @@ -0,0 +1,3 @@ +[2025-09-05 20:43:45] ๐Ÿš€ Starting automatic deployment for portfolio +[2025-09-05 20:43:45] ๐Ÿ“‹ Step 1: Running code quality checks... +[WARNING] You have uncommitted changes. Committing them... diff --git a/scripts/auto-deploy.sh b/scripts/auto-deploy.sh index 8632444..f8e54d4 100755 --- a/scripts/auto-deploy.sh +++ b/scripts/auto-deploy.sh @@ -11,7 +11,7 @@ CONTAINER_NAME="portfolio-app" IMAGE_NAME="portfolio-app" PORT=3000 BACKUP_PORT=3001 -LOG_FILE="/var/log/portfolio-deploy.log" +LOG_FILE="./logs/portfolio-deploy.log" # Colors for output RED='\033[0;31m' @@ -44,7 +44,7 @@ if [[ $EUID -eq 0 ]]; then fi # 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." exit 1 fi @@ -107,14 +107,14 @@ log "๐Ÿณ Step 3: Docker operations..." # Build Docker image log "๐Ÿ—๏ธ Building Docker image..." -docker build -t "$IMAGE_NAME:latest" . || { +sudo docker build -t "$IMAGE_NAME:latest" . || { error "Docker build failed" exit 1 } # Tag with timestamp 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" @@ -122,10 +122,10 @@ success "โœ… Docker image built successfully" log "๐Ÿš€ Step 4: Deploying application..." # 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..." - docker stop "$CONTAINER_NAME" || true - docker rm "$CONTAINER_NAME" || true + sudo docker stop "$CONTAINER_NAME" || true + sudo docker rm "$CONTAINER_NAME" || true fi # Check if port is available @@ -138,7 +138,7 @@ fi # Start new container log "๐Ÿš€ Starting new container on port $DEPLOY_PORT..." -docker run -d \ +sudo docker run -d \ --name "$CONTAINER_NAME" \ --restart unless-stopped \ -p "$DEPLOY_PORT:3000" \ @@ -189,22 +189,22 @@ fi # Show 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 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 log "๐Ÿงน Step 6: Cleaning up old images..." # 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" } # Clean up unused Docker resources -docker system prune -f --volumes || { +sudo docker system prune -f --volumes || { 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 "๐Ÿฅ Health check endpoint: http://localhost:$DEPLOY_PORT/api/health" log "๐Ÿ“Š Container name: $CONTAINER_NAME" -log "๐Ÿ“ Logs: docker logs $CONTAINER_NAME" +log "๐Ÿ“ Logs: sudo docker logs $CONTAINER_NAME" # Update deployment log echo "$(date): Deployment successful - Port: $DEPLOY_PORT - Image: $IMAGE_NAME:$TIMESTAMP" >> "$LOG_FILE"