问题
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