【问题标题】:how to start an eventstore in Gitlab-CI test如何在 Gitlab-CI 测试中启动事件存储
【发布时间】:2019-02-28 15:52:02
【问题描述】:

我的 gitlab 存储库中有以下代码

package.json

{ 
  ...
  "scripts": {
    "test": "mocha --require ts-node/register --watch-extensions ts,tsx \"src/**/*.{spec,test}.{ts,tsx}\""
  }
  ...
}

.gitlab-ci.yml

stages:
  - test
test:
  image: node:8
  stage: test
  script:
    - npm install
    - npm run test

test.ts

import { exec } from 'child_process';
import { promisify } from 'util';

const Exec = promisify(exec);
describe(test, async () => {
  before(async () => {
    // next line doesn't work in GitLab-CI
    await Exec(`docker run -d --rm -p 1113:1113 -p 2113:2113 eventstore/eventstore`);
    // an so on
  })
});

当我在本地机器上运行“npm run test”时效果很好。

我的问题是如何在 Gitlab-CI 中运行此测试?

【问题讨论】:

    标签: unit-testing gitlab-ci


    【解决方案1】:

    如果您尝试运行连接到 eventstore docker 的测试,您可以使用 gitlab 服务:

    GitLab CI 使用 services 关键字来定义 docker 容器 应该与您的基本图像相关联。

    首先,您需要设置docker executor

    那么您将能够将 eventstore 用作服务。这是example with postgres。更多信息here

    例子:

    test_server:
        tags:
          - docker
        services:
          - eventstore:latest
        script:
          - npm install && npm run test
    

    编辑:

    access服务:

    服务主机名的默认别名是根据其图像名称创建的

    或者使用alias

    services:
    - name: mysql:latest
      alias: mysql-1
    

    【讨论】:

    • 我一直在使用这种方法,但无法访问 eventstore。然后发现无法使用localhost访问eventstore服务,因为服务运行在172.17.0.2。 IP 可以从 eventstore 在 'EVENTSTORE_EVENTSTORE_PORT_1113_TCP_ADDR' 处创建的环境变量中获取
    • @simon 您可以在此处阅读有关如何访问该服务的信息:docs.gitlab.com/ee/ci/docker/…。我将编辑回复
    猜你喜欢
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 2015-10-24
    • 2017-11-14
    • 2018-01-10
    相关资源
    最近更新 更多