Creates Docker files and runs docker-compose for Neo4j.
()
| 958 | setup_local_binary() |
| 959 | |
| 960 | def setup_docker(): |
| 961 | """Creates Docker files and runs docker-compose for Neo4j.""" |
| 962 | console.print("\n[bold cyan]Setting up Neo4j with Docker...[/bold cyan]") |
| 963 | |
| 964 | # Prompt for password first |
| 965 | console.print("Please set a secure password for your Neo4j database:") |
| 966 | password_questions = [ |
| 967 | {"type": "password", "message": "Enter Neo4j password:", "name": "password"}, |
| 968 | {"type": "password", "message": "Confirm password:", "name": "password_confirm"}, |
| 969 | ] |
| 970 | |
| 971 | while True: |
| 972 | passwords = prompt(password_questions) |
| 973 | if not passwords: |
| 974 | return # User cancelled |
| 975 | |
| 976 | password = passwords.get("password", "") |
| 977 | if password and password == passwords.get("password_confirm"): |
| 978 | break |
| 979 | console.print("[red]Passwords do not match or are empty. Please try again.[/red]") |
| 980 | |
| 981 | # Create data directories |
| 982 | neo4j_dir = Path.cwd() / "neo4j_data" |
| 983 | for subdir in ["data", "logs", "conf", "plugins"]: |
| 984 | (neo4j_dir / subdir).mkdir(parents=True, exist_ok=True) |
| 985 | |
| 986 | # Fixed docker-compose.yml content |
| 987 | docker_compose_content = f""" |
| 988 | services: |
| 989 | neo4j: |
| 990 | image: neo4j:5.21 |
| 991 | container_name: neo4j-cgc |
| 992 | restart: unless-stopped |
| 993 | ports: |
| 994 | - "7474:7474" |
| 995 | - "7687:7687" |
| 996 | environment: |
| 997 | - NEO4J_AUTH=neo4j/{password} |
| 998 | - NEO4J_ACCEPT_LICENSE_AGREEMENT=yes |
| 999 | volumes: |
| 1000 | - neo4j_data:/data |
| 1001 | - neo4j_logs:/logs |
| 1002 | |
| 1003 | volumes: |
| 1004 | neo4j_data: |
| 1005 | neo4j_logs: |
| 1006 | """ |
| 1007 | |
| 1008 | # Write docker-compose.yml |
| 1009 | compose_file = Path.cwd() / "docker-compose.yml" |
| 1010 | with open(compose_file, "w") as f: |
| 1011 | f.write(docker_compose_content) |
| 1012 | |
| 1013 | console.print("[green]✅ docker-compose.yml created with secure password.[/green]") |
| 1014 | |
| 1015 | # Validate configuration format before attempting Docker operations |
| 1016 | console.print("\n[cyan]🔍 Validating configuration...[/cyan]") |
| 1017 | from codegraphcontext.core.database import DatabaseManager |
no test coverage detected