Neo4j docker in GitHub action

Hi all,

I am trying to setup a neo4j service in a GitHub action. For now, the action yml contains:

    services:
      # Label used to access the service container
      neo4j:
        # Docker Hub image
        image: neo4j:latest
        env:
          # install GDS at startup
          NEO4JLABS_PLUGINS: '["graph-data-science"]'
          NEO4J_AUTH: neo4j/${{ secrets.NEO4J_PASSWORD }}
          NEO4J_dbms_connector_bolt_advertised__address: localhost:7687
        ports:
          # Maps bolt port
          - 7687:7687

[...]

    steps:

[...]

    - name: Test with pytest
      env:
        NEO4J_URI: "bolt://localhost:${{ job.services.postgres.ports[7687] }}"
        NEO4J_PASSWORD: ${{ secrets.NEO4J_PASSWORD }}
      run: |
        pytest

(I have cut parts that seems irrelevant to me, but full file is here: https://github.com/stellasia/pygds/blob/master/.github/workflows/python-package.yml)

But most of the time, the tests fail with neo4j._exceptions.BoltHandshakeError: Connection to localhost:7687 closed without handshake response (not always though) which makes me think that neo4j is not totally initialized when tests start, but I have no clue how to check this hypothesis and fix it if it turns to be true.

Has someone already run into the same issue?

Thanks!

Hi Estelle,

It might be a bit late, but I had the same issue as you and managed to solve it. In my case it was due to the tests running before the neo4j DB was fully initialised. The solution was to set some healthchecks to be sure the DB is ready before running the test command:

    services:
      neo4j:
        image: neo4j:4.2.0-enterprise
        env:
          NEO4J_dbms_security_procedures_unrestricted: apoc.*
          NEO4J_dbms_connector_bolt_enabled: "true"
          NEO4J_apoc_import_file_enabled: "true"
          NEO4J_apoc_export_file_enabled: "true"
          NEO4J_apoc_import_file_use__neo4j__config: "true"
          NEO4J_ACCEPT_LICENSE_AGREEMENT: "yes"
          NEO4J_dbms_security_auth__enabled: "false"
          NEO4J_dbms_connector_bolt_advertised__address: localhost:7687
          NEO4JLABS_PLUGINS: '["apoc"]'
        options: >-
          --health-cmd "cypher-shell 'match (n) return count(n)'"
          --health-timeout 10s
          --health-retries 20
          --health-interval 10s
          --health-start-period 30s
        ports:
          - 7687:7687

Another unrelated issue in your example is that you are using postgres instead of neo4j when trying to resolve the port number: NEO4J_URI: "bolt://localhost:${{ job.services.postgres.ports[7687] }}"

Hi Anthony,

Thank you so much for your answer! The problem was actually never totally solved, I used some ugly workarounds to make it work but will experiment with your solution in the coming days.