Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 40 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
# devops-framework
![GitHub](https://img.shields.io/github/license/bkdevops-projects/devops-framework)
![Maven Central](https://img.shields.io/maven-central/v/com.tencent.devops/devops-boot)
![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/bkdevops-projects/devops-framework/build)
<h1 align="center" style="font-weight: bold;">DevOps Boot</h1>
<h4 align="center">基于Spring Boot的微服务快速开发框架</h4>
<div align="center">

[![GitHub](https://img.shields.io/github/license/bkdevops-projects/devops-framework)](https://img.shields.io/github/license/bkdevops-projects/devops-framework)
[![Maven Central](https://img.shields.io/maven-central/v/com.tencent.devops/devops-boot)](https://img.shields.io/maven-central/v/com.tencent.devops/devops-boot)
[![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/bkdevops-projects/devops-framework/build)](https://img.shields.io/github/workflow/status/bkdevops-projects/devops-framework/build)

`devops-framework`是一款基于`Spring Boot`的微服务快速开发框架,提炼自腾讯DevOps团队内部多个项目,使用约定优于配置的设计理念,帮助我们专注于`DevOps`业务快速开发。
</div>

## 项目特点
<div align="center">

[中文文档地址](https://bkdevops-projects.github.io/devops-framework/)

</div>

----------

## DevOps Boot 是什么?

`devops-boot`提炼自腾讯DevOps团队内部多个项目,使用约定优于配置的设计理念,帮助我们专注于DevOps业务快速开发,它具有以下优势:

- **简单** :几乎零配置快速开发微服务,低成本上手
- **易用** :采用`Spring Boot`组件化思想,易于学习理解
- **统一** :目前已集成了微服务开发常用组件和统一配置
- **扩展** :组件之间低耦合,高内聚,扩展十分方便

查看[快速开始](quick-start.md)了解详情。

## DevOps Boot 能解决什么问题?

- **统一项目配置** : 免去繁琐的项目配置,gradle插件帮您解决烦恼
- **统一依赖版本管理** : 多个项目统一jdk和三方依赖版本,避免版本冲突
- **统一微服务治理解决方案**: 解决多个项目技术方案参差不齐,架构不统一问题
- **统一常用工具类** : 避免代码重复

## 功能特性
- 提供gradle快速开发插件[devops-boot-gradle-plugin](./devops-boot-project/devops-boot-tools/devops-boot-gradle-plugin/README.md)
- 提供gradle快速发布插件[devops-publish-gradle-plugin](./devops-boot-project/devops-boot-tools/devops-publish-gradle-plugin/README.md)
- 提供统一版本依赖管理[devops-boot-dependencies](./devops-boot-project/devops-boot-dependencies/README.md)
- 提供多个开箱即用的starter组件
- [starter-logging](./devops-boot-project/devops-boot-starters/devops-boot-starter-logging/README.md)
- [starter-api](./devops-boot-project/devops-boot-starters/devops-boot-starter-api/README.md)
- [starter-logging](./devops-boot-project/devops-boot-starters/devops-boot-starter-logging/README.md)
- [starter-web](./devops-boot-project/devops-boot-starters/devops-boot-starter-web/README.md)
- [starter-service](./devops-boot-project/devops-boot-starters/devops-boot-starter-service/README.md)
- TODO

## 快速开始
- **gradle.build.kts**
```groovy
// 添加devops-boot gradle插件
plugins {
id("com.tencent.devops.boot") version ${version}
}

dependencies {
// 添加需要的starter组件
implementation("com.tencent.devops:devops-boot-starter-web")
}
```
只需要添加`devops-boot`插件,就自动为我们配置好`jdk`版本、编译选项、依赖管理、`kotlin`依赖及`kotlin-spring`插件等等繁琐的配置项。

接下来即可直接开始业务逻辑代码的编写了。


## 工程结构
```shell script
devops-framework/
├── buildSrc # gradle项目构建目录
├── devops-boot-project # devops-boot源码目录
│   ├── devops-boot-core # 核心模块
│   ├── devops-boot-dependencies # maven bom模块
│   ├── devops-boot-starters # starter组件目录
│   └── devops-boot-tools # gradle脚本等工具目录
├── devops-boot-sample # sample项目
└── docs # 开发文档
```
- ...

## 核心依赖

Expand All @@ -55,11 +52,9 @@ devops-framework/
| JDK | 1.8+ |
| Kotlin | 1.4.32 |
| Gradle | 6.8.3 |
| Spring Boot | 2.3.7.RELEASE |
| Spring Cloud | Hoxton.SR9 |
| Spring Boot | 2.4.5 |
| Spring Cloud | 2020.0.2 |

## 示例

## 发行版本
- 0.0.1 2020年10月9日
- 0.0.2 2020年12月22日
- 0.0.3 2021年1月5日
可以查看[sample](https://github.com/bkdevops-projects/devops-framework/tree/master/devops-boot-sample)来了解如何优雅集成`devops-boot`框架。
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description = "DevOps Boot Plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
description = "DevOps Boot Plugin Api"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tencent.devops.plugin.api

/**
* 用于标记扩展类
*/
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
@MustBeDocumented
annotation class Extension
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tencent.devops.plugin.api

/**
* 扩展点
* 插件中的扩展类需要实现该接口
*/
interface ExtensionPoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.tencent.devops.plugin.api

/**
* 扩展注册器
*/
interface ExtensionRegistry {

/**
* 注册扩展controller
* @param plugin 插件名称
* @param type 扩展controller class类型
*/
fun registerExtensionController(plugin: String, name: String, type: Class<*>)

/**
* 注册扩展点
* @param plugin 插件名称
* @param type 扩展point class类型
*/
fun registerExtensionPoint(plugin: String, name: String, type: Class<*>)

/**
* 查找扩展点
* @param type 扩展点类型
*/
fun <T : ExtensionPoint> findExtensionPoints(type: Class<T>): List<T>

/**
* 注销插件[plugin]相关的扩展point
*/
fun unregisterExtensionPointsByPlugin(plugin: String)

/**
* 注销插件[plugin]相关的扩展controller
*/
fun unregisterExtensionControllerByPlugin(plugin: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tencent.devops.plugin.api

/**
* 扩展类型
*/
enum class ExtensionType(val identifier: String) {
/**
* 扩展controller,可以通过插件实现新增接口
*/
CONTROLLER("ExtensionController"),

/**
* 扩展点,可以通过插件实现新增逻辑
*/
POINT("ExtensionPoint")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.tencent.devops.plugin.api

const val EXTENSION_LOCATION = "META-INF/extensions.factories"
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.tencent.devops.plugin.api

/**
* 插件信息
*/
class PluginInfo(
/**
* 插件id
*/
val id: String,
/**
* 插件元数据信息
*/
val metadata: PluginMetadata,
/**
* 文件摘要
*/
val digest: String,
/**
* 插件扩展点
*/
val extensionPoints: List<String>,
/**
* 扩展controller
*/
val extensionControllers: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tencent.devops.plugin.api

/**
* 插件管理器
*/
interface PluginManager {

/**
* 加载所有插件
*/
fun load()

/**
* 加载插件
* @param id 插件id
*/
fun load(id: String)

/**
* 卸载插件
* @param id 插件id
*/
fun unload(id: String)

/**
* 查找扩展点列表
* @param clazz 扩展点类型
*/
fun <T : ExtensionPoint> findExtensionPoints(clazz: Class<T>): List<T>

/**
* 获取注册的插件列表
*/
fun getPluginMap(): Map<String, PluginInfo>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tencent.devops.plugin.api

/**
* 查找扩展点, kotlin风格扩展函数
*/
inline fun <reified T : ExtensionPoint> PluginManager.find(): List<T> {
return this.findExtensionPoints(T::class.java)
}

/**
* 查找扩展点并遍历执行扩展逻辑
*/
inline fun <reified T : ExtensionPoint> PluginManager.applyExtension(block: T.() -> Unit) {
this.findExtensionPoints(T::class.java).forEach {
block(it)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.tencent.devops.plugin.api

/**
* 插件metadata信息
*/
data class PluginMetadata(
/**
* 插件id,要求唯一
*/
val id: String,
/**
* 插件名称,要求唯一,先保持和id一致
*/
val name: String,
/**
* 插件版本,语义化版本格式
*/
val version: String,
/**
* 插件生效范围
*/
val scope: List<String>,
/**
* 插件作者
*/
val author: String? = null,
/**
* 插件描述
*/
val description: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.tencent.devops.plugin.api

import java.nio.file.Path

/**
* 插件扫描器
*/
interface PluginScanner {

/**
* 扫描插件路径
* @return 插件路径集合
*/
fun scan(): List<Path>

/**
* 扫描指定插件路径
* 此方法要求插件必须按照指定格式命名:plugin-xxx-1.0.0.jar,其中xxx代表插件id
* @param id 插件id
*/
fun scan(id: String): Path?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
description = "DevOps Boot Plugin Core"

dependencies {
api(project(":devops-boot-project:devops-boot-core:devops-plugin:plugin-api"))
api("org.springframework.boot:spring-boot-starter")
api("org.springframework:spring-webmvc")
compileOnly("org.springframework.boot:spring-boot-starter-actuator")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tencent.devops.plugin

import com.tencent.devops.plugin.api.ExtensionRegistry
import com.tencent.devops.plugin.api.PluginManager
import com.tencent.devops.plugin.api.PluginScanner
import com.tencent.devops.plugin.config.PluginProperties
import com.tencent.devops.plugin.core.DefaultPluginManager
import com.tencent.devops.plugin.core.DefaultPluginScanner
import com.tencent.devops.plugin.spring.SpringExtensionRegistry
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(PluginProperties::class)
class PluginAutoConfiguration {

@Bean
@ConditionalOnMissingBean(PluginScanner::class)
fun pluginScanner(pluginProperties: PluginProperties) = DefaultPluginScanner(pluginProperties)

@Bean
@ConditionalOnMissingBean(ExtensionRegistry::class)
fun extensionRegistry() = SpringExtensionRegistry()

@Bean
@ConditionalOnMissingBean(PluginManager::class)
fun pluginManager(
pluginScanner: PluginScanner,
extensionRegistry: ExtensionRegistry
): PluginManager {
return DefaultPluginManager(pluginScanner, extensionRegistry)
}
}
Loading