在自托管 GitHub Actions 运行程序中连接到 Redis 服务时出现问题

问题描述 投票:0回答:1

我正在尝试设置 GitHub Actions 工作流程来运行我的单元测试,其中包括 Redis 服务容器。我已按照文档此处中的所有步骤进行操作,但遇到错误。

redis.exceptions.ConnectionError: Error -2 connecting to redistester:6380. Name or service not known.

这是我的工作流程配置的相关部分:

name: Start Unit Tests
run-name: Testing ${{ github.ref }} for ${{ github.actor }}
on:
  workflow_call:

jobs:
  pytest:
    timeout-minutes: 30
    runs-on: self-hosted

    # Service containers to run with `runner-job`
    services:
      # Label used to access the service container
      redistester:
        # Docker Hub image
        image: redis:7.2.1-alpine
        # Set health checks to wait until redis has started
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Maps port 6380 on service container to the host
          - 6380:6379

    steps:
      - name: Run unit tests
        run: python3.12 manage.py test tests.sockets --debug-mode --noinput
        env:
          REDIS_HOST: redistester
          REDIS_PORT: 6380

测试运行期间Redis服务是否需要额外配置才能正常访问?

任何帮助将不胜感激!

生产实例也在同一台机器上运行,这需要我更改端口。

此外,所有单元测试都在本地成功。只是不在跑步者中。

docker ps -a
>

CONTAINER ID   IMAGE                                   COMMAND                  CREATED          STATUS                     PORTS                                                                 
                                                                       NAMES
fb76367e1d52   redis:7.2.1-alpine                      "docker-entrypoint.s…"   14 seconds ago   Up 11 seconds (healthy)    0.0.0.0:6380->6379/tcp, :::6380->6379/tcp                             
                                                                       13e28f6bf7644a87aa7931ccf2667369_redis721alpine_e6c6aa
docker redis github-actions cicd
1个回答
0
投票

您正在尝试与

HOST: redistester
互动,这只是一个标签,主持人是
localhost

您也可以在单元测试中看到它。

© www.soinside.com 2019 - 2024. All rights reserved.