运行测试时,服务elasticsearch不可见 [英] Service elasticsearch is not visible when run tests
问题描述
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"
因此,在服务/容器内部,我看到一个主机弹性搜索,但在步骤运行测试中没有.我能做什么?
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.
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/
这篇关于运行测试时,服务elasticsearch不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!