gpt4 book ai didi

docker - 构建失败但 Gitlab 中的工作状态为成功

转载 作者:行者123 更新时间:2023-12-04 13:43:05 25 4
gpt4 key购买 nike

我的 Dockerfile:

FROM mm_php:7.1

ADD ./docker/test/source/entrypoint.sh /work/entrypoint.sh
ADD ./docker/wait-for-it.sh /work/wait-for-it.sh
RUN chmod 755 /work/entrypoint.sh \
&& chmod 755 /work/wait-for-it.sh

ENTRYPOINT ["/work/entrypoint.sh"]

入口点.sh:

#!/bin/bash -e

/work/wait-for-it.sh db:5432 -- echo "PostgreSQL started"

./vendor/bin/parallel-phpunit --pu-cmd="./vendor/bin/phpunit -c phpunit-docker.xml" tests

docker-compose.yml:

version: '2'
services:

test:
build:
context: .
args:
ssh_prv_key: ${ssh_prv_key}
application_env: ${application_env}
dockerfile: docker/test/source/Dockerfile
links:
- db

db:
build:
context: .
dockerfile: docker/test/postgres/Dockerfile
environment:
PGDATA: /tmp

.gitlab-ci.yml:

image: docker:latest

services:
- name: docker:dind
command: ["--insecure-registry=my.domain:5000 --registry-mirror=http://my.domain"]

before_script:
- apk add --no-cache py-pip
- pip install docker-compose
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

test:
stage: test
script:
- export ssh_prv_key="$(cat ~/.ssh/id_rsa)" && export application_env="testing-docker" && docker-compose up --build test

一切正常。但是如果测试失败,Gitlab 中的作业状态是 SUCCESS 而不是 FAILED。

如果测试失败,如何获取状态FAILED?

UPD

如果我在本地运行 docker-compose up,它不会返回任何错误代码:

$ export ssh_prv_key="$(cat ~/.ssh/id_rsa)" && export application_env="testing-docker" && docker-compose up --build test
Building db
Step 1/2 : FROM mm_postgres:9.6
...
test_1 | FAILURES!
test_1 | Tests: 1, Assertions: 1, Failures: 1.
test_1 | Success: 2 Fail: 2 Error: 0 Skip: 2 Incomplete: 0
mmadmin_test_1 exited with code 1

$ echo $?
0

最佳答案

在我看来,它报告测试失败,但不一定报告 docker-compose 调用的返回值失败。您是否尝试过在本地测试失败时捕获 docker-compose 的返回值?

为了让 docker-compose 从特定服务返回退出代码,试试这个:

docker-compose up --exit-code-from=service

关于docker - 构建失败但 Gitlab 中的工作状态为成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49736193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com