Service elasticsearch is not visible when run tests

前端 未结 1 971
时光取名叫无心
时光取名叫无心 2021-01-23 10:00
name: Rspec
on: [push]
jobs:
  build:
    runs-on: [self-hosted, linux]
    services:
      elasticsearch:
        image: docker.         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-23 10:43

    You have to map the ports of your service containers and use localhost:host-port as address in your steps running on the GitHub Actions runner.

    If you configure the job to run directly on the runner machine and your step doesn't use a container action, you must map any required Docker service container ports to the Docker host (the runner machine). You can access the service container using localhost and the mapped port.

    https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idservices

    name: Rspec
    on: [push]
    jobs:
      build:
        runs-on: [self-hosted, linux]
        services:
          elasticsearch:
            image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
            env:
              discovery.type: single-node
            options: >-
              --health-cmd "curl http://localhost:9200/_cluster/health"
              --health-interval 10s
              --health-timeout 5s
              --health-retries 10
            ports:
            # :
            - 9200:9200
          redis:
            image: redis
            options: --entrypoint redis-server
        steps:
          - uses: actions/checkout@v2
          - name: running tests
            run: |
              sleep 60
              curl -X GET http://localhost:9200/
    

    Alternative: Also run your job in a container. Then the job has to access the service containers by hostname.

    name: Rspec
    on: [push]
    jobs:
      build:
        services:
          elasticsearch:
            image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
            env:
              discovery.type: single-node
            options: >-
              --health-cmd "curl http://localhost:9200/_cluster/health"
              --health-interval 10s
              --health-timeout 5s
              --health-retries 10
          redis:
            image: redis
            options: --entrypoint redis-server
        # Containers must run in Linux based operating systems
        runs-on: [self-hosted, linux]
        # Docker Hub image that this job executes in, pick any image that works for you
        container: node:10.18-jessie
        steps:
          - uses: actions/checkout@v2
          - name: running tests
            run: |
              sleep 60
              curl -X GET http://elasticsearch:9200/
    

    0 讨论(0)
提交回复
热议问题