我正在使用Gitlab CI/CD构建我们的Node服务器的Docker映像。
我想知道是否有一种方法可以测试图像的docker run
正常。
我们很少有构建Docker的场合,但是它缺少一些文件/ env变量,并且无法启动服务器。
有没有办法运行docker
映像并测试CI / CD管道中的映像是否正确启动?
干杯。
使用Gitlab,您可以use a docker-runner。
[当您使用docker-runner而不是shell运行器时,类似docker图片及其服务必须启动,如果出现错误失败。
Chek this docs from 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在加载图像时应检测到任何错误
如果您是doing it with the shell gitlab-runner,则应致电码头工人形象开始像这样:
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