Check docker run in Gitlab CICD pipeline

南楼画角 提交于 2019-12-22 14:59:25

问题


I'm using Gitlab CI/CD to build Docker images of our Node server.

I am wondering if there is a way to test that docker run of the image was ok.

We've had few occasions where the Docker builds but it is missing some files/env variables and it fails to start the server.

Is there any way to run the docker image and test if it is starting up correctly in the CI/CD pipeline?

Cheers.


回答1:


With Gitlab you are able to use a docker-runner.

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.

Chek this docs from gitlab:

This is a classic yml from that web:

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

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

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  


来源:https://stackoverflow.com/questions/58229210/check-docker-run-in-gitlab-cicd-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!