在GitLab CI/CD作业中执行服务 [英] Exec into service in the context of GitLab CI/CD job
问题描述
我想使用GitLab CI/CD进行涉及两个容器的测试.该测试要求两个容器都启动,然后在其中一个容器中运行脚本(其语义类似于 kubectl exec ... script.sh
或 docker exec ...脚本.sh
).我已经尝试使用 服务
对此模型进行建模收到上一个答案:
I want to employ GitLab CI/CD for a test that involves two containers. The test requires that both containers are up and that a script is then run in one of them (with semantics akin to kubectl exec ... script.sh
or docker exec ... script.sh
). I've tried modeling this with services
thanks to a previous answer received:
my_test:
stage: test
services:
- my_image_2
image: my_image_1
script:
- my_script.sh
但是,与此有关的问题是,现在有效的 my_script.sh
替换了 my_image_1
的入口点.然后,容器的行为会有所不同,这显然会使测试失败.是否有一种已知的模式可以克服这种情况,在概念上类似于 script:["docker exec ... script.sh"]
?
However, the problem with this is that my_script.sh
now in effect replaces the entrypoint of my_image_1
. The container then behaves differently and this obviously makes the test fail. Is there a known pattern for overcoming this situation, something conceptually akin to script: ["docker exec ... script.sh"]
?
我考虑过还将 my_image_1
作为服务运行.但这是一个Web服务器,因此例如内部没有运行 sshd
,因此也没有外部连接可用于执行脚本.我还考虑过在 script:
的第一步中添加/entrypoint.sh&
,但这似乎是一种hack,并且在第二步时还需要进行额外的运行状况检查,因为Web服务器在后台启动的速度相对较慢,因此必须延迟 my_script.sh
(第3步).什么是前进的好方法?
I have considered running also my_image_1
as service. But it is a web server, so there is e.g. no sshd
running inside, hence no outside connectivity for executing the script either. I've also considered adding /entrypoint.sh &
as first step in script:
, but this seems like a hack and would also require an additional health check as 2nd step, because the web server's start in the background will be relatively slow, so my_script.sh
(the then 3rd step) would have to be delayed. What is a good way forward?
推荐答案
您可以覆盖入口点,并根据需要设置其行为.
You can override the entrypoint of the image specified with the entrypoint
keyword and set it how you want it to behave.
my_test:
stage: test
services:
- my_image_2
image:
name: my_image_1
entrypoint: [""]
script:
- my_script.sh
这篇关于在GitLab CI/CD作业中执行服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!