运行测试时服务弹性搜索不可见 [英] Service elasticsearch is not visible when run tests

查看:21
本文介绍了运行测试时服务弹性搜索不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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
      redis:
        image: redis
        options: --entrypoint redis-server
    steps:
      - uses: actions/checkout@v2
      - name: running tests
        run: |
          sleep 60
          curl -X GET http://elasticsearch:9200/

我正在运行自托管的测试,我在带有 docker ps 的主机上看到容器(redis 和 elasticsearch)进行测试时.

I am running tests self hosted, I see on host with docker ps the containers (redis and elasticsearch) when they up to test.

我访问了一个 redis 容器,安装了一个 curl 并运行 curl -X GET http://elasticsearch:9200/ 并且我在 60 秒之前看到一个响应正常(等待时间服务)

I access a container of redis, install a curl and run curl -X GET http://elasticsearch:9200/ and i see a response ok before 60 sec (wait time to service up)

运行测试步骤中,我收到错误消息无法解析主机:elasticsearch"

On step running tests I got error message "Could not resolve host: elasticsearch"

因此,在服务/容器 redis 中,我看到了一个主机 elasticsearch,但在步骤 running tests 中没有.我能做什么?

So, inside service/container redis I see a host elasticsearch but on step running tests no. What I can do?

推荐答案

您必须映射服务容器的端口,并在 GitHub 上运行的步骤中使用 localhost:host-port 作为地址动作亚军.

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.

如果您将作业配置为直接在运行器机器上运行并且您的步骤不使用容器操作,则您必须将任何必需的 Docker 服务容器端口映射到 Docker 主机(运行器机器).您可以使用 localhost 和映射端口访问服务容器.

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:
        # <port on host>:<port on container>
        - 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/

这篇关于运行测试时服务弹性搜索不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆