In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to analyze the sustainable delivery problems based on Docker. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
From the standpoint of testing, we hope that all the code written by the developer will be unit tested by the developer, but in fact, there is always a gap between ideal and reality, so why don't we develop the deployment environment and automate the testing of the service. The overall design idea is to develop the written code, use Dockerfile to build the image file, and then use docker-compose to start the image file automatically. the next step is actually very simple. We carry out intelligent automatic verification here, issue a specific test report at the end of the test and trigger the overall alarm mechanism if there is a problem. Mainly combined with CI continuous integration tools, the process is fully automated, as well as intelligent process. Of course, the main technology stack used is Spring Boot.
After creating the Spring Boot project, this place simply writes a test interface. The controller layer source code is as follows:
Package com.example.app;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class AppController {@ RequestMapping ("/ index") public String hello () {return "Hello SpringBoot!";} @ RequestMapping ("/ testDev") public String testDev () {return "Test developer";}}
This part of the code is actually relatively simple, so I won't explain it in detail here. After writing the code, write the Dockerfile file to build the image. The location where the Dockerfile is stored in the project is the docker folder under src/main. After creating the docker folder, create the Dockerfile file in it, and then write the content information to build the image in the package. The specific directory structure is as follows:
The contents of the Dockerfile folder are:
FROM java:8MAINTAINER VOLUME / tmpRUN mkdir / appCOPY app-0.0.1-SNAPSHOT.jar / app/app.jarWORKDIR / appEXPOSE 8081CMD ["java", "- Djava.security.egd=file:/dev/./urandom", "- jar", "app.jar"]
Next, create a docker-compose.yml file in the folder of docker, where the image resources, network and the process of starting and stopping are mainly defined. The content information of this file is as follows:
Version: '3.2'services: app: image: app:0.0.1-SNAPSHOT hostname: localhost ports:-"8081 app 8081" networks:-mynetworknetworks: mynetwork: external: true
You can see in the above file that the custom network is mynetwork. You can create a network in docker and view the existing network information, as shown below:
Docker network lsNETWORK ID NAME DRIVER SCOPE5e0d06b35341 bridge bridge local34f731bed1dc host host local4b5926f1e44d mynetwork bridge local
Next, write the code for the test. The code for the test is written in Python language combined with the Pytest test framework. The source code of the test module test_sprintboot.py is as follows:
Import requestsimport pytest def test_springboot_index (): r=requests.get ("http://localhost:8081/index") assert r.status_code==200def test_springboot_testDev (): r=requests.get (" http://localhost:8081/testDev") assert r.status_code==200)
This test code is relatively simple, and the main thing that needs to be verified here is the intelligent verification after service automation deployment.
After making the preparations as above, let's go down to create the Pipeline project in Jenkins. The script for Pipeline script is as follows:
Pipeline {agent any stages {stage ('build the image') {steps {sh' cd / Applications/code/workSpace/data/app mvn clean package-Dmaven.test.skip=true docker:build'''}} stage ('run the container') {steps {sh' '' cd / Applications/code/workSpace/data/app/src/main/docker docker-compose up-d''}} stage ('smoke test') {steps {sh' cd / Applications/code/workSpace/data/app/src/main/docker sleep 10s python3-m pytest-v test_ Springboot.py'''}
Next, start the process of building and executing in CI. The visual interface information after building is as follows:
Only some of the details of the output are shown here, as follows:
= 2 passed, 3 warnings in 0.72s = [Pipeline]} [Pipeline] / / stage [Pipeline]} [Pipeline] / / node [Pipeline] End of PipelineFinished: SUCCESS
For the quality delivery team, the point to think about is how we can combine existing technologies to achieve our goals and the means of quality verification. In fact, a process of verifying the R & D system is that the developer needs to unit test the code he has written anyway, so that a system can be verified through a continuous pipeline of the overall system, so as to improve the efficiency of delivery and submit high-quality code to the test team.
The above is the analysis of how to carry out Docker-based sustainable delivery problems shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.