CN118656085A - Microservice publishing method, device, terminal device and storage medium - Google Patents
Microservice publishing method, device, terminal device and storage medium Download PDFInfo
- Publication number
- CN118656085A CN118656085A CN202410786721.3A CN202410786721A CN118656085A CN 118656085 A CN118656085 A CN 118656085A CN 202410786721 A CN202410786721 A CN 202410786721A CN 118656085 A CN118656085 A CN 118656085A
- Authority
- CN
- China
- Prior art keywords
- image
- microservice
- micro
- file
- service
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/73—Program documentation
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Library & Information Science (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请公开了一种微服务发布方法、装置、终端设备以及存储介质,涉及微服务管理领域,其方法包括:获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像。本发明可以提高微服务的发布效率。
The present application discloses a microservice publishing method, apparatus, terminal device and storage medium, which relates to the field of microservice management. The method includes: obtaining branch code data; generating an image file according to the branch code data, and building a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generating a declarative file according to the microservice name and the branch information; and publishing the microservice image through a preset container orchestration cluster according to the declarative file. The present invention can improve the publishing efficiency of microservices.
Description
技术领域Technical Field
本发明涉及微服务管理领域,尤其涉及一种微服务发布方法、装置、终端设备以及存储介质。The present invention relates to the field of microservice management, and in particular to a microservice publishing method, apparatus, terminal equipment and storage medium.
背景技术Background Art
随着社会的不断发展和进步,微服务架构已经成为现代软件开发中的重要趋势之一,微服务架构将复杂的应用程序拆分成更小、更独立的服务组件,这些组件可以独立进行开发、测试和部署,从而提高了开发效率和产品质量,同时,微服务架构还支持快速迭代和灵活的扩展性,在微服务架构中,每个服务都可以独立进行开发、测试和部署,这意味着团队可以更加专注于自己的工作,减少了协作和沟通的成本。With the continuous development and progress of society, microservice architecture has become one of the important trends in modern software development. Microservice architecture splits complex applications into smaller and more independent service components, which can be developed, tested and deployed independently, thereby improving development efficiency and product quality. At the same time, microservice architecture also supports rapid iteration and flexible scalability. In the microservice architecture, each service can be developed, tested and deployed independently, which means that the team can focus more on their work and reduce the cost of collaboration and communication.
而目前常用的微服务发布方法依赖于手动操作和交互,即主要由开发人员手动执行微服务发布的各个步骤,过程繁琐、容易出错并且缺乏自动化和持续集成的特性,因此,该种微服务发布方法仍存在发布效率低下的问题。The currently commonly used microservice release method relies on manual operations and interactions, that is, developers mainly manually perform various steps of microservice release. The process is cumbersome, error-prone, and lacks automation and continuous integration features. Therefore, this microservice release method still has the problem of low release efficiency.
发明内容Summary of the invention
本发明的主要目的在于提供一种微服务发布方法、装置、终端设备以及存储介质,可以提高微服务的发布效率。The main purpose of the present invention is to provide a microservice publishing method, apparatus, terminal device and storage medium, which can improve the publishing efficiency of microservices.
为实现上述目的,本发明提供一种微服务发布方法,所述方法包括:To achieve the above object, the present invention provides a microservice publishing method, the method comprising:
获取分支代码数据;Get branch code data;
根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;Generate an image file according to the branch code data, and build a microservice image through the image file, wherein the microservice image includes a microservice name and branch information;
根据所述微服务名称和所述分支信息自动生成声明式文件;Automatically generate a declarative file according to the microservice name and the branch information;
根据所述声明式文件,通过预设的容器编排集群发布微服务镜像。According to the declarative file, the microservice image is published through a preset container orchestration cluster.
可选地,所述获取分支代码数据的步骤包括:Optionally, the step of obtaining branch code data includes:
获取目标代码;Get the object code;
将所述目标代码存储至代码仓库Gitlab;Storing the target code in the code repository Gitlab;
根据流程配置gitflow,由所述代码仓库Gitlab对所述目标代码进行分支管理,得到分支代码数据。According to the process configuration gitflow, the code warehouse Gitlab performs branch management on the target code to obtain branch code data.
可选地,所述根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息的步骤包括:Optionally, the step of generating an image file according to the branch code data, and building a microservice image through the image file, wherein the microservice image includes a microservice name and branch information, comprises:
获取镜像模板文件;Get the image template file;
根据所述镜像模板文件和代码版本号自动生成镜像文件,所述代码版本号包括在所述分支代码数据;Automatically generate an image file according to the image template file and the code version number, wherein the code version number is included in the branch code data;
根据所述镜像文件对所述分支代码数据进行镜像构建,得到微服务镜像,所述微服务镜像包括微服务名称以及分支信息中。The branch code data is mirrored according to the mirror file to obtain a microservice mirror, where the microservice mirror includes a microservice name and branch information.
可选地,所述根据所述微服务名称和所述分支信息自动生成声明式文件的步骤包括:Optionally, the step of automatically generating a declarative file according to the microservice name and the branch information includes:
获取声明式模板文件和发布指令;Get declarative template files and publishing instructions;
将所述微服务镜像发送至镜像仓库,由所述镜像仓库对所述微服务镜像进行存储管理;Send the microservice image to an image warehouse, which stores and manages the microservice image;
根据所述发布指令,从所述镜像仓库获取所述微服务名称和所述分支信息,根据所述声明式模板文件、所述微服务名称和所述分支信息自动生成声明式文件。According to the publishing instruction, the microservice name and the branch information are obtained from the image repository, and a declarative file is automatically generated according to the declarative template file, the microservice name and the branch information.
可选地,所述根据所述声明式文件,通过预设的容器编排集群发布微服务镜像的步骤包括:Optionally, the step of publishing the microservice image through a preset container orchestration cluster according to the declarative file includes:
根据所述分支信息中的环境类型,将所述声明式文件发送至预设的容器编排集群;Sending the declarative file to a preset container orchestration cluster according to the environment type in the branch information;
根据所述声明式文件,通过所述容器编排集群获取微服务镜像;According to the declarative file, obtain the microservice image through the container orchestration cluster;
通过所述容器编排集群,对所述微服务镜像进行发布。The microservice image is published through the container orchestration cluster.
可选地,所述根据所述声明式文件,通过所述容器编排集群获取微服务镜像的步骤包括:Optionally, the step of obtaining a microservice image through the container orchestration cluster according to the declarative file includes:
通过所述容器编排集群获取镜像仓库访问权限;Obtaining access rights to the image repository through the container orchestration cluster;
根据所述访问权限和镜像地址,通过所述容器编排集群在所述镜像仓库中拉取镜像,得到微服务镜像,所述镜像地址包括在所述声明式文件。According to the access permission and the image address, the image is pulled from the image repository through the container orchestration cluster to obtain a microservice image, and the image address is included in the declarative file.
可选地,所述通过所述容器编排集群,对所述微服务镜像进行发布的步骤之后包括:Optionally, after the step of publishing the microservice image through the container orchestration cluster, the step includes:
通过预设的容器管理平台rancher对所述微服务镜像进行监管,得到微服务数据,所述微服务数据包括微服务实例状态和日志信息;The microservice image is supervised by the preset container management platform Rancher to obtain microservice data, which includes microservice instance status and log information;
根据所述微服务实例状态和所述日志信息,通过所述容器管理平台rancher对微服务进行调整。According to the microservice instance status and the log information, the microservice is adjusted through the container management platform Rancher.
本申请实施例还提出一种微服务发布装置,所述微服务发布装置包括:The present application also provides a microservice publishing device, which includes:
数据获取模块,用于获取分支代码数据;A data acquisition module, used to acquire branch code data;
镜像构建模块,用于根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;An image building module, used to generate an image file according to the branch code data, and build a microservice image through the image file, wherein the microservice image includes a microservice name and branch information;
文件生成模块,用于根据所述微服务名称和所述分支信息自动生成声明式文件;A file generation module, used to automatically generate a declarative file according to the microservice name and the branch information;
微服务发布模块,用于根据所述声明式文件,通过预设的容器编排集群发布微服务镜像。The microservice publishing module is used to publish the microservice image through a preset container orchestration cluster according to the declarative file.
本申请实施例还提出一种终端设备,所述终端设备包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的微服务发布程序,所述微服务发布程序被所述处理器执行时实现如上所述的微服务发布方法的步骤。An embodiment of the present application also proposes a terminal device, which includes a memory, a processor, and a microservice publishing program stored in the memory and executable on the processor, wherein the microservice publishing program implements the steps of the microservice publishing method described above when executed by the processor.
本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质上存储有微服务发布程序,所述微服务发布程序被处理器执行时实现如上所述的微服务发布方法的步骤。An embodiment of the present application further proposes a computer-readable storage medium, on which a microservice publishing program is stored. When the microservice publishing program is executed by a processor, the steps of the microservice publishing method as described above are implemented.
本申请实施例提出的微服务发布方法、装置、终端设备以及存储介质,通过获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像,由于,镜像文件和声明式文件在微服务发布的过程中起到关键的作用,当有大量微服务需要进行发布时,对于每个微服务而言,每次的发布都需要手动修改对应的镜像文件以及声明式文件,过程十分繁琐且效率较低,而本方案中的镜像文件以及声明式文件是根据对应的数据自动生成的,不需要人为干预,因此,通过该方式,不仅可以极大地降低出错的概率,还可以使微服务的发布过程更具自动化,提高微服务整体的发布效率。The microservice publishing method, apparatus, terminal device and storage medium proposed in the embodiments of the present application obtain branch code data; generate an image file according to the branch code data, and build a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generate a declarative file according to the microservice name and the branch information; and publish the microservice image through a preset container orchestration cluster according to the declarative file. Since image files and declarative files play a key role in the microservice publishing process, when a large number of microservices need to be published, for each microservice, each publication requires manual modification of the corresponding image files and declarative files, and the process is very cumbersome and inefficient. The image files and declarative files in this solution are automatically generated according to the corresponding data, and no human intervention is required. Therefore, in this way, not only the probability of errors can be greatly reduced, but also the microservice publishing process can be made more automated, thereby improving the overall publishing efficiency of microservices.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1为本申请微服务发布装置所属终端设备的功能模块示意图;FIG1 is a schematic diagram of the functional modules of a terminal device to which the microservice publishing device of the present application belongs;
图2为本申请微服务发布方法第一示例性实施例的流程示意图;FIG2 is a flow chart of a first exemplary embodiment of a microservice publishing method of the present application;
图3为本申请微服务发布方法第二示例性实施例的流程示意图;FIG3 is a flow chart of a second exemplary embodiment of a microservice publishing method of the present application;
图4为本申请微服务发布方法第三示例性实施例的流程示意图;FIG4 is a flow chart of a third exemplary embodiment of a microservice publishing method of the present application;
图5为本申请微服务发布方法第四示例性实施例的流程示意图;FIG5 is a flowchart of a fourth exemplary embodiment of a microservice publishing method of the present application;
图6为本申请微服务发布方法第五示例性实施例的流程示意图;FIG6 is a flowchart of a fifth exemplary embodiment of a microservice publishing method of the present application;
图7为本申请微服务发布方法第六示例性实施例的流程示意图;FIG7 is a flowchart of a sixth exemplary embodiment of a microservice publishing method of the present application;
图8为本申请微服务发布方法第七示例性实施例的流程示意图;FIG8 is a flow chart of a seventh exemplary embodiment of the microservice publishing method of the present application;
图9为本申请微服务发布方法流程示意图。FIG9 is a flow chart of the microservice publishing method of the present application.
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings.
具体实施方式DETAILED DESCRIPTION
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
本申请实施例的主要解决方案是:通过获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像,由于,镜像文件和声明式文件在微服务发布的过程中起到关键的作用,当有大量微服务需要进行发布时,对于每个微服务而言,每次的发布都需要手动修改对应的镜像文件以及声明式文件,过程十分繁琐且效率较低,而本方案中的镜像文件以及声明式文件是根据对应的数据自动生成的,不需要人为干预,因此,通过该方式,不仅可以极大地降低出错的概率,还可以使微服务的发布过程更具自动化,提高微服务整体的发布效率。The main solution of the embodiment of the present application is: by obtaining branch code data; generating an image file according to the branch code data, and building a microservice image through the image file, the microservice image includes a microservice name and branch information; generating a declarative file according to the microservice name and the branch information; according to the declarative file, publishing the microservice image through a preset container orchestration cluster. Since the image file and the declarative file play a key role in the microservice publishing process, when a large number of microservices need to be published, for each microservice, each publication requires manual modification of the corresponding image file and declarative file, and the process is very cumbersome and inefficient. The image file and declarative file in this solution are automatically generated according to the corresponding data, and no human intervention is required. Therefore, through this method, not only the probability of error can be greatly reduced, but also the microservice publishing process can be made more automated, thereby improving the overall publishing efficiency of microservices.
本实施例考虑到,随着社会的发展与进步,微服务架构已经成为现代软件开发中的重要趋势之一,微服务架构将复杂的应用程序拆分成更小、更独立的服务组件,这些组件可以独立进行开发、测试和部署,从而提高了开发效率和产品质量,而目前常用的微服务发布方法依赖于手动操作和交互,即主要由开发人员手动执行微服务发布的各个步骤,过程繁琐、容易出错并且缺乏自动化和持续集成的特性,因此,该种微服务发布方法仍存在发布效率低下的问题。This embodiment takes into account that with the development and progress of society, microservice architecture has become one of the important trends in modern software development. Microservice architecture splits complex applications into smaller and more independent service components, which can be independently developed, tested and deployed, thereby improving development efficiency and product quality. The currently commonly used microservice publishing method relies on manual operations and interactions, that is, the various steps of microservice publishing are mainly manually performed by developers. The process is cumbersome, error-prone and lacks automation and continuous integration features. Therefore, this microservice publishing method still has the problem of low publishing efficiency.
基于此,本申请实施例提出一种解决方案,在微服务发布的过程中,通过对应的数据自动生成镜像文件进而根据镜像文件构建微服务镜像,这使得微服务镜像可以轻松地在不同的环境中进行部署和运行,而通过自动生成的声明式文件,预设的容器编排集群可以自动发布对应的微服务镜像,通过该方法,微服务可以通过自动化的方式被持续集成和持续发布,从而提高微服务整体的发布效率。Based on this, an embodiment of the present application proposes a solution. During the microservice publishing process, an image file is automatically generated through the corresponding data and then a microservice image is built based on the image file. This allows the microservice image to be easily deployed and run in different environments. Through the automatically generated declarative file, the preset container orchestration cluster can automatically publish the corresponding microservice image. Through this method, microservices can be continuously integrated and continuously released in an automated manner, thereby improving the overall release efficiency of microservices.
具体地,参照图1,图1为本申请微服务发布装置所属终端设备的功能模块示意图。该微服务发布装置可以为独立于终端设备的、能够进行数据处理的装置,也可以通过硬件或软件的形式承载于终端设备上。Specifically, referring to Figure 1, Figure 1 is a functional module diagram of a terminal device to which the microservice publishing device of the present application belongs. The microservice publishing device can be a device independent of the terminal device and capable of data processing, or it can be carried on the terminal device in the form of hardware or software.
在本实施例中,该微服务发布装置所属终端设备至少包括输出模块110、处理器120、存储器130以及通信模块140。In this embodiment, the terminal device to which the microservice publishing apparatus belongs includes at least an output module 110 , a processor 120 , a memory 130 and a communication module 140 .
存储器130中存储有操作系统以及微服务发布程序,获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像,所述微服务镜像存储于该存储器130中。输出模块110可为显示屏、扬声器等。通信模块140可以包括WIFI模块、移动通信模块以及蓝牙模块等,通过通信模块140与外部设备或服务器进行通信。The memory 130 stores an operating system and a microservice publishing program, obtains branch code data; generates an image file according to the branch code data, and builds a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generates a declarative file according to the microservice name and the branch information; and publishes the microservice image through a preset container orchestration cluster according to the declarative file, wherein the microservice image is stored in the memory 130. The output module 110 may be a display screen, a speaker, etc. The communication module 140 may include a WIFI module, a mobile communication module, a Bluetooth module, etc., and communicates with an external device or server through the communication module 140.
其中,存储器130中的微服务发布程序被处理器执行时实现以下步骤:Among them, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are implemented:
获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像。Obtain branch code data; generate an image file according to the branch code data, and build a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generate a declarative file according to the microservice name and the branch information; and publish the microservice image through a preset container orchestration cluster according to the declarative file.
进一步地,存储器130中的微服务发布程序被处理器执行时还实现以下步骤:Furthermore, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are also implemented:
获取目标代码;Get the object code;
将所述目标代码存储至代码仓库Gitlab;Storing the target code in the code repository Gitlab;
根据流程配置gitflow,由所述代码仓库Gitlab对所述目标代码进行分支管理,得到分支代码数据。According to the process configuration gitflow, the code warehouse Gitlab performs branch management on the target code to obtain branch code data.
进一步地,存储器130中的微服务发布程序被处理器执行时还实现以下步骤:Furthermore, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are also implemented:
获取镜像模板文件;Get the image template file;
根据所述镜像模板文件和代码版本号自动生成镜像文件,所述代码版本号包括在所述分支代码数据中;Automatically generate an image file according to the image template file and a code version number, wherein the code version number is included in the branch code data;
根据所述镜像文件对所述分支代码数据进行镜像构建,得到微服务镜像,所述微服务镜像包括微服务名称以及分支信息。The branch code data is mirrored according to the mirror file to obtain a microservice image, where the microservice image includes a microservice name and branch information.
进一步地,存储器130中的微服务发布程序被处理器执行时还实现以下步骤:Furthermore, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are also implemented:
获取声明式模板文件和发布指令;Get declarative template files and publishing instructions;
将所述微服务镜像发送至镜像仓库,由所述镜像仓库对所述微服务镜像进行存储管理;Send the microservice image to an image warehouse, which stores and manages the microservice image;
根据所述发布指令,从所述镜像仓库获取所述微服务名称和所述分支信息,根据所述声明式模板文件、所述微服务名称和所述分支信息自动生成声明式文件。According to the publishing instruction, the microservice name and the branch information are obtained from the image repository, and a declarative file is automatically generated according to the declarative template file, the microservice name and the branch information.
进一步地,存储器130中的微服务发布程序被处理器执行时还实现以下步骤:Furthermore, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are also implemented:
根据所述分支信息中的环境类型,将所述声明式文件发送至预设的容器编排集群;Sending the declarative file to a preset container orchestration cluster according to the environment type in the branch information;
根据所述声明式文件,通过所述容器编排集群获取微服务镜像;According to the declarative file, obtain the microservice image through the container orchestration cluster;
通过所述容器编排集群,对所述微服务镜像进行发布。The microservice image is published through the container orchestration cluster.
进一步地,存储器130中的微服务发布程序被处理器执行时还实现以下步骤:Furthermore, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are also implemented:
通过所述容器编排集群获取镜像仓库访问权限;Obtaining access rights to the image repository through the container orchestration cluster;
根据所述访问权限和镜像地址,通过所述容器编排集群在所述镜像仓库中拉取镜像,得到微服务镜像,所述镜像地址包括在所述声明式文件。According to the access permission and the image address, the image is pulled from the image repository through the container orchestration cluster to obtain a microservice image, and the image address is included in the declarative file.
进一步地,存储器130中的微服务发布程序被处理器执行时还实现以下步骤:Furthermore, when the microservice publishing program in the memory 130 is executed by the processor, the following steps are also implemented:
通过预设的容器管理平台rancher对所述微服务镜像进行监管,得到微服务数据,所述微服务数据包括微服务实例状态和日志信息;The microservice image is supervised by the preset container management platform Rancher to obtain microservice data, which includes microservice instance status and log information;
根据所述微服务实例状态和所述日志信息,通过所述容器管理平台rancher对微服务进行调整。According to the microservice instance status and the log information, the microservice is adjusted through the container management platform Rancher.
本实施例通过上述方案,通过获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像,由于,镜像文件和声明式文件在微服务发布的过程中起到关键的作用,当有大量微服务需要进行发布时,对于每个微服务而言,每次的发布都需要手动修改对应的镜像文件以及声明式文件,过程十分繁琐且效率较低,而本方案中的镜像文件以及声明式文件是根据对应的数据自动生成的,不需要人为干预,因此,通过该方式,不仅可以极大地降低出错的概率,还可以使微服务的发布过程更具自动化,提高微服务整体的发布效率。This embodiment uses the above scheme to obtain branch code data; generate an image file based on the branch code data, and build a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generate a declarative file based on the microservice name and the branch information; and publish the microservice image through a preset container orchestration cluster based on the declarative file. Since image files and declarative files play a key role in the microservice publishing process, when a large number of microservices need to be published, for each microservice, each publication requires manual modification of the corresponding image file and declarative file, and the process is very cumbersome and inefficient. The image file and declarative file in this scheme are automatically generated based on the corresponding data, and no human intervention is required. Therefore, this method can not only greatly reduce the probability of errors, but also make the microservice publishing process more automated, thereby improving the overall microservice publishing efficiency.
参照图2,图2为本申请微服务发布方法第一示例性实施例的流程示意图。Referring to FIG. 2 , FIG. 2 is a flow chart of a first exemplary embodiment of a microservice publishing method of the present application.
本发明一实施例提供一种微服务发布方法,该方法包括:An embodiment of the present invention provides a microservice publishing method, the method comprising:
步骤S10,获取分支代码数据;Step S10, obtaining branch code data;
在软件开发中,通常会使用版本控制系统(比如Git)来管理代码,当需要同时进行多个功能开发、版本发布或者紧急修复时,开发人员会基于主要开发线创建不同的分支,以便并行进行工作。In software development, a version control system (such as Git) is usually used to manage code. When multiple functions need to be developed, versions released, or emergency fixes need to be carried out simultaneously, developers will create different branches based on the main development line to work in parallel.
具体地,Gitflow是一种Git分支模型,基于分支管理的思想,为团队协作开发提供了一套完整的流程规范,Gitflow流程可以包含两个长期分支:master(主分支)和develop(开发分支)以及三种短期分支:feature(特性分支)、release(发布分支)和hotfix(修复分支)。Specifically, Gitflow is a Git branch model that provides a complete set of process specifications for team collaborative development based on the idea of branch management. The Gitflow process can include two long-term branches: master (main branch) and develop (development branch) and three short-term branches: feature (feature branch), release (release branch) and hotfix (repair branch).
分支代码数据可以理解为在这些分支上所包含的代码文件、配置文件、测试用例、文档等开发过程中产生的各种数据。这些数据可能涵盖了新功能的实现、bug修复、性能优化等内容。Branch code data can be understood as various data generated during the development process, including code files, configuration files, test cases, documents, etc. on these branches. These data may cover the implementation of new features, bug fixes, performance optimization, etc.
获取分支代码数据的方法可以包括:Methods for obtaining branch code data may include:
克隆整个仓库:使用版本控制系统(如Git)提供的克隆命令,将整个仓库包括所有分支的代码数据都复制到本地,例如,在Git中使用git clone命令来克隆一个远程仓库到本地。Clone the entire repository: Use the clone command provided by the version control system (such as Git) to copy the entire repository including the code data of all branches to the local computer. For example, use the git clone command in Git to clone a remote repository to the local computer.
切换到指定分支:如果只需要获取某个特定分支的代码数据,可以通过切换分支的方式来获取,在Git中使用git checkout命令可以切换到目标分支,然后可以查看该分支的代码数据。Switch to the specified branch: If you only need to obtain the code data of a specific branch, you can obtain it by switching branches. In Git, use the git checkout command to switch to the target branch, and then you can view the code data of the branch.
下载分支代码压缩包:有些代码托管平台(如GitHub、GitLab)提供了下载分支代码的功能,因此,可以在平台上找到对应的分支后,下载分支代码的压缩包,这种方法可以避免克隆整个仓库,只获取特定分支的代码数据。Download branch code compressed package: Some code hosting platforms (such as GitHub, GitLab) provide the function of downloading branch code. Therefore, after finding the corresponding branch on the platform, you can download the compressed package of the branch code. This method can avoid cloning the entire repository and only obtain the code data of a specific branch.
使用特定版本控制工具的API:一些版本控制工具提供了API接口,可以通过编程的方式获取分支代码数据,通过调用这些API可以获取指定分支的代码内容、文件列表等信息。Use the API of a specific version control tool: Some version control tools provide API interfaces that can obtain branch code data programmatically. By calling these APIs, you can obtain information such as the code content and file list of a specified branch.
可以根据具体情况选择适合的方式获取分支代码数据。You can choose a suitable method to obtain branch code data according to the specific situation.
步骤S20,根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;Step S20, generating an image file according to the branch code data, and building a microservice image through the image file, wherein the microservice image includes a microservice name and branch information;
获取分支代码数据后可以根据分支代码数据自动生成镜像文件。After obtaining the branch code data, the image file can be automatically generated according to the branch code data.
其中,镜像文件Dockerfile是指用于定义镜像的文本文件,镜像文件包含一系列的指令和配置项,用于构建一个可运行的Docker镜像,使用镜像文件可以实现对镜像版本的控制和重复部署,方便开发人员在不同环境中快速构建一致的容器镜像,此外,镜像文件还提供了一种可读性强的方式来描述镜像的构建过程,使得镜像的构建和维护更加简单和可靠。Among them, the image file Dockerfile refers to a text file used to define the image. The image file contains a series of instructions and configuration items for building an executable Docker image. The image file can be used to control the image version and repeatedly deploy it, making it convenient for developers to quickly build consistent container images in different environments. In addition, the image file also provides a highly readable way to describe the image building process, making the image building and maintenance simpler and more reliable.
具体地,可以通过发布平台提供的模板自动生成镜像文件(Dockerfile),发布平台通常会提供一系列预定义的模板,这些模板包含了常见的软件配置和环境设置以及最佳实践的建议,开发人员可以根据应用程序的需求选择合适的模板并提供一些配置参数,进一步地,发布平台可以根据这些相关的数据,自动生成镜像文件。Specifically, the image file (Dockerfile) can be automatically generated through the template provided by the publishing platform. The publishing platform usually provides a series of predefined templates that contain common software configurations and environment settings as well as best practice recommendations. Developers can select the appropriate template based on the application requirements and provide some configuration parameters. Furthermore, the publishing platform can automatically generate the image file based on these related data.
自动生成镜像文件后,可以根据镜像文件构建微服务镜像。After the image file is automatically generated, you can build a microservice image based on the image file.
其中,微服务镜像是指用于部署和运行单个微服务的容器镜像,在微服务架构中,应用程序被拆分成多个小型的、相互独立的服务单元,每个服务单元都可以被打包为一个独立的容器镜像,这些镜像可以被部署到容器化平台(比如Docker、Kubernetes等)中并通过容器编排工具进行管理和扩展。Among them, a microservice image refers to a container image used to deploy and run a single microservice. In a microservice architecture, an application is split into multiple small, independent service units. Each service unit can be packaged as an independent container image. These images can be deployed to containerized platforms (such as Docker, Kubernetes, etc.) and managed and expanded through container orchestration tools.
具体地,通过镜像文件构建微服务镜像的步骤可以包括:Specifically, the steps of building a microservice image through an image file may include:
编写Dockerfile:在微服务项目的根目录下创建一个镜像文件,其中包含构建微服务镜像所需的依赖项和环境设置,其中,可以使用基础镜像、安装软件包、复制项目文件等命令来编写镜像文件。Write Dockerfile: Create an image file in the root directory of the microservice project, which contains the dependencies and environment settings required to build the microservice image. You can use commands such as base image, install software packages, copy project files, etc. to write the image file.
构建微服务镜像:使用Docker命令或其他构建工具构建微服务镜像,例如,可以使用docker build命令来执行构建操作并指定标记(tag)来标识镜像。Build microservice images: Use Docker commands or other build tools to build microservice images. For example, you can use the docker build command to perform build operations and specify tags to identify the image.
运行微服务容器:使用docker run命令来启动微服务容器,例如,dockerrun-p8080:8080my_microservice表示将容器的8080端口映射到主机的对应端口并运行被标记为my_microservice的镜像。Run the microservice container: Use the docker run command to start the microservice container. For example, docker run -p8080:8080my_microservice means mapping the container's port 8080 to the corresponding port of the host and running the image marked as my_microservice.
以上是一般的步骤和指导,由于每个微服务项目的具体情况可能有所不同,因此可以根据实际情况进行调整和修改。The above are general steps and guidelines. Since the specific circumstances of each microservice project may be different, they can be adjusted and modified according to the actual situation.
步骤S30,根据所述微服务名称和所述分支信息自动生成声明式文件;Step S30, automatically generating a declarative file according to the microservice name and the branch information;
微服务名称是指对一个微服务的命名,微服务架构是一种将应用程序拆分为一系列小型、独立的服务的方法,由于每个服务都有自己的特定功能并可以独立部署、扩展和管理,因此,在微服务架构中,每个服务都存在有一个清晰且具有描述性的名称以便于理解和识别。The microservice name refers to the naming of a microservice. The microservice architecture is a method of splitting an application into a series of small, independent services. Since each service has its own specific functions and can be deployed, expanded, and managed independently, in the microservice architecture, each service has a clear and descriptive name for easy understanding and identification.
举个例子,例如一个电子商务应用可能包含多个微服务,如用户服务、产品服务、订单服务等。在这种情况下,可以使用类似于"user-service"、"product-service"、"order-service"等命名方式来命名微服务,这样的命名方式可以帮助团队成员快速理解每个微服务的功能和职责。For example, an e-commerce application may contain multiple microservices, such as user service, product service, order service, etc. In this case, you can use naming methods such as "user-service", "product-service", "order-service", etc. to name the microservices. This naming method can help team members quickly understand the functions and responsibilities of each microservice.
分支信息是指用于管理代码开发和版本控制的分支名称和其对应的含义,分支信息可以包含对应的环境信息,例如,开发分支中的分支代码所处的环境为开发环境,测试分支的分支代码所处的环境为测试环境,通过分支信息,开发人员可以轻松地理解和管理代码库中不同分支的用途和环境,为后续编排镜像提供数据支持。Branch information refers to the branch name and its corresponding meaning used to manage code development and version control. Branch information can contain corresponding environment information. For example, the environment where the branch code in the development branch is located is the development environment, and the environment where the branch code in the test branch is located is the test environment. Through branch information, developers can easily understand and manage the purpose and environment of different branches in the code base, providing data support for subsequent orchestration of images.
声明式文件是指一种描述系统状态或配置的文件,它通过声明所需的目标状态,而不需要指定达到该状态的具体步骤,具体地,声明式文件中可以包括生成的微服务镜像、微服务运行实例个数、微服务所需资源等信息生成的微服务镜像、微服务运行实例个数、微服务所需资源等信息。A declarative file is a file that describes the system status or configuration. It declares the desired target state without specifying the specific steps to achieve that state. Specifically, the declarative file may include information such as the generated microservice image, the number of running microservice instances, and the resources required for the microservice.
具体地,声明式文件格式可以包括:Specifically, the declarative file format may include:
YAML:YAML是一种人类可读的数据序列化格式,可以用于描述配置和数据结构,在软件开发中,YAML用于编写Kubernetes的配置文件、Docker Compose文件等。YAML: YAML is a human-readable data serialization format that can be used to describe configurations and data structures. In software development, YAML is used to write Kubernetes configuration files, Docker Compose files, etc.
JSON:JSON是一种轻量级的数据交换格式,易于阅读和编写,可以用于描述RESTAPI的请求和响应、配置文件等。JSON: JSON is a lightweight data exchange format that is easy to read and write. It can be used to describe REST API requests and responses, configuration files, etc.
具体地,根据微服务名称和分支信息生成声明式文件的步骤可以包括:Specifically, the steps of generating a declarative file according to the microservice name and branch information may include:
确定声明式文件的类型:确定要生成的声明式文件的类型,例如Kubernetes的YAML文件、Dockerfile、Swagger规范等,不同的声明式文件类型有不同的语法和结构。Determine the type of declarative file: Determine the type of declarative file to be generated, such as Kubernetes YAML file, Dockerfile, Swagger specification, etc. Different declarative file types have different syntax and structure.
定义模板:可以创建一个基于模板的文件以自动生成声明式文件,其中可以包含一些占位符或变量,占位符或变量用于将微服务名称和分支信息插入到相应的位置,进一步地,可以使用标记语言(如Jinja2、Mustache)或脚本语言(如Python、Go)来定义和处理模板。Define a template: You can create a template-based file to automatically generate a declarative file, which can contain some placeholders or variables. The placeholders or variables are used to insert the microservice name and branch information into the corresponding locations. Furthermore, you can use a markup language (such as Jinja2, Mustache) or a scripting language (such as Python, Go) to define and process the template.
解析微服务名称和分支信息:根据实际需求可以手动输入微服务名称和分支信息或者从其他来源(如版本控制系统、配置文件)中获取这些信息。Parse microservice name and branch information: According to actual needs, you can manually enter the microservice name and branch information or obtain this information from other sources (such as version control systems, configuration files).
填充模板:若存在声明式模板文件,可以将解析得到的微服务名称和分支信息填充到声明式模板文件中的相应位置,具体地,可以通过简单的字符串替换或更复杂的模板引擎功能来实现。Filling the template: If a declarative template file exists, the parsed microservice name and branch information can be filled into the corresponding positions in the declarative template file. Specifically, this can be achieved through simple string replacement or more complex template engine functions.
生成文件:根据填充后的模板,生成最终的声明式文件,可以将生成的文件保存到指定的目录或输出到特定的位置,以便进一步使用和部署。Generate files: Generate the final declarative files based on the filled template. The generated files can be saved to a specified directory or output to a specific location for further use and deployment.
需要注意的是,自动生成声明式文件需要考虑文件的正确性和安全性。确保生成的文件符合相应的语法规范,并在填充模板时对输入进行适当的验证和转义,以防止潜在的安全漏洞。It should be noted that the automatic generation of declarative files needs to consider the correctness and security of the files. Make sure that the generated files comply with the corresponding syntax specifications, and perform proper validation and escape on the input when filling in the template to prevent potential security vulnerabilities.
此外,还可以将自动生成声明式文件的过程集成到持续集成/持续部署(CI/CD)流水线中,以实现自动化的构建和部署过程。这样可以确保每次代码更改都能自动生成相应的声明式文件,并提高开发效率和部署一致性。In addition, the process of automatically generating declarative files can be integrated into the continuous integration/continuous deployment (CI/CD) pipeline to achieve automated building and deployment processes. This ensures that the corresponding declarative files are automatically generated for each code change, and improves development efficiency and deployment consistency.
步骤S40,根据所述声明式文件,通过预设的容器编排集群发布微服务镜像;Step S40, publishing the microservice image through a preset container orchestration cluster according to the declarative file;
生成声明式文件后,预设的容器编排集群可以根据该声明式文件发布微服务镜像。After the declarative file is generated, the preset container orchestration cluster can publish the microservice image according to the declarative file.
其中,容器编排集群是指一个用于运行和管理容器化应用程序的开源容器编排平台,具体地,容器编排集群可以是kubernetes集群,kubernetes集群提供了一种可靠且可扩展的方式来部署、扩展和管理容器化应用程序,使开发人员能够更轻松地管理复杂的分布式系统。Among them, the container orchestration cluster refers to an open source container orchestration platform for running and managing containerized applications. Specifically, the container orchestration cluster can be a Kubernetes cluster. The Kubernetes cluster provides a reliable and scalable way to deploy, scale and manage containerized applications, enabling developers to manage complex distributed systems more easily.
具体地,Kubernetes集群通过使用容器抽象层(Container Abstraction Layer)来管理容器化应用程序,其中,集群使用一组称为Pod的抽象概念来组织和管理容器,Pod是一个或多个相关容器的组合,它们共享网络和存储资源并在同一节点上运行,Kubernetes集群负责调度和管理Pod的生命周期,确保Pod的健康状态。Specifically, the Kubernetes cluster manages containerized applications by using the Container Abstraction Layer, where the cluster uses a set of abstract concepts called Pods to organize and manage containers. A Pod is a combination of one or more related containers that share network and storage resources and run on the same node. The Kubernetes cluster is responsible for scheduling and managing the life cycle of the Pod to ensure the health of the Pod.
通过声明式文件中的信息,如镜像地址,Kubernetes集群可以获取微服务镜像,当Kubernetes集群获取微服务镜像后,Kubernetes集群可以将其发布并运行在Pod中从而完成整个微服务发布的流程。Through the information in the declarative file, such as the image address, the Kubernetes cluster can obtain the microservice image. After the Kubernetes cluster obtains the microservice image, the Kubernetes cluster can publish it and run it in the Pod to complete the entire microservice publishing process.
本申请实施例提出的微服务发布方法,通过获取获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像,由于,镜像文件和声明式文件在微服务发布的过程中起到关键的作用,当有大量微服务需要进行发布时,对于每个微服务而言,每次的发布都需要手动修改对应的镜像文件以及声明式文件,过程十分繁琐且效率较低,而本方案中的镜像文件以及声明式文件是根据对应的数据自动生成的,不需要人为干预,因此,通过该方式,不仅可以极大地降低出错的概率,还可以使微服务的发布过程更具自动化,提高微服务整体的发布效率。The microservice publishing method proposed in the embodiment of the present application obtains branch code data; generates an image file according to the branch code data, and builds a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generates a declarative file according to the microservice name and the branch information; and publishes the microservice image through a preset container orchestration cluster according to the declarative file. Since image files and declarative files play a key role in the microservice publishing process, when a large number of microservices need to be published, for each microservice, each publication requires manual modification of the corresponding image files and declarative files, and the process is very cumbersome and inefficient. The image files and declarative files in this solution are automatically generated according to the corresponding data, and no human intervention is required. Therefore, in this way, not only the probability of errors can be greatly reduced, but also the microservice publishing process can be made more automated, thereby improving the overall publishing efficiency of microservices.
参照图3,图3为本申请微服务发布方法第二示例性实施例的流程示意图。Referring to FIG. 3 , FIG. 3 is a flow chart of a second exemplary embodiment of a microservice publishing method of the present application.
基于第一实施例,提出本申请第二实施例,本申请第二实施例与第一实施例的区别在于:Based on the first embodiment, a second embodiment of the present application is proposed. The difference between the second embodiment of the present application and the first embodiment is that:
在本实施例中,对步骤S10,获取分支代码数据进行细化,其中细化的步骤可以包括:In this embodiment, step S10, obtaining branch code data, is refined, wherein the refining steps may include:
步骤S11,获取目标代码;Step S11, obtaining the target code;
目标代码是指用于最终发布的软件或服务的完整代码,它包括了所有必要的代码和资源,以便能够在特定环境中部署和运行,对于微服务架构而言,目标代码包含了构成各个微服务的代码数据。The target code refers to the complete code for the final released software or service. It includes all the necessary code and resources to enable it to be deployed and run in a specific environment. For the microservice architecture, the target code contains the code data that constitutes each microservice.
获取目标代码的方法可以包括:Methods for obtaining object code may include:
从开源项目中获取:如果目标代码来自开源项目,可以通过访问代码库(如GitHub)下载源代码并按照项目文档的说明编译生成目标代码。Obtained from open source projects: If the object code comes from an open source project, you can download the source code by accessing the code repository (such as GitHub) and compile it according to the instructions in the project documentation to generate the object code.
通过第三方代码库获取:部分第三方代码库可能提供了预编译好的目标代码,因此,可以从这些代码库中获取这些代码并使用,例如,当使用Python时,可以使用PyPI这个Python软件包索引来获取预编译好的Python模块。Obtained through third-party code repositories: Some third-party code repositories may provide precompiled target code, so you can obtain these codes from these code repositories and use them. For example, when using Python, you can use PyPI, the Python package index, to obtain precompiled Python modules.
步骤S12,将所述目标代码存储至代码仓库Gitlab;Step S12, storing the target code in the code repository Gitlab;
其中,代码仓库Gitlab是一个基于Git的代码托管和协作平台,它提供了一个私有Git仓库和一个Web界面,用户可以轻松地管理、开发和部署代码。GitLab包括了一系列工具和功能,如版本控制、持续集成/部署(CI/CD)、项目管理、代码审查、问题跟踪等并支持集成,如Slack、JIRA等。Among them, the code repository Gitlab is a Git-based code hosting and collaboration platform that provides a private Git repository and a web interface, allowing users to easily manage, develop and deploy code. GitLab includes a range of tools and features, such as version control, continuous integration/deployment (CI/CD), project management, code review, issue tracking, etc., and supports integrations such as Slack, JIRA, etc.
具体地,将目标代码存储至代码仓库Gitlab的步骤可以包括:Specifically, the steps of storing the target code in the code repository Gitlab may include:
创建项目:登录到GitLab并在GitLab上创建一个新项目,点击新建项目按钮,填写项目名称、描述等信息并选择适当的可见性选项(私有或公开)。Create a project: Log in to GitLab and create a new project on GitLab. Click the New Project button, fill in the project name, description and select the appropriate visibility option (private or public).
克隆仓库:在本地电脑上选择一个合适的文件夹,打开命令行终端。使用Git命令克隆刚刚创建的项目仓库到本地。Clone the repository: Select a suitable folder on your local computer and open the command line terminal. Use the Git command to clone the newly created project repository to your local computer.
添加代码:将你的目标代码复制或移动到刚刚克隆的本地仓库文件夹中。Add code: Copy or move your target code to the local repository folder you just cloned.
提交更改:在命令行终端中,进入本地仓库文件夹的路径,将代码提交到GitLab仓库:Submit changes: In the command line terminal, enter the path of the local warehouse folder and submit the code to the GitLab warehouse:
查看代码:刷新GitLab页面后,可以在项目的代码页面上看到推送的代码以及可以在GitLab的界面上查看文件的历史记录、进行比较和合并等操作。View code: After refreshing the GitLab page, you can see the pushed code on the project's code page and view the file history, compare and merge, and other operations on the GitLab interface.
通过以上步骤,可以将目标代码存储到GitLab代码仓库中,方便后续进行版本控制、协作开发以及其他与GitLab相关的操作。Through the above steps, the target code can be stored in the GitLab code repository, which is convenient for subsequent version control, collaborative development, and other GitLab-related operations.
步骤S13,根据流程配置gitflow,由所述代码仓库Gitlab对所述目标代码进行分支管理,得到分支代码数据;Step S13, configuring gitflow according to the process, and having the code repository Gitlab perform branch management on the target code to obtain branch code data;
流程配置gitflow是指一种流行的Git分支管理工作流程,它定义了一套在软件开发中使用的分支命名约定和分支管理策略。Process configuration gitflow refers to a popular Git branch management workflow, which defines a set of branch naming conventions and branch management strategies used in software development.
具体地,通过流程配置gitflow对目标代码进行分支管理产生的分支可以包括:Specifically, the branches generated by configuring gitflow to manage the target code can include:
主分支(Master):主分支用于存储稳定的、可发布的代码,当开发完成并经过测试后,代码会合并到主分支中。Master branch: The master branch is used to store stable, releasable code. When development is completed and tested, the code will be merged into the master branch.
开发分支(Develop):开发分支是主要的集成分支,所有的功能开发都应该从此分支创建。开发人员在自己的特性分支上进行开发,并将代码合并到开发分支上。Development branch (Develop): The development branch is the main integration branch, and all feature development should be created from this branch. Developers develop on their own feature branches and merge the code into the development branch.
特性分支(Feature):每个新功能或用户故事都应该在独立的特性分支上进行开发。特性分支从开发分支创建,并在完成开发后合并回开发分支,在特性分支中可以包括测试分支。Feature branch: Each new feature or user story should be developed on an independent feature branch. Feature branches are created from development branches and merged back to development branches after development is completed. Test branches can be included in feature branches.
发布分支(Release):发布分支用于准备发布新版本。当开发分支上的功能已经完成,并且经过测试后,可以从开发分支创建一个发布分支,用于进行最终的调试和准备工作。Release branch: The release branch is used to prepare for the release of a new version. When the functions on the development branch have been completed and tested, a release branch can be created from the development branch for final debugging and preparation.
修复分支(Hotfix):如果在生产环境中发现了紧急的bug或问题,可以从主分支创建一个修复分支来解决问题。修复分支完成后,需将其合并回主分支和开发分支。Hotfix: If you find an urgent bug or problem in the production environment, you can create a hotfix branch from the main branch to solve the problem. After the hotfix branch is completed, it needs to be merged back to the main branch and the development branch.
流程配置gitflow的核心思想是将开发过程分割成不同的分支以提高代码的可维护性和版本控制的灵活性。The core idea of process configuration gitflow is to split the development process into different branches to improve the maintainability of the code and the flexibility of version control.
根据流程配置gitflow对目标代码进行管理可以得到分支代码数据。By configuring gitflow according to the process to manage the target code, you can get the branch code data.
具体地,分支代码数据指的是在流程配置gitflow的管理下,不同分支中代码所包含的相关数据例,每个分支都可以包含不同的代码修改、新增或删除,以及相应的配置文件、资源文件等项目所需的数据,分支代码数据可以包括代码版本号,代码所处环境等信息。Specifically, branch code data refers to the relevant data contained in the code in different branches under the management of the process configuration gitflow. Each branch can contain different code modifications, additions or deletions, as well as corresponding configuration files, resource files and other data required by the project. Branch code data can include information such as the code version number and the environment in which the code is located.
分支代码数据的主要作用是在不同的开发环境中进行代码管理和版本控制,通过创建和使用不同的分支,团队成员可以并行地进行独立的开发工作,而不会互相干扰,而每个分支可以用于实现不同的功能、修复bug、进行测试或通过生成镜像或容器部署和运行至不同的环境中。The main function of branch code data is to perform code management and version control in different development environments. By creating and using different branches, team members can perform independent development work in parallel without interfering with each other. Each branch can be used to implement different functions, fix bugs, perform tests, or generate images or containers for deployment and operation in different environments.
本申请实施例提出的微服务发布方法,通过获取目标代码;将所述目标代码存储至代码仓库Gitlab;根据流程配置gitflow,由所述代码仓库Gitlab对所述目标代码进行分支管理,得到分支代码数据,通过将目标代码存储至代码仓库Gitlab中可以帮助团队更好地管理和开发代码,而进一步地,在代码仓库Gitlab中,根据流程配置gitflow对目标代码进行管理,流程配置gitflow可以将开发过程分为若干类型的分支以进行后续的功能开发、版本发布和错误修复,通过该方式可以有效避免代码冲突、提高代码管理、开发以及发布效率。The microservice publishing method proposed in the embodiment of the present application obtains the target code; stores the target code in the code warehouse Gitlab; and according to the process configuration gitflow, the code warehouse Gitlab performs branch management on the target code to obtain branch code data. Storing the target code in the code warehouse Gitlab can help the team better manage and develop the code. Furthermore, in the code warehouse Gitlab, the target code is managed according to the process configuration gitflow. The process configuration gitflow can divide the development process into several types of branches for subsequent function development, version release and error repair. In this way, code conflicts can be effectively avoided and the efficiency of code management, development and release can be improved.
参照图4,图4为本申请微服务发布方法第三示例性实施例的流程示意图。Referring to FIG. 4 , FIG. 4 is a flow chart of a third exemplary embodiment of a microservice publishing method of the present application.
基于第二实施例,提出本申请第三实施例,本申请第三实施例与第二实施例的区别在于:Based on the second embodiment, a third embodiment of the present application is proposed. The difference between the third embodiment of the present application and the second embodiment is that:
在本实施例中,对步骤S20,根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息进行细化,其中细化的步骤可以包括:In this embodiment, for step S20, an image file is generated according to the branch code data, and a microservice image is constructed by the image file. The microservice image includes a microservice name and branch information for refinement, wherein the refinement step may include:
步骤S21,获取镜像模板文件;Step S21, obtaining an image template file;
镜像模板文件是指用于创建容器镜像的配置文件或蓝图。容器镜像是一种轻量级、可移植的软件打包方式,其中包含了运行应用程序所需的所有依赖项、运行环境和配置信息。An image template file is a configuration file or blueprint used to create a container image. A container image is a lightweight, portable way of packaging software that contains all the dependencies, operating environment, and configuration information required to run an application.
镜像模板文件包含了构建容器镜像所需的指令和配置信息,它描述了如何在基础镜像的基础上添加、配置和运行特定的应用程序或服务。常见的镜像模板文件格式包括Dockerfile(用于Docker容器)和Kubernetes的YAML文件(用于容器编排)。An image template file contains the instructions and configuration information required to build a container image. It describes how to add, configure, and run a specific application or service based on a base image. Common image template file formats include Dockerfile (for Docker containers) and Kubernetes YAML files (for container orchestration).
镜像模板文件通常包括以下内容:An image template file usually includes the following:
基础镜像:指定用作基础的操作系统镜像或其他已存在的镜像,例如Ubuntu、Alpine等。Base image: Specifies the operating system image or other existing image used as the basis, such as Ubuntu, Alpine, etc.
安装步骤:定义了在容器中安装和配置应用程序所需的命令和依赖项。其中可以包括软件包管理器的命令、下载和解压文件、设置环境变量等。Installation steps: Define the commands and dependencies required to install and configure the application in the container. This may include package manager commands, downloading and unpacking files, setting environment variables, etc.
配置文件:指定应用程序的配置选项,例如数据库连接字符串、端口号、日志等,这些配置可以通过环境变量、配置文件或命令行参数传递给容器。Configuration file: Specifies the configuration options of the application, such as database connection string, port number, log, etc. These configurations can be passed to the container through environment variables, configuration files, or command line parameters.
运行命令:定义容器启动时执行的命令以及应用程序的入口点,这可以是启动Web服务器、运行脚本、启动后台服务等。Run command: Defines the command executed when the container starts and the entry point of the application, which can be starting a web server, running a script, starting a background service, etc.
具体地,获取镜像模板文件的方法可以包括:Specifically, the method for obtaining the image template file may include:
发布平台提供的默认模板:由于,发布平台提供一些默认的镜像模板文件,适用于不同类型的应用程序,因此,可以在发布平台的文档或界面中查找这些默认的镜像模板文件并根据需要选择合适的模板进行使用。Default templates provided by the publishing platform: Since the publishing platform provides some default image template files that are suitable for different types of applications, you can search for these default image template files in the documents or interfaces of the publishing platform and select the appropriate template to use as needed.
共享模板:通过搜索引擎、代码托管平台(如GitHub)或社区论坛查找共享的镜像模板文件,例如,Docker Hub上提供大量的镜像模板文件,因此,可以在它们的仓库中找到对应的可以用于生成Dockerfile的镜像模板文件。Shared templates: Find shared image template files through search engines, code hosting platforms (such as GitHub), or community forums. For example, Docker Hub provides a large number of image template files, so you can find the corresponding image template files that can be used to generate Dockerfile in their repositories.
步骤S22,根据所述镜像模板文件和代码版本号自动生成镜像文件,所述代码版本号包括在所述分支代码数据中;Step S22, automatically generating an image file according to the image template file and the code version number, wherein the code version number is included in the branch code data;
当获取合适的镜像模板文件后,可以根据镜像模板文件和代码版本号自动生成镜像文件。After obtaining a suitable image template file, the image file can be automatically generated according to the image template file and the code version number.
其中,代码版本号是指用来标识和识别软件代码的特定版本的一种标识符,可以用于跟踪和管理代码的变化、发布不同版本的软件以及对特定版本进行错误修复和功能改进,代码版本号可以包括在分支代码数据。Among them, the code version number refers to an identifier used to identify and recognize a specific version of the software code. It can be used to track and manage code changes, release different versions of software, and perform bug fixes and functional improvements on specific versions. The code version number can be included in the branch code data.
具体地,在流程配置gitflow管理目标代码的过程中,代码版本号可以通过标签(Tag)进行表示,标签是在特定的提交上创建的一个指向的引用,用于标识代码库的特定版本,使用标签来表示代码的版本号,可以方便地跟踪和回溯历史的特定版本,同时也能够为不同的版本提供可靠的标识。Specifically, in the process of configuring gitflow to manage the target code, the code version number can be represented by a tag. A tag is a reference created on a specific commit to identify a specific version of the code base. Using tags to represent the version number of the code can easily track and trace back to a specific version of history, while also providing reliable identification for different versions.
在Gitflow工作流程中,通常会根据不同的分支和阶段来创建标签,举个例子,常见的标签包括:In the Gitflow workflow, tags are usually created based on different branches and stages. For example, common tags include:
Release标签:在发布软件的时候,可以创建一个Release标签来标识该版本的代码。通常,当代码通过各种测试并准备好发布时,会在主分支(通常是master分支)上创建一个Release标签。Release tag: When releasing software, you can create a Release tag to identify the code of that version. Usually, when the code passes various tests and is ready for release, a Release tag is created on the main branch (usually the master branch).
Hotfix标签:当需要立即修复生产环境中的紧急问题时,可以创建一个Hotfix标签。Hotfix标签通常会在主分支的基础上创建,并且不会受到其他开发分支的影响。Hotfix tag: When an urgent problem in the production environment needs to be fixed immediately, a Hotfix tag can be created. Hotfix tags are usually created based on the main branch and will not be affected by other development branches.
具体地,根据镜像模板文件和代码版本号自动生成镜像文件的方法可以包括:Specifically, the method for automatically generating an image file according to an image template file and a code version number may include:
编写Dockerfile:编写Dockerfile文件,该文件描述了如何构建镜像,在Dockerfile中,你可以指定镜像的基础操作系统、依赖项安装、代码的复制等操作,具体地,可以使用类似COPY命令将代码添加到镜像中。这个过程中,可以将代码版本号作为构建参数传递给Dockerfile。Write Dockerfile: Write a Dockerfile file that describes how to build an image. In the Dockerfile, you can specify the image's base operating system, dependency installation, code copying, and other operations. Specifically, you can use commands like COPY to add code to the image. In this process, you can pass the code version number to the Dockerfile as a build parameter.
使用构建工具:使用Docker或其他构建工具,通过执行构建命令来构建镜像文件,在构建命令中,可以将代码版本号作为参数传入以便在构建过程中使用,例如,在Docker中,你可以使用docker build命令,并且通过-build-arg选项将代码版本号传递给Dockerfile。Use build tools: Use Docker or other build tools to build image files by executing build commands. In the build command, you can pass the code version number as a parameter for use in the build process. For example, in Docker, you can use the docker build command and pass the code version number to the Dockerfile through the -build-arg option.
自动化脚本:为了实现自动生成镜像文件的自动化过程,可以通过编写脚本的方式完成上述步骤,这个脚本可以接收代码版本号作为输入然后执行构建镜像的命令,通过该方法,当有新的代码版本发布时,只需运行脚本就可以自动构建相应版本的镜像文件。Automation script: In order to realize the automation process of automatically generating image files, the above steps can be completed by writing a script. This script can receive the code version number as input and then execute the command to build the image. Through this method, when a new code version is released, you only need to run the script to automatically build the image file of the corresponding version.
步骤S23,根据所述镜像文件对所述分支代码数据进行镜像构建,得到微服务镜像,所述微服务镜像包括微服务名称以及分支信息;Step S23, mirroring the branch code data according to the mirror file to obtain a microservice mirror, wherein the microservice mirror includes a microservice name and branch information;
当获得镜像文件后,可以根据镜像文件中所包含的指令对分支代码数据进行镜像构建,得到微服务镜像。After obtaining the image file, the branch code data can be mirrored according to the instructions contained in the image file to obtain a microservice image.
具体地,根据镜像文件将分支代码数据构建成镜像的步骤可以包括:Specifically, the step of building the branch code data into an image according to the image file may include:
1、在Dockerfile的目录中准备好所有必需的文件和代码。1. Prepare all the necessary files and codes in the directory of Dockerfile.
2、打开终端或命令提示符并导航到包含Dockerfile的目录。2. Open a terminal or command prompt and navigate to the directory containing the Dockerfile.
3、执行构建命令docker build-t image_name:tag path_to_dockerfile,其中image_name:tag镜像指定的名称和标签,path_to_dockerfile是Dockerfile所在的路径,该命令可以自动查找并读取Dockerfile并按照其中的指示构建镜像。3. Execute the build command docker build -t image_name:tag path_to_dockerfile, where image_name:tag is the name and tag specified by the image, and path_to_dockerfile is the path where the Dockerfile is located. This command can automatically find and read the Dockerfile and build the image according to the instructions therein.
4、Docker将根据Dockerfile中的指示逐步完成构建过程,在构建过程中,Docker将运行Dockerfile中的每一个指令,例如加载分支代码数据、安装依赖项、运行构建命令等。4. Docker will step by step complete the building process according to the instructions in the Dockerfile. During the building process, Docker will run each instruction in the Dockerfile, such as loading branch code data, installing dependencies, running build commands, etc.
5、构建完成后可以使用命令docker images列出所有已经构建的镜像以查验构建的镜像是否存在。5. After the build is complete, you can use the command docker images to list all built images to check whether the built image exists.
需要注意的是,上述步骤为构建微服务镜像的一种方式,具体使用哪种方式可以根据需要进行修改。It should be noted that the above steps are one way to build a microservice image, and the specific method can be modified as needed.
可以理解地,将微服务应用程序的源代码和相关依赖项打包到Dockerfile中并使用Docker命令构建容器镜像得到的容器镜像可以理解为微服务镜像。Understandably, the container image obtained by packaging the source code and related dependencies of the microservice application into a Dockerfile and building the container image using the Docker command can be understood as a microservice image.
本申请实施例提出的微服务发布方法,通过获取镜像模板文件;根据所述镜像模板文件和代码版本号自动生成镜像文件,所述代码版本号包括在所述分支代码数据中;根据所述镜像文件对所述分支代码数据进行镜像构建,得到微服务镜像,所述微服务镜像包括微服务名称以及分支信息,根据镜像模板文件和代码版本号,平台可以自动生成后续用于对分支代码数据进行镜像构建的镜像文件,由于整个的镜像文件是自动生成的,因此,在面对大量微服务发布以及集成需求时可以提高整个集成以及发布的效率。The microservice publishing method proposed in the embodiment of the present application obtains an image template file; automatically generates an image file according to the image template file and a code version number, wherein the code version number is included in the branch code data; mirrors the branch code data according to the image file to obtain a microservice image, wherein the microservice image includes a microservice name and branch information. According to the image template file and the code version number, the platform can automatically generate an image file for subsequent mirroring of the branch code data. Since the entire image file is automatically generated, the efficiency of the entire integration and publishing can be improved when facing a large number of microservice publishing and integration requirements.
参照图5,图5为本申请微服务发布方法第四示例性实施例的流程示意图。Referring to FIG. 5 , FIG. 5 is a flow chart of a fourth exemplary embodiment of a microservice publishing method of the present application.
基于第三实施例,提出本申请第四实施例,本申请第四实施例与第三实施例的区别在于:Based on the third embodiment, a fourth embodiment of the present application is proposed. The difference between the fourth embodiment of the present application and the third embodiment is that:
在本实施例中,对步骤S30,根据所述微服务名称和所述分支信息自动生成声明式文件进行细化,其中细化的步骤可以包括:In this embodiment, step S30, automatically generating a declarative file according to the microservice name and the branch information, is refined, wherein the refinement step may include:
步骤S31,获取声明式模板文件和发布指令;Step S31, obtaining a declarative template file and publishing instructions;
声明式模板文件是指一种用于定义基础设施资源的文本文件,通常使用YAML或JSON格式进行编写,这些文件描述了所需的资源类型、配置和属性以及它们之间的关系,如依赖和引用关系,需要注意的是,声明式模板文件以声明的方式定义基础设施,而不是通过编程方式创建和配置资源。A declarative template file is a text file used to define infrastructure resources. It is usually written in YAML or JSON format. These files describe the required resource types, configurations, and properties, as well as the relationships between them, such as dependencies and references. It should be noted that declarative template files define infrastructure in a declarative manner rather than creating and configuring resources programmatically.
声明式模板文件可以与基础设施管理工具如Kubernetes一起使用,Kubernetes可以读取声明式模板文件并根据其中的定义自动创建和配置基础设施资源,声明式模板文件还可以用于版本控制和协作,多个开发人员可以共同编辑和维护一个模板文件以便更好地管理基础设施的变化和演进。Declarative template files can be used with infrastructure management tools such as Kubernetes. Kubernetes can read declarative template files and automatically create and configure infrastructure resources according to the definitions in them. Declarative template files can also be used for version control and collaboration. Multiple developers can jointly edit and maintain a template file to better manage infrastructure changes and evolution.
发布指令是指一种授权机制的授权指令,在对分支代码进行微服务镜像构建之后,需要将微服务镜像持续发布至各环境集群中,然而,为了避免未经测试的代码进入生产环境从而导致严重的问题,在对微服务镜像进行发布前,可以通过发布指令获取发布授权信息,通过发布指令,可以获取相关信息并根据相关信息生成声明式文件,该声明式文件可以作用于后续对微服务镜像的持续发布。A release instruction refers to an authorization instruction of an authorization mechanism. After building a microservice image for a branch code, the microservice image needs to be continuously released to each environment cluster. However, in order to prevent untested code from entering the production environment and causing serious problems, before releasing the microservice image, you can obtain release authorization information through a release instruction. Through the release instruction, you can obtain relevant information and generate a declarative file based on the relevant information. The declarative file can be used for the subsequent continuous release of the microservice image.
具体地,发布指令可以包括用于查询分支代码数据相关信息的数据,即通过发布指令可以查询后续可用于发布的分支代码数据,例如微服务名称以及分支信息等,可以理解地,只有获取发布指令才可以获取已授权发布的分支代码数据相关信息并生成与该分支代码数据对应的声明式文件。Specifically, the release instruction may include data for querying information related to branch code data, that is, the branch code data that can be used for subsequent release, such as the microservice name and branch information, can be queried through the release instruction. It can be understood that only by obtaining the release instruction can the information related to the branch code data that has been authorized for release be obtained and a declarative file corresponding to the branch code data be generated.
获取声明式模板文件和发布指令的方法可以通过版本控制系统,即声明式模板文件和发布指令可以与代码一起存储在版本控制系统(如Git)中,帮助开发人员或系统平台获取最新的模板文件和发布指令。The method for obtaining declarative template files and release instructions can be through a version control system, that is, the declarative template files and release instructions can be stored in a version control system (such as Git) together with the code, to help developers or system platforms obtain the latest template files and release instructions.
步骤S32,将所述微服务镜像发送至镜像仓库,由所述镜像仓库对所述微服务镜像进行存储管理;Step S32, sending the microservice image to an image warehouse, which stores and manages the microservice image;
镜像仓库是指用于存储和管理容器镜像的中央存储库,用于集中管理和分发容器镜像,镜像仓库提供了一个集中式的位置,供开发人员、运维人员和其他相关方从中获取所需的容器镜像,镜像仓库可以存储多个版本的镜像,并提供标签或标识符来唯一标识每个镜像,具体地,镜像仓库还可以提供了一些额外的功能,例如权限控制、镜像搜索、镜像构建和发布流程、镜像审核和验证等。An image repository is a central repository for storing and managing container images. It is used to centrally manage and distribute container images. The image repository provides a centralized location for developers, operations personnel, and other relevant parties to obtain the required container images. The image repository can store multiple versions of images and provide tags or identifiers to uniquely identify each image. Specifically, the image repository can also provide some additional functions, such as permission control, image search, image building and release process, image review and verification, etc.
步骤S33,根据所述发布指令,从所述镜像仓库获取所述微服务名称和所述分支信息,根据所述声明式模板文件、所述微服务名称和所述分支信息自动生成声明式文件;Step S33, according to the publishing instruction, obtaining the microservice name and the branch information from the image repository, and automatically generating a declarative file according to the declarative template file, the microservice name and the branch information;
获取发布指令后,可以根据发布指令中的分支代码数据相关数据从镜像仓库中获取微服务名称和分支信息并根据获取的微服务名称和分支信息自动生成声明式文件。After obtaining the release instructions, the microservice name and branch information can be obtained from the image repository according to the branch code data related data in the release instructions, and a declarative file can be automatically generated according to the obtained microservice name and branch information.
根据镜像文件对分支代码数据进行镜像构建所得到的微服务镜像带有微服务名称以及分支信息,其中,分支信息可以反映该分支代码数据来源于哪条代码分支,通过该信息,可以将微服务镜像发布到对应的环境集群进行运行,而发布指令中带有查询该分支代码数据的权限以及查询地址,因此,通过查询权限以及查询地址可以在镜像仓库获取分支信息,同理,通过发布指令也可以在镜像仓库获取对应的微服务名称。The microservice image obtained by mirroring the branch code data according to the image file carries the microservice name and branch information, wherein the branch information can reflect which code branch the branch code data comes from. Through this information, the microservice image can be published to the corresponding environment cluster for operation, and the publishing instruction carries the permission and query address for querying the branch code data. Therefore, the branch information can be obtained in the image repository through the query permission and query address. Similarly, the corresponding microservice name can also be obtained in the image repository through the publishing instruction.
根据声明式模板文件、微服务名称和分支信息自动生成声明式文件(如deployment.yaml)的方法可以包括:Methods for automatically generating declarative files (such as deployment.yaml) based on declarative template files, microservice names, and branch information may include:
1、从声明式模板文件中读取需要使用的Kubernetes YAML配置模板,比如包含了部署、服务等相关配置信息的deployment.yaml文件。1. Read the required Kubernetes YAML configuration template from the declarative template file, such as the deployment.yaml file that contains deployment, service and other related configuration information.
2、替换YAML模板中相关变量:根据传入的微服务名称和分支信息,可以将YAML配置模板中的变量替换为具体值,例如,可以使用类似Mustache或Jinja2的模板引擎来实现。2. Replace relevant variables in the YAML template: Based on the passed in microservice name and branch information, you can replace the variables in the YAML configuration template with specific values. For example, you can use a template engine like Mustache or Jinja2 to achieve this.
3、获取对应微服务镜像的信息:可以根据传入的分支信息连接到Docker镜像仓库,获取对应微服务镜像的名称和版本号等信息。3. Get the information of the corresponding microservice image: You can connect to the Docker image repository based on the incoming branch information to obtain the name and version number of the corresponding microservice image.
4、将镜像信息和其他必要信息填充到YAML模板中:将步骤2和步骤3中获取的信息填充到YAML模板中对应的位置。4. Fill the image information and other necessary information into the YAML template: Fill the information obtained in steps 2 and 3 into the corresponding positions in the YAML template.
5、根据需要指定微服务运行实例个数、所需资源等信息,这些信息也可以从传入的参数中获取,然后添加到YAML模板中对应的位置。5. Specify the number of microservice running instances, required resources and other information as needed. This information can also be obtained from the incoming parameters and then added to the corresponding position in the YAML template.
6、将生成的deployment.yaml保存到指定的位置:将生成的文件保存到Git仓库中或者通过Kubernetes API Server直接对镜像进行部署。6. Save the generated deployment.yaml to the specified location: Save the generated file to the Git repository or deploy the image directly through the Kubernetes API Server.
需要注意的是,具体实现可能会有所不同,这里仅提供一种基本的实现方式作为参考,同时,还需要注意对生成的声明式文件进行验证以确保其可以被Kubernetes集群正确解析和部署。It should be noted that the specific implementation may vary. Here we only provide a basic implementation method for reference. At the same time, we also need to verify the generated declarative file to ensure that it can be correctly parsed and deployed by the Kubernetes cluster.
本申请实施例提出的微服务发布方法,通过获取声明式模板文件和发布指令;将所述微服务镜像发送至镜像仓库,由所述镜像仓库对所述微服务镜像进行存储管理;根据所述发布指令,从所述镜像仓库获取所述微服务名称和所述分支信息,根据所述声明式模板文件、所述微服务名称和所述分支信息自动生成声明式文件,将微服务镜像发送至镜像仓库,由镜像仓库对生成的微服务镜像进行上传与下载管理可以提高部署容器化应用程序的效率和可靠性,而根据发布指令从镜像仓库获取微服务名称和分支信息等信息可以避免未经测试的代码进入生产环境从而导致严重的问题,最后,在获取微服务名称和分支信息后,可以根据声明式模板文件自动生成声明式文件,而由于声明式文件是根据发布指令获取的相关信息自动生成的,因此,通过该方法,不仅可以提高获取声明式文件的效率,还可以确保获取的声明式文件具有较高的可用性。The microservice publishing method proposed in the embodiment of the present application obtains a declarative template file and a publishing instruction; sends the microservice image to an image repository, and the image repository stores and manages the microservice image; obtains the microservice name and the branch information from the image repository according to the publishing instruction, automatically generates a declarative file according to the declarative template file, the microservice name and the branch information, sends the microservice image to the image repository, and the image repository manages uploading and downloading the generated microservice image, which can improve the efficiency and reliability of deploying containerized applications, and obtains information such as the microservice name and branch information from the image repository according to the publishing instruction to prevent untested code from entering the production environment and causing serious problems. Finally, after obtaining the microservice name and branch information, a declarative file can be automatically generated according to the declarative template file. Since the declarative file is automatically generated according to the relevant information obtained by the publishing instruction, this method can not only improve the efficiency of obtaining declarative files, but also ensure that the obtained declarative files have high availability.
参照图6,图6为本申请微服务发布方法第五示例性实施例的流程示意图。Referring to FIG. 6 , FIG. 6 is a flowchart of a fifth exemplary embodiment of a microservice publishing method of the present application.
基于第四实施例,提出本申请第五实施例,本申请第五实施例与第四实施例的区别在于:Based on the fourth embodiment, a fifth embodiment of the present application is proposed. The difference between the fifth embodiment of the present application and the fourth embodiment is that:
在本实施例中,对步骤S40,根据所述声明式文件,通过预设的容器编排集群发布微服务镜像进行细化,其中细化的步骤可以包括:In this embodiment, in step S40, according to the declarative file, the microservice image is published through a preset container orchestration cluster for refinement, wherein the refinement step may include:
步骤S41,根据所述分支信息中的环境类型,将所述声明式文件发送至预设的容器编排集群;Step S41, sending the declarative file to a preset container orchestration cluster according to the environment type in the branch information;
其中,环境类型是指分支代码在流程配置gitflow中所处的代码分支的分支类型,由于微服务镜像是由分支代码数据进行镜像而构建得到的,而分支代码数据包括了分支代码所处分支的分支类型,因此,微服务镜像也会包含分支类型,例如,代码来自测试分支,则由该代码构建的微服务镜像会包含表示测试分支的环境类型,为了可以使微服务镜像可以运行在对应的容器编排集群(如kubernetes集群),可以根据微服务镜像中包含的分支信息中的环境类型将声明式文件发送对应环境的集群中。Among them, the environment type refers to the branch type of the code branch where the branch code is located in the process configuration gitflow. Since the microservice image is built by mirroring the branch code data, and the branch code data includes the branch type of the branch where the branch code is located, the microservice image will also contain the branch type. For example, if the code comes from the test branch, the microservice image built by the code will contain the environment type representing the test branch. In order to enable the microservice image to run in the corresponding container orchestration cluster (such as the kubernetes cluster), the declarative file can be sent to the cluster of the corresponding environment according to the environment type in the branch information contained in the microservice image.
具体地,持续发布将不同的微服务镜像的方式发布到不同的环境并以容器的形式运行,举个例子,开发分支(Develop)的微服务镜像发布到开发环境的集群中,测试分支(UAT)的微服务镜像发布到测试环境的集群中,主分支(Master)的微服务镜像发布到生产环境的集群中。Specifically, continuous release publishes different microservice images to different environments and runs them in the form of containers. For example, the microservice image of the development branch (Develop) is published to the cluster of the development environment, the microservice image of the test branch (UAT) is published to the cluster of the test environment, and the microservice image of the master branch (Master) is published to the cluster of the production environment.
此外,开发、测试、生产环境之间存在物理隔离,避免相互影响,同时开发和测试以及运维各司其职,在对应环境完成各自工作,大大提高工程师的工作效率。In addition, there is physical isolation between the development, testing, and production environments to avoid mutual impact. At the same time, development, testing, and operation and maintenance each perform their respective duties and complete their respective work in the corresponding environment, greatly improving the work efficiency of engineers.
步骤S42,根据所述声明式文件,通过所述容器编排集群获取微服务镜像;Step S42, obtaining a microservice image through the container orchestration cluster according to the declarative file;
当容器编排集群获取声明式文件后,容器编排集群可以根据声明式文件中的相关信息,例如镜像地址等获取微服务镜像。After the container orchestration cluster obtains the declarative file, the container orchestration cluster can obtain the microservice image according to the relevant information in the declarative file, such as the image address.
具体地,容器编排集群可以根据声明式文件中指定的微服务名称和版本号自动拉取对应环境的微服务镜像并进行部署,如果要查看微服务镜像是否成功拉取,可以使用Kubernetes的命令行工具kubectl进行查看。Specifically, the container orchestration cluster can automatically pull the microservice image of the corresponding environment and deploy it according to the microservice name and version number specified in the declarative file. If you want to check whether the microservice image is successfully pulled, you can use the Kubernetes command line tool kubectl to check.
步骤S43,通过所述容器编排集群,对所述微服务镜像进行发布;Step S43, publishing the microservice image through the container orchestration cluster;
当容器编排集群获取微服务镜像后,可以对微服务镜像进行发布。After the container orchestration cluster obtains the microservice image, it can publish the microservice image.
具体地,对微服务镜像进行发布方法可以包括:Specifically, the method for publishing a microservice image may include:
创建命名空间:在集群中创建一个命名空间(Namespace),用于隔离不同的应用程序或服务。Create a namespace: Create a namespace in the cluster to isolate different applications or services.
创建服务配置:根据实际需求创建一个服务配置文件(Service Configuration),其中包括服务名称、端口号、协议等信息。这将帮助集群管理和暴露你的微服务。Create a service configuration: Create a service configuration file (Service Configuration) according to actual needs, which includes information such as service name, port number, protocol, etc. This will help cluster management and expose your microservices.
创建部署文件:使用声明式文件,定义微服务的部署配置,部署文件中应包含容器镜像的名称、版本号、资源要求、环境变量等信息。Create a deployment file: Use a declarative file to define the deployment configuration of the microservice. The deployment file should contain information such as the container image name, version number, resource requirements, and environment variables.
应用部署:使用kubectl等工具,将部署文件应用到集群中,这将触发集群根据部署文件创建相应的Pod并将微服务镜像拉取到集群节点上运行。Application deployment: Use tools such as kubectl to apply the deployment file to the cluster, which will trigger the cluster to create the corresponding Pod according to the deployment file and pull the microservice image to the cluster node for running.
验证发布:通过访问服务的入口点,验证微服务是否成功发布并正常工作,确保服务能够响应请求并按照预期提供功能。Verify release: Verify that the microservice is successfully released and working properly by accessing the service entry point to ensure that the service can respond to requests and provide functions as expected.
需要注意的是,上述方法是其中一个微服务镜像发布流程,具体步骤可以根据实际情况进行调整。It should be noted that the above method is one of the microservice image release processes, and the specific steps can be adjusted according to actual conditions.
本申请实施例提出的微服务发布方法,通过根据所述分支信息中的环境类型,将所述声明式文件发送至预设的容器编排集群;根据所述声明式文件,通过所述容器编排集群获取微服务镜像;通过所述容器编排集群,对所述微服务镜像进行发布,根据分支信息中的环境类型,可以将生成的声明式文件发送至各环境的容器编排集群中,而容器编排集群接收到声明式文件后,可以根据声明式文件中对应的微服务镜像信息在镜像仓库中查询并拉取相关微服务镜像,最后将拉取的微服务镜像在集群中发布,通过该方法,微服务镜像可以被持续发布至对应环境的容器编排集群中,提高微服务镜像的持续发布效率。The microservice publishing method proposed in the embodiment of the present application sends the declarative file to a preset container orchestration cluster according to the environment type in the branch information; obtains the microservice image through the container orchestration cluster according to the declarative file; and publishes the microservice image through the container orchestration cluster. According to the environment type in the branch information, the generated declarative file can be sent to the container orchestration cluster of each environment. After the container orchestration cluster receives the declarative file, it can query and pull the relevant microservice image in the image repository according to the corresponding microservice image information in the declarative file, and finally publish the pulled microservice image in the cluster. Through this method, microservice images can be continuously published to the container orchestration cluster of the corresponding environment, thereby improving the continuous publishing efficiency of microservice images.
参照图7,图7为本申请微服务发布方法第六示例性实施例的流程示意图。Referring to FIG. 7 , FIG. 7 is a flowchart of a sixth exemplary embodiment of a microservice publishing method of the present application.
基于第五实施例,提出本申请第六实施例,本申请第六实施例与第五实施例的区别在于:Based on the fifth embodiment, a sixth embodiment of the present application is proposed. The difference between the sixth embodiment of the present application and the fifth embodiment is that:
在本实施例中,对步骤S42,根据所述声明式文件,通过所述容器编排集群获取微服务镜像进行细化,其中细化的步骤可以包括:In this embodiment, in step S42, the microservice image is obtained through the container orchestration cluster according to the declarative file and refined, wherein the refining step may include:
步骤S421,通过所述容器编排集群获取镜像仓库访问权限;Step S421, obtaining image repository access rights through the container orchestration cluster;
镜像仓库访问权限是指在容器编排集群中,用于在镜像仓库中拉取微服务镜像所需的权限。当容器编排集群需要从镜像仓库中拉取镜像时,容器编排集群需要提供合法的凭证来验证其身份并获取访问权限。Image repository access permissions refer to permissions required to pull microservice images from the image repository in a container orchestration cluster. When a container orchestration cluster needs to pull images from the image repository, the container orchestration cluster needs to provide legitimate credentials to verify its identity and obtain access permissions.
具体地,获取镜像仓库访问权限的方法可以包括:Specifically, methods for obtaining access rights to an image repository may include:
用户名和密码:使用用户名和密码作为凭证进行认证,具体地,可以在容器编排集群创建一个Secret对象并将用户名和密码信息存储在其中,进一步地,在声明式文件中引用该Secret对象以便集群可以使用这些凭证来拉取对应的微服务镜像。Username and password: Use username and password as credentials for authentication. Specifically, you can create a Secret object in the container orchestration cluster and store the username and password information in it. Further, reference the Secret object in the declarative file so that the cluster can use these credentials to pull the corresponding microservice image.
令牌(Token):创建一个访问令牌以便集群可以使用该令牌进行身份验证,具体地,可以在镜像仓库中生成一个访问令牌并将其存储在集群的Secret对象中,然后,在声明式文件中指定使用该Secret对象中的令牌信息。Token: Create an access token so that the cluster can use the token for authentication. Specifically, you can generate an access token in the image repository and store it in the cluster's Secret object. Then, specify the token information in the Secret object in the declarative file.
OAuth令牌:若镜像仓库支持OAuth认证时,可以生成一个OAuth令牌,并将其存储在集群的Secret对象中,然后,在声明式文件中指定使用该Secret对象中的令牌信息。OAuth token: If the image repository supports OAuth authentication, you can generate an OAuth token and store it in the cluster's Secret object. Then, specify the token information in the Secret object in the declarative file.
以上是部分获取镜像仓库访问权限的方式,具体的获取镜像仓库访问权限的方式可以取决于所使用的镜像仓库平台和认证机制。The above are some ways to obtain access rights to the image repository. The specific way to obtain access rights to the image repository may depend on the image repository platform and authentication mechanism used.
步骤S422,根据所述访问权限和镜像地址,通过所述容器编排集群在所述镜像仓库中拉取镜像,得到微服务镜像,所述镜像地址包括在所述声明式文件;Step S422, according to the access permission and the image address, pull the image from the image repository through the container orchestration cluster to obtain a microservice image, wherein the image address is included in the declarative file;
具体地,获取镜像仓库访问权限后,容器编排集群拉取微服务镜像的步骤可以包括:Specifically, after obtaining access rights to the image repository, the steps for the container orchestration cluster to pull the microservice image may include:
应用声明式文件:使用kubectl或其他工具,将声明式文件部署到集群中并根据声明式文件的定义创建一个或多个Pod,随后,集群根据访问权限和镜像地址从镜像仓库中拉取对应的微服务镜像到这些Pod中运行。Apply declarative files: Use kubectl or other tools to deploy the declarative files to the cluster and create one or more Pods based on the definition of the declarative files. Then, the cluster pulls the corresponding microservice images from the image repository based on the access permissions and image address and runs them in these Pods.
拉取镜像:根据声明式文件中指定的镜像地址,容器编排集群会通过访问权限验证身份并使用相应的凭证去镜像仓库中拉取微服务镜像,集群会自动处理认证流程并下载所需的镜像文件。Pull the image: According to the image address specified in the declarative file, the container orchestration cluster will verify the identity through access permissions and use the corresponding credentials to pull the microservice image from the image repository. The cluster will automatically handle the authentication process and download the required image file.
获取微服务镜像:一旦镜像拉取成功,容器编排集群就会在集群节点上创建相应的容器,并使用所拉取的微服务镜像构建和运行这些容器。这样,你就成功获得了所需的微服务镜像。Get the microservice image: Once the image is pulled successfully, the container orchestration cluster will create the corresponding containers on the cluster nodes and build and run these containers using the pulled microservice image. In this way, you have successfully obtained the required microservice image.
本申请实施例提出的微服务发布方法,通过所述容器编排集群获取镜像仓库访问权限;根据所述访问权限和镜像地址,通过所述容器编排集群在所述镜像仓库中拉取镜像,得到微服务镜像,所述镜像地址包括在所述声明式文件,根据镜像仓库访问权限,容器编排集群可以访问镜像仓库,而通过镜像地址,容器编排集群可以在镜像仓库中查询并拉取对应的微服务镜像,得到微服务镜像,通过该方法,容器编排集群可以准确且安全地拉取对应的微服务镜像,提高了系统的安全性。The microservice publishing method proposed in the embodiment of the present application obtains image repository access rights through the container orchestration cluster; according to the access rights and the image address, the image is pulled from the image repository through the container orchestration cluster to obtain a microservice image, and the image address is included in the declarative file. According to the image repository access rights, the container orchestration cluster can access the image repository, and through the image address, the container orchestration cluster can query and pull the corresponding microservice image in the image repository to obtain the microservice image. Through this method, the container orchestration cluster can accurately and securely pull the corresponding microservice image, thereby improving the security of the system.
参照图8,图8为本申请微服务发布方法第七示例性实施例的流程示意图。Referring to FIG. 8 , FIG. 8 is a flow chart of a seventh exemplary embodiment of the microservice publishing method of the present application.
基于第六实施例,提出本申请第七实施例,本申请第七实施例与第六实施例的区别在于:Based on the sixth embodiment, a seventh embodiment of the present application is proposed. The difference between the seventh embodiment of the present application and the sixth embodiment is that:
在本实施例中,在步骤S43,通过所述容器编排集群,对所述微服务镜像进行发布之后还包括:In this embodiment, in step S43, after publishing the microservice image through the container orchestration cluster, the following further includes:
步骤S50,通过预设的容器管理平台rancher对所述微服务镜像进行监管,得到微服务数据,所述微服务数据包括微服务实例状态和日志信息;Step S50, supervising the microservice image through the preset container management platform Rancher to obtain microservice data, wherein the microservice data includes microservice instance status and log information;
微服务发布完成并正常运行之后,可以采用容器管理平台(rancher)对其进行管理,在容器管理平台可以监控微服务实例状态、日志和资源使用情况。After the microservice is released and running normally, you can use the container management platform (rancher) to manage it. The container management platform can monitor the microservice instance status, logs, and resource usage.
其中,容器管理平台Rancher是一个开源的容器管理平台,旨在简化容器化应用程序的部署、管理和操作。它提供了一个统一的界面和工具集,帮助用户轻松地在生产环境中管理容器化的应用程序和基础设施。Among them, the container management platform Rancher is an open source container management platform designed to simplify the deployment, management and operation of containerized applications. It provides a unified interface and tool set to help users easily manage containerized applications and infrastructure in a production environment.
具体地,容器管理平台rancher的功能可以包括:Specifically, the functions of the container management platform Rancher can include:
多集群管理:Rancher可以支持管理不同环境下的多个Kubernetes集群,用户可以通过统一的可视化界面来管理不同类型的容器集群而无需切换多个管理工具。Multi-cluster management: Rancher can support the management of multiple Kubernetes clusters in different environments. Users can manage different types of container clusters through a unified visual interface without switching multiple management tools.
用户友好的界面:Rancher提供了直观易用的Web界面,让用户能够轻松地进行集群部署、监控、扩展和维护等操作,无需深入了解底层技术细节。User-friendly interface: Rancher provides an intuitive and easy-to-use web interface that allows users to easily deploy, monitor, expand, and maintain clusters without having to delve into the underlying technical details.
安全和权限控制:Rancher可以支持对用户和团队的权限管理,可以定义不同角色和权限策略以确保只有授权人员能够进行特定的操作。Security and permission control: Rancher can support permission management for users and teams, and can define different roles and permission policies to ensure that only authorized personnel can perform specific operations.
持续交付和CI/CD:Rancher整合了持续交付(Continuous Delivery)以及持续集成/持续部署(CI/CD)工具,使得用户能够通过Rancher平台实现自动化的部署流程。Continuous Delivery and CI/CD: Rancher integrates continuous delivery (Continuous Delivery) and continuous integration/continuous deployment (CI/CD) tools, allowing users to automate deployment processes through the Rancher platform.
其中,微服务实例状态是指运行在容器中的微服务的当前状态,具体地,微服务实例状态可以包括以下信息:The microservice instance status refers to the current status of the microservice running in the container. Specifically, the microservice instance status may include the following information:
运行状态:表示微服务实例是否正在运行、已停止或出现故障。Running status: Indicates whether the microservice instance is running, stopped, or faulty.
健康状态:表示微服务实例的健康状况,例如是否正常、是否有错误或警告等。Health status: indicates the health status of the microservice instance, such as whether it is normal, whether there are errors or warnings, etc.
资源利用情况:表示微服务实例当前所使用的计算资源(如CPU、内存、存储)的利用率。Resource utilization: Indicates the utilization of computing resources (such as CPU, memory, and storage) currently used by the microservice instance.
运行时间:表示微服务实例从启动到当前的运行时间。Running time: indicates the running time of the microservice instance from startup to the current time.
日志信息是指在运行过程中所产生的日志记录。它包括微服务实例的输出、错误、警告以及其他与应用程序相关的日志消息。通过查看微服务实例的日志信息,管理员和开发人员可以追踪应用程序的执行过程,排查问题并进行故障排除。Log information refers to the log records generated during the operation process. It includes the output, errors, warnings, and other log messages related to the microservice instance. By viewing the log information of the microservice instance, administrators and developers can track the execution process of the application, troubleshoot problems, and perform troubleshooting.
通过监控微服务实例状态和查看日志信息,容器管理平台Rancher可以帮助用户更好地了解微服务的运行状况,及时发现和解决问题,从而提高应用程序的可靠性和可维护性。By monitoring the status of microservice instances and viewing log information, the container management platform Rancher can help users better understand the operating status of microservices, discover and solve problems in a timely manner, and thus improve the reliability and maintainability of applications.
步骤S51,根据所述微服务实例状态和所述日志信息,通过所述容器管理平台rancher对微服务进行调整;Step S51, adjusting the microservice through the container management platform Rancher according to the microservice instance status and the log information;
根据微服务实例状态和日志信息,容器管理平台rancher可以对微服务进行调整,具体地,调整操作可以包括:Based on the microservice instance status and log information, the container management platform Rancher can adjust the microservice. Specifically, the adjustment operations may include:
扩容和缩容:根据微服务实例状态和资源利用情况判断是否需要增加或减少微服务实例的数量,若发现某个微服务实例的资源利用率高,可以选择扩容该实例,增加其副本数量以满足负载需求,反之,若某个实例资源利用率低,可以选择缩容该实例,减少其副本数量以节省资源。Scaling: Determine whether to increase or decrease the number of microservice instances based on the status of the microservice instances and resource utilization. If you find that the resource utilization of a microservice instance is high, you can choose to scale up the instance and increase the number of its replicas to meet the load demand. Conversely, if the resource utilization of an instance is low, you can choose to scale down the instance and reduce the number of its replicas to save resources.
故障恢复:通过监测微服务实例的健康状态和日志信息可以及时发现出现故障的实例,当出现故障时,可以使用平台提供的自动故障恢复机制,例如自动重启实例、替换故障实例等以确保微服务的可用性。Fault recovery: By monitoring the health status and log information of microservice instances, you can promptly detect faulty instances. When a fault occurs, you can use the automatic fault recovery mechanism provided by the platform, such as automatically restarting the instance, replacing the faulty instance, etc. to ensure the availability of the microservice.
日志分析和故障排查:容器管理平台提供了对微服务实例日志信息的聚合和展示功能,管理员和开发人员可以搜索、过滤和查看微服务实例的日志,以追踪应用程序的执行过程并进行故障排查。通过分析日志信息,可以快速定位问题所在,并采取相应的调整措施。Log analysis and troubleshooting: The container management platform provides the function of aggregating and displaying the log information of microservice instances. Administrators and developers can search, filter, and view the logs of microservice instances to track the execution process of applications and perform troubleshooting. By analyzing the log information, problems can be quickly located and corresponding adjustment measures can be taken.
性能优化:通过监控微服务实例的资源利用情况和性能指标,可以发现潜在的性能瓶颈或资源短缺问题。根据这些信息,可以进行调整,例如调整微服务的资源配额、优化配置参数、重新设计服务架构等,以提高微服务的性能和可扩展性。Performance optimization: By monitoring the resource utilization and performance indicators of microservice instances, potential performance bottlenecks or resource shortages can be discovered. Based on this information, adjustments can be made, such as adjusting the resource quota of microservices, optimizing configuration parameters, and redesigning the service architecture to improve the performance and scalability of microservices.
本申请实施例提出的微服务发布方法,通过预设的容器管理平台rancher对所述微服务镜像进行监管,得到微服务数据,所述微服务数据包括;根据所述微服务实例状态和所述日志信息,通过所述容器管理平台rancher对微服务进行调整,根据微服务实例状态和日志信息,容器管理平台可以提供有针对性的调整操作,帮助管理员和开发人员优化微服务的运行状况、解决问题,通过该方法可以提高整体应用程序的可靠性和性能。The microservice publishing method proposed in the embodiment of the present application supervises the microservice image through a preset container management platform Rancher to obtain microservice data, and the microservice data includes: adjusting the microservice through the container management platform Rancher according to the microservice instance status and the log information. According to the microservice instance status and the log information, the container management platform can provide targeted adjustment operations to help administrators and developers optimize the operating status of microservices and solve problems. This method can improve the reliability and performance of the overall application.
图9为本申请微服务发布方法流程示意图。FIG9 is a flow chart of the microservice publishing method of the present application.
如图9所示,整体流程可以分为以下步骤:As shown in Figure 9, the overall process can be divided into the following steps:
步骤S1:开发人员将目标代码提交到代码仓库(Gitlab)中,具体地,可以使用Git进行版本控制,同时,采用流程配置gitflow来管理代码的分支和版本,流程配置gitflow是一种常用的分支管理策略,通过采用流程配置gitflow对目标代码进行管理可以有效避免代码冲突,提高代码管理效率,进而提高开发和发布效率。Step S1: The developer submits the target code to the code repository (Gitlab). Specifically, Git can be used for version control. At the same time, the process configuration gitflow is used to manage the branches and versions of the code. The process configuration gitflow is a commonly used branch management strategy. By using the process configuration gitflow to manage the target code, code conflicts can be effectively avoided, code management efficiency can be improved, and development and release efficiency can be improved.
步骤S2:将目标代码提交到代码仓库(Gitlab)并创建分支之后,就可以进行持续集成,持续集成的过程可以基于容器技术(Docker)实现,在这个过程中,可以基于镜像文件(Dockerfile)为分支代码数据创建镜像,然后将镜像推送到镜像仓库(用于统一管理容器镜像的仓库,用于上传、下载镜像),其中镜像文件(Dockerfile)在发布平台基于模板自动生成,当有多个微服务的时候也无需人为操作,降低多个微服务发布的难度和出错概率,同时微服务每个版本的镜像存放在镜像仓库,微服务出现问题时,可以追溯是哪个版本镜像出现问题,并随时回滚到之前正常的版本。Step S2: After submitting the target code to the code repository (Gitlab) and creating a branch, continuous integration can be performed. The continuous integration process can be implemented based on container technology (Docker). In this process, an image can be created for the branch code data based on the image file (Dockerfile), and then the image can be pushed to the image repository (a warehouse used to uniformly manage container images, for uploading and downloading images). The image file (Dockerfile) is automatically generated based on a template on the publishing platform. When there are multiple microservices, no manual operation is required, which reduces the difficulty and error probability of publishing multiple microservices. At the same time, the image of each version of the microservice is stored in the image repository. When a problem occurs with a microservice, it can be traced back to which version of the image has the problem, and it can be rolled back to the previous normal version at any time.
步骤S3:微服务镜像创建完成并上传到镜像仓库之后,便可以进行持续发布,持续发布的过程中,可以将不同的微服务镜像发布到不同环境的容器编排集群中(如图9中K8S集群),微服务镜像在容器编排集群中以容器的形式运行,如图9所示,其中开发分支(Develop)的微服务镜像发布到开发环境,测试分支(UAT)的微服务镜像发布到测试环境,主分支(Master)的微服务镜像发布到生产环境,需要注意的是,各环境的容器编排集群相互隔离,避免相互影响,同时开发和测试以及运维各司其职,在对应环境完成各自工作,大大提高工程师的工作效率。Step S3: After the microservice image is created and uploaded to the image repository, it can be continuously released. During the continuous release process, different microservice images can be released to container orchestration clusters in different environments (such as the K8S cluster in Figure 9). The microservice image runs in the container orchestration cluster in the form of a container, as shown in Figure 9, where the microservice image of the development branch (Develop) is released to the development environment, the microservice image of the test branch (UAT) is released to the test environment, and the microservice image of the master branch (Master) is released to the production environment. It should be noted that the container orchestration clusters of each environment are isolated from each other to avoid mutual influence. At the same time, development, testing, and operation and maintenance each perform their duties and complete their respective work in the corresponding environment, greatly improving the work efficiency of engineers.
步骤S4:持续发布基于容器编排技术(kubernetes),其中发布平台可以根据微服务名称和微服务所在的代码分支自动生成容器管理集群(kubernetes容器编排集群)所需的声明式文件deployment.yaml(该文件可以包括上述步骤生成的微服务镜像、微服务运行实例个数、微服务所需资源等信息),基于该声明式文件,微服务镜像可以以容器的形式运行在容器编排集群中,另外容器编排集群(kubernetes集群)可以将微服务自动调度到资源充足的节点运行,当微服务异常时,也可以自动拉起,也即微服务同容器编排技术结合,可以大大提高微服务系统的稳定性。Step S4: Continuous publishing is based on container orchestration technology (Kubernetes), in which the publishing platform can automatically generate the declarative file deployment.yaml required by the container management cluster (Kubernetes container orchestration cluster) according to the microservice name and the code branch where the microservice is located (this file may include the microservice image generated in the above steps, the number of microservice running instances, the resources required for the microservice, and other information). Based on this declarative file, the microservice image can be run in the container orchestration cluster in the form of a container. In addition, the container orchestration cluster (Kubernetes cluster) can automatically schedule the microservice to a node with sufficient resources to run. When the microservice is abnormal, it can also be automatically pulled up. That is, the combination of microservices and container orchestration technology can greatly improve the stability of the microservice system.
步骤S5:当微服务发布完成并正常运行之后,可以采用容器管理平台(rancher)对其进行管理,在容器管理平台可以监控微服务实例的状态、日志和资源使用情况,也可以对微服务进行扩容、缩容或更新,以及其他的管理操作,在容器平台管理下,可以进一步提高微服务的稳定性。Step S5: After the microservice is published and running normally, it can be managed by a container management platform (rancher). The container management platform can monitor the status, logs, and resource usage of the microservice instance, and can also expand, shrink, or update the microservice, as well as perform other management operations. Under the management of the container platform, the stability of the microservice can be further improved.
此外,本申请实施例还提出一种微服务发布装置,所述微服务发布装置包括:In addition, the embodiment of the present application also provides a microservice publishing device, the microservice publishing device comprising:
数据获取模块,用于获取分支代码数据;A data acquisition module, used to acquire branch code data;
镜像构建模块,用于根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;An image building module, used to generate an image file according to the branch code data, and build a microservice image through the image file, wherein the microservice image includes a microservice name and branch information;
文件生成模块,用于根据所述微服务名称和所述分支信息自动生成声明式文件;A file generation module, used to automatically generate a declarative file according to the microservice name and the branch information;
微服务发布模块,用于根据所述声明式文件,通过预设的容器编排集群发布微服务镜像。The microservice publishing module is used to publish the microservice image through a preset container orchestration cluster according to the declarative file.
本实施例实现微服务发布的原理及实施过程,请参照上述各实施例,在此不再赘述。For the principle and implementation process of implementing microservice release in this embodiment, please refer to the above embodiments and will not be repeated here.
此外,本申请实施例还提出一种终端设备,所述终端设备包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的微服务发布程序,所述微服务发布程序被所述处理器执行时实现如上所述的微服务发布方法的步骤。In addition, an embodiment of the present application also proposes a terminal device, which includes a memory, a processor, and a microservice publishing program stored in the memory and executable on the processor, and the microservice publishing program implements the steps of the microservice publishing method described above when executed by the processor.
由于本微服务发布程序被处理器执行时,采用了前述所有实施例的全部技术方案,因此至少具有前述所有实施例的全部技术方案所带来的所有有益效果,在此不再一一赘述。Since all the technical solutions of all the aforementioned embodiments are adopted when this microservice publishing program is executed by the processor, it has at least all the beneficial effects brought by all the technical solutions of all the aforementioned embodiments, which will not be described one by one here.
此外,本申请实施例还提出一种终端设备,所述终端设备包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的微服务发布程序,所述微服务发布程序被所述处理器执行时实现如上所述的微服务发布方法的步骤。In addition, an embodiment of the present application also proposes a terminal device, which includes a memory, a processor, and a microservice publishing program stored in the memory and executable on the processor, and the microservice publishing program implements the steps of the microservice publishing method described above when executed by the processor.
由于本微服务发布程序被处理器执行时,采用了前述所有实施例的全部技术方案,因此至少具有前述所有实施例的全部技术方案所带来的所有有益效果,在此不再一一赘述。Since all the technical solutions of all the aforementioned embodiments are adopted when this microservice publishing program is executed by the processor, it has at least all the beneficial effects brought by all the technical solutions of all the aforementioned embodiments, which will not be described one by one here.
相比现有技术,本申请实施例提出的微服务发布方法,通过获取分支代码数据;根据所述分支代码数据生成镜像文件,并通过所述镜像文件构建微服务镜像,所述微服务镜像包括微服务名称以及分支信息;根据所述微服务名称和所述分支信息生成声明式文件;根据所述声明式文件,通过预设的容器编排集群发布微服务镜像,由于,镜像文件和声明式文件在微服务发布的过程中起到关键的作用,当有大量微服务需要进行发布时,对于每个微服务而言,每次的发布都需要手动修改对应的镜像文件以及声明式文件,过程十分繁琐且效率较低,而本方案中的镜像文件以及声明式文件是根据对应的数据自动生成的,不需要人为干预,因此,通过该方式,不仅可以极大地降低出错的概率,还可以使微服务的发布过程更具自动化,提高微服务整体的发布效率。Compared with the prior art, the microservice publishing method proposed in the embodiment of the present application obtains branch code data; generates an image file according to the branch code data, and builds a microservice image through the image file, wherein the microservice image includes a microservice name and branch information; generates a declarative file according to the microservice name and the branch information; and publishes the microservice image through a preset container orchestration cluster according to the declarative file. Since image files and declarative files play a key role in the microservice publishing process, when a large number of microservices need to be published, for each microservice, each publication requires manual modification of the corresponding image files and declarative files, and the process is very cumbersome and inefficient. The image files and declarative files in this solution are automatically generated according to the corresponding data, and no human intervention is required. Therefore, in this way, not only the probability of errors can be greatly reduced, but also the microservice publishing process can be made more automated, thereby improving the overall publishing efficiency of microservices.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410786721.3A CN118656085A (en) | 2024-06-18 | 2024-06-18 | Microservice publishing method, device, terminal device and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202410786721.3A CN118656085A (en) | 2024-06-18 | 2024-06-18 | Microservice publishing method, device, terminal device and storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN118656085A true CN118656085A (en) | 2024-09-17 |
Family
ID=92706569
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202410786721.3A Pending CN118656085A (en) | 2024-06-18 | 2024-06-18 | Microservice publishing method, device, terminal device and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN118656085A (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119322621A (en) * | 2024-09-30 | 2025-01-17 | 湖南长银五八消费金融股份有限公司 | Method and device for deploying micro-service application cluster |
-
2024
- 2024-06-18 CN CN202410786721.3A patent/CN118656085A/en active Pending
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119322621A (en) * | 2024-09-30 | 2025-01-17 | 湖南长银五八消费金融股份有限公司 | Method and device for deploying micro-service application cluster |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US10191733B2 (en) | Software change process orchestration in a runtime environment | |
| CN110928529B (en) | Method and system for assisting operator development | |
| US10565095B2 (en) | Hybrid testing automation engine | |
| US20230236809A1 (en) | Ios application program construction method and apparatus, electronic device, and storage medium | |
| CN106559438B (en) | A program upload method and device based on a target network platform | |
| US9274843B2 (en) | Multi-redundant switchable process pooling for cloud it services delivery | |
| CN113434158B (en) | Custom management method, device, equipment and medium for big data component | |
| US10656971B2 (en) | Agile framework for vertical application development and delivery | |
| US20110004564A1 (en) | Model Based Deployment Of Computer Based Business Process On Dedicated Hardware | |
| CN107370786A (en) | A kind of general information management system based on micro services framework | |
| US9459859B2 (en) | Template derivation for configuration object management | |
| CN112036825A (en) | Automatic operation and maintenance management system based on work order | |
| US10732948B2 (en) | System and method for implementing automated deployment | |
| CN111274001A (en) | Micro-service management platform | |
| US20140123114A1 (en) | Framework for integration and execution standardization (fiesta) | |
| US20170220324A1 (en) | Data communication accelerator system | |
| CN106776127A (en) | An activity-based disaster recovery management system and management method | |
| CN109002307A (en) | A kind of upgrading and automated testing method automatically | |
| CN117931159B (en) | Cloud native security-based low-code platform building system | |
| CN111596928A (en) | Application control method and device and electronic equipment | |
| US20240192974A1 (en) | Simulation of one or more pipeline jobs in a software deployment pipeline | |
| CN118656085A (en) | Microservice publishing method, device, terminal device and storage medium | |
| CN103729286B (en) | Automatic test platform for embedded device | |
| CN119987798A (en) | Component deployment method, device, equipment, storage medium and product | |
| Bhattacharjee et al. | Cloudcamp: A model-driven generative approach for automating cloud application deployment and management |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |