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