简体   繁体   English

Gitlab CI/CD 管道中 SpringBoot 服务的健康检查

[英]Healthcheck of SpringBoot service in Gitlab CI/CD pipeline

I have a Gitlab CI/CD pipeline which:我有一个 Gitlab CI/CD 管道,它:

  • builds Spring Boot app构建 Spring Boot 应用程序
  • packages it to a Docker image将其打包为 Docker 镜像
  • deploy the image using docker run ...使用docker run ...部署映像docker run ...

I'd like to be able to validate the service after deployment.我希望能够在部署后验证服务。 I want to be informed by the pipeline about the failure.我想通过管道通知失败。 I guess I need an additional healthcheck step in the pipeline to validate the service.我想我需要在管道中进行额外的健康检查步骤来验证服务。

Is there any best practices for this task?此任务是否有最佳实践? Is there any ready to use solutions?有没有现成的解决方案?

It's possible to implement the check using spring actuator + curl + grep .可以使用spring 执行器+ curl + grep来实现检查。

The pipeline:管道:

check-spring-actuator-health:
  image: curlimages/curl
  stage: Health Ckeck
  script:
# exit with error if actuator/health doesn't return 'UP'
    - curl $ACTUATOR_HEALTH_URL | grep "{\"status\":\"UP\"}" || ( echo Helth Check Failed Actuator=$ACTUATOR_HEALTH_URL && exit 2; )

This step fails it the actruator/health URL isn't available or returns anything but {"status":"UP"}如果执行器/健康 URL 不可用或返回除{"status":"UP"}任何内容,则此步骤失败

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM