fixing mem issue
This commit is contained in:
		
							
								
								
									
										46
									
								
								build-pi.sh
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								build-pi.sh
									
									
									
									
									
								
							@@ -96,33 +96,23 @@ build_container() {
 | 
				
			|||||||
        exit 1
 | 
					        exit 1
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Build with memory limits for Pi Zero
 | 
					    # Build without memory limits (they may not be supported on all systems)
 | 
				
			||||||
    if [[ "$ARCH" == "armv6l" ]] && [ $TOTAL_MEM_MB -lt 512 ]; then
 | 
					 | 
				
			||||||
        print_warning "Building with memory constraints..."
 | 
					 | 
				
			||||||
    ${RUNTIME} build \
 | 
					    ${RUNTIME} build \
 | 
				
			||||||
            --memory-swap -1 \
 | 
					 | 
				
			||||||
        --file "${DOCKERFILE}" \
 | 
					        --file "${DOCKERFILE}" \
 | 
				
			||||||
        --tag "${IMAGE_NAME}" \
 | 
					        --tag "${IMAGE_NAME}" \
 | 
				
			||||||
        . || {
 | 
					        . || {
 | 
				
			||||||
        print_error "Build failed!"
 | 
					        print_error "Build failed!"
 | 
				
			||||||
            print_info "Try these solutions:"
 | 
					        if [ $TOTAL_MEM_MB -lt 512 ]; then
 | 
				
			||||||
 | 
					            print_info "Try these solutions for low memory:"
 | 
				
			||||||
            echo "  1. Add swap space:"
 | 
					            echo "  1. Add swap space:"
 | 
				
			||||||
            echo "     sudo dd if=/dev/zero of=/swapfile bs=1M count=1024"
 | 
					            echo "     sudo dd if=/dev/zero of=/swapfile bs=1M count=1024"
 | 
				
			||||||
            echo "     sudo mkswap /swapfile"
 | 
					            echo "     sudo mkswap /swapfile"
 | 
				
			||||||
            echo "     sudo swapon /swapfile"
 | 
					            echo "     sudo swapon /swapfile"
 | 
				
			||||||
            echo "  2. Use pre-built image:"
 | 
					            echo "  2. Use pre-built image:"
 | 
				
			||||||
            echo "     ${RUNTIME} pull docker.io/yourusername/turmli-calendar:armv6"
 | 
					            echo "     ${RUNTIME} pull docker.io/yourusername/turmli-calendar:armv6"
 | 
				
			||||||
            exit 1
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
        ${RUNTIME} build \
 | 
					 | 
				
			||||||
            --file "${DOCKERFILE}" \
 | 
					 | 
				
			||||||
            --tag "${IMAGE_NAME}" \
 | 
					 | 
				
			||||||
            . || {
 | 
					 | 
				
			||||||
            print_error "Build failed!"
 | 
					 | 
				
			||||||
            exit 1
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        fi
 | 
					        fi
 | 
				
			||||||
 | 
					        exit 1
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    print_success "Container image built successfully!"
 | 
					    print_success "Container image built successfully!"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -144,27 +134,25 @@ run_container() {
 | 
				
			|||||||
        print_info "Created cache file"
 | 
					        print_info "Created cache file"
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Run with appropriate resource limits for Pi
 | 
					    # Run container (without memory limits as they may not be supported)
 | 
				
			||||||
    if [[ "$ARCH" == "armv6l" ]] && [ $TOTAL_MEM_MB -lt 512 ]; then
 | 
					    print_info "Starting container..."
 | 
				
			||||||
        print_info "Running with memory constraints..."
 | 
					 | 
				
			||||||
        ${RUNTIME} run -d \
 | 
					 | 
				
			||||||
            --name ${CONTAINER_NAME} \
 | 
					 | 
				
			||||||
            --memory 256m \
 | 
					 | 
				
			||||||
            --memory-swap -1 \
 | 
					 | 
				
			||||||
            -p 8000:8000 \
 | 
					 | 
				
			||||||
            -v $(pwd)/calendar_cache.json:/app/calendar_cache.json:Z \
 | 
					 | 
				
			||||||
            -e TZ=Europe/Berlin \
 | 
					 | 
				
			||||||
            --restart unless-stopped \
 | 
					 | 
				
			||||||
            ${IMAGE_NAME}
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    ${RUNTIME} run -d \
 | 
					    ${RUNTIME} run -d \
 | 
				
			||||||
        --name ${CONTAINER_NAME} \
 | 
					        --name ${CONTAINER_NAME} \
 | 
				
			||||||
        -p 8000:8000 \
 | 
					        -p 8000:8000 \
 | 
				
			||||||
        -v $(pwd)/calendar_cache.json:/app/calendar_cache.json:Z \
 | 
					        -v $(pwd)/calendar_cache.json:/app/calendar_cache.json:Z \
 | 
				
			||||||
        -e TZ=Europe/Berlin \
 | 
					        -e TZ=Europe/Berlin \
 | 
				
			||||||
        --restart unless-stopped \
 | 
					        --restart unless-stopped \
 | 
				
			||||||
 | 
					        ${IMAGE_NAME} || {
 | 
				
			||||||
 | 
					        # If it fails with :Z flag (SELinux label), try without it
 | 
				
			||||||
 | 
					        print_warning "Retrying without SELinux labels..."
 | 
				
			||||||
 | 
					        ${RUNTIME} run -d \
 | 
				
			||||||
 | 
					            --name ${CONTAINER_NAME} \
 | 
				
			||||||
 | 
					            -p 8000:8000 \
 | 
				
			||||||
 | 
					            -v $(pwd)/calendar_cache.json:/app/calendar_cache.json \
 | 
				
			||||||
 | 
					            -e TZ=Europe/Berlin \
 | 
				
			||||||
 | 
					            --restart unless-stopped \
 | 
				
			||||||
            ${IMAGE_NAME}
 | 
					            ${IMAGE_NAME}
 | 
				
			||||||
    fi
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    print_success "Container started!"
 | 
					    print_success "Container started!"
 | 
				
			||||||
    print_info "Access the calendar at: http://$(hostname -I | awk '{print $1}'):8000"
 | 
					    print_info "Access the calendar at: http://$(hostname -I | awk '{print $1}'):8000"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user