In Jenkins pipeline, using Groovy DSL, how do I spin up a Docker image in the background?

We had a Jenkins build system, using the Groovy DSL, that worked well for us.

But then we recently hired a new developer who is supposed to be very good. He decided to rewrite the way our tests work. We are now trying to make our build process adjust to his new ideas. We have a Python app. Previously, our build system went something like this:

git pull

run tests

if good, then push to ECR

Simple.

But he pulled all the tests into a separate container. So now I need to do something like:

  1. 'docker build' the main app

  2. 'docker run' the main app

  3. 'docker build' the test app

  4. 'docker run' the test app (this fires HTTP requests at the main app)

  5. get results from test app

  6. shut down main app

  7. if test results good, push to ECR

But when I call 'docker run' on the main app, it just runs forever. It's a Python web app, Django, with Gunicorn serving the web requests.

So, what do I do here? Should I spin the main app up in a separate thread, perhaps with a time to automatically kill it after a certain amount of time?

1
задан 26 July 2018 в 16:45
1 ответ

Вы используете docker run -d ... с параметром -d , чтобы отсоединиться от контейнера? Может быть, в этом проблема?

Edit

Я думаю, вы обнаружите, что вам нужно запустить docker run -d , чтобы отсоединиться от контейнера, иначе он просто останется на первом контейнере с отображением STDOUT пока Дженкинс не убьет контейнер, когда он остановит работу. Я бы просто запустил их и дал им имя, а затем в конце задания Jenkins остановил и удалил все контейнеры с этим именем.

Пример:

docker run -d --name jenkins-main-app main-app 
docker run -d --name jenkins-test-app test-app 

Затем в конце:

docker stop --name jenkins-main-app
docker stop --name jenkins-test-app
docker rm --name jenkins-main-app
docker rm --name jenkins-test-app

Надеюсь, что это поможет.

0
ответ дан 4 December 2019 в 03:47

Теги

Похожие вопросы