繁体   English   中英

等效于 GitLab CI/CD 中的健康检查测试

[英]Equivalent of healthcheck test in GitLab CI/CD

我有这个docker-compose.yml

version: '3.4'

services:
  localstack:
    image: localstack/localstack:0.11.2
    environment: 
      - AWS_DEFAULT_REGION=us-east-1
      - EDGE_PORT=4566
      - SERVICES=sns,sqs
    ports:
      - "4566:4566"
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
    healthcheck:
      test:
        - CMD
        - bash
        - -c
        - awslocal sns list-topics
          && awslocal sqs list-queues
      interval: 5s
      timeout: 10s
      retries: 10

这样,它会利用容器具有可用的awslocal命令来检查 healtheck。

假设我需要对 localstack 运行一些测试并且我想等待 localstack 服务启动并运行,那么 GitLab 的等价物是什么?

像这样的东西:

tests:
  stage: test
  services:
    - name: localstack/localstack:0.11.2
      alias: localstack
  variables:
    AWS_DEFAULT_REGION: "us-east-1"
    EDGE_PORT: "4566"
    SERVICES: "sns,sqs"
  before_script:
    # should I use before_script? is there a better way? What's the linux command to test the same and wait?
  script: dotnet test --blame --configuration Release
  rules:
    - exists:
      - test/**/*Tests.csproj

更新 1:一种可能的技巧是使用before_script ,但很高兴听到更好的内置解决方案。 这也不起作用

/bin/bash: line 125: awslocal: command not found
Failed rounds=9

但这是我的尝试

tests:
  stage: test
  services:
    - name: localstack/localstack:0.11.2
      alias: localstack
  variables:
    AWS_DEFAULT_REGION: "us-east-1"
    EDGE_PORT: "4566"
    SERVICES: "sns,sqs"
  before_script:
    - rounds=10;
      while [ $rounds -gt 0 ]; do
        awslocal sns list-topics && awslocal sqs list-queues && echo OK && break || echo Failed
        rounds=$(($rounds - 1));
        sleep 5;
      done;
  script: dotnet test --blame --configuration Release
  rules:
    - exists:
      - test/**/*Tests.csproj

这是一个可能的工作解决方案。 请注意,尽管在 localstack 容器中有可用的 awslocal(可能需要安装某些东西),但我不能在服务中使用 awslocal。

无论如何,我用一个简单的 curl 解决了它。

tests:
  stage: test
  services:
    - name: localstack/localstack:0.11.2
      alias: localstack
  variables:
    AWS_DEFAULT_REGION: "us-east-1"
    EDGE_PORT: "4566"
    SERVICES: "sns,sqs"
  before_script:
    - rounds=10;
      while [ $rounds -gt 0 ]; do
        curl http://localstack:4566 && echo OK && break || echo FAIL
        rounds=$rounds - 1;
        sleep 5;
      done;
  script: dotnet test --blame --configuration Release
  rules:
    - exists:
      - test/**/*Tests.csproj

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM