检查docker在Gitlab CICD管道中运行 [英] Check docker run in Gitlab CICD pipeline
问题描述
我正在使用 Gitlab CI / CD 构建以下内容的Docker映像:我们的节点服务器。
I'm using Gitlab CI/CD to build Docker images of our Node server.
我想知道是否有一种方法可以测试图像的 docker run
正常
I am wondering if there is a way to test that docker run
of the image was ok.
我们很少构建Docker,但是缺少一些文件/ env变量,因此无法启动服务器。
We've had few occasions where the Docker builds but it is missing some files/env variables and it fails to start the server.
有什么方法可以运行 docker
映像并测试它在CI / CD管道中是否正确启动?
Is there any way to run the docker
image and test if it is starting up correctly in the CI/CD pipeline?
干杯。
推荐答案
使用Gitlab,您可以使用docker-runner 。
With Gitlab you are able to use a docker-runner.
当您使用docker-runner而不是shell运行器时,类似docker的
映像及其服务必须初始化,如果
某些操作失败,则应该给出错误。
When you use the docker-runner, and not a shell runner, a docker-like image and its services have to initiate, it should give an error if something fails.
检查来自gitlab的文档:
这是该网站上的经典 yml
:
default:
image:
name: ruby:2.2
entrypoint: ["/bin/bash"]
services:
- name: my-postgres:9.4
alias: db-postgres
entrypoint: ["/usr/local/bin/db-postgres"]
command: ["start"]
before_script:
- bundle install
test:
script:
- bundle exec rake spec
如您所见,测试部分将在构建映像后执行,因此,您不必担心。 Gitlab在加载图像时应该检测到任何错误
As you see, the test sections will be executed after building the image, so, you should not have to worry about. Gitlab should detect any errors when loading the image
如果您使用shell gitlab-runner 来执行此操作,您应该像这样调用
docker镜像开始:
If you are doing it with the shell gitlab-runner, you should call the docker image start like this:
stages:
- dockerStartup
- build
- test
- deploy
- dockerStop
job 0:
stage: dockerStartup
script:
- docker build -t my-docker-image .
- docker run my-docker-image /script/to/run/tests
[...] //your jobs here
job 5:
stage: dockerStop
script: docker stop whatever
这篇关于检查docker在Gitlab CICD管道中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!