本项目基于Mendmix cloud + GaussDB 搭建微服开发脚手架

举报
韦文满 发表于 2024/11/11 17:06:34 2024/11/11
【摘要】 基于Mendmix cloud + Spring cloud gateway + spring boot jpa + GaussDB 搭建微服开发脚手架,基于华为云CCE,OBS,SWR,CodeArts,实现代码持续集成,自动部署功能

项目背景

Mendmix-cloud定位是一站式云原生架构技术底座。Mendmix-cloud提供了数据库、缓存、消息中间件、分布式定时任务、安全框架、网关以及主流产商云服务快速集成能力。本项目基于Mendmix cloud + Spring cloud gateway + spring boot jpa + GaussDB 搭建微服开发脚手架,基于华为云CCE,OBS,SWR,CodeArts,实现代码持续集成,自动部署功能。

源码地址https://gitee.com/dromara/mendmix-cloud

开发过程

1. 创建工程,目录结构如下

  • mendmix-cloud-demo #pom 依赖管理
    –apis-server #服务api入口
    –eureka-server #eureka服务注册中心
    –gateway-server #网关服务
    –gaussdb-demo-server #使用gaussdb demo示例服务

2. maven依赖配置

  1. eureka-server pom.xml依赖配置
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>3.1.1</version>
        </dependency>
  1. gateway-server pom.xml依赖配置
        <dependency>
            <groupId>com.mendmix</groupId>
            <artifactId>mendmix-gateway</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-reactor-netty</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>3.1.1</version>
        </dependency>
  1. gaussdb-demo-server pom.xml 依赖核心配置

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>3.1.1</version>
        </dependency>
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Database access -->
        <!-- 引入lib目录下jar包 -->
        <dependency>
            <groupId>org.opengauss</groupId>
            <artifactId>opengauss-jdbc</artifactId>
            <version>5.0.0-htrunk3.csi.gaussdb_kernel.opengaussjdbc.r3</version>
            <scope>system</scope>
            <systemPath>${pom.basedir}/src/main/resources/lib/gsjdbc4.jar</systemPath>
        </dependency>
        <!-- plug配置允许引入lib目录下jar包 -->
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>

3. dockerfile编写

  1. eureka-server 模块
FROM openjdk:17-alpine
LABEL authors="wmwei"
RUN mkdir -p /opt
COPY target/eureka-server.jar /opt
WORKDIR /opt
EXPOSE 8761
ENTRYPOINT ["java", "-jar","eureka-server.jar"]
  1. gateway-server 模块
FROM openjdk:17-alpine
LABEL authors="wmwei"
RUN mkdir -p /opt
COPY target/gateway-server.jar /opt
WORKDIR /opt
EXPOSE 8080
ENTRYPOINT ["java", "-jar","gateway-server.jar"]
  1. gaussdb-demo-server 模块
FROM openjdk:17-alpine
LABEL authors="wmwei"
RUN mkdir -p /opt
COPY target/gaussdb-used-server.jar /opt
WORKDIR /opt
EXPOSE 8088
ENTRYPOINT ["java", "-jar","gaussdb-used-server.jar"]

4. kubernetes yaml编写

  1. eureka-server 模块
apiVersion: v1
kind: Service
metadata:
  name: eureka-server
spec:
  selector:
    app: eureka-server-pods
  ports:
    - protocol: TCP
      port: 8761
      targetPort: 8761

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: eureka-server
  labels:
    app: eureka-server-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: eureka-server-pods
  template:
    metadata:
      name: eureka-server
      labels:
        app: eureka-server-pods
    spec:
      containers:
        - name: eureka-server-container
          image: swr.cn-north-4.myhuaweicloud.com/wmwei/eureka-server:0.0.1
          env:
            - name: EK_SERVER
              value: "eureka-server:8761"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8761
              protocol: TCP
          resources:
            requests:
              memory: "256Mi"
              cpu: "250m"
            limits:
              memory: "256Mi"
              cpu: "250m"
      imagePullSecrets:
        - name: default-secret
      restartPolicy: Always
  1. gateway-server 模块
apiVersion: v1
kind: Service
metadata:
  name: gateway-server
spec:
  selector:
    app: gateway-server-pods
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30100
  type: NodePort

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gateway-server
  labels:
    app: gateway-server-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gateway-server-pods
  template:
    metadata:
      name: gateway-server
      labels:
        app: gateway-server-pods
    spec:
      containers:
        - name: gateway-server-container
          image: swr.cn-north-4.myhuaweicloud.com/wmwei/gateway-server:0.0.1
          env:
            - name: EK_SERVER
              value: "eureka-server:8761"
            - name: GAUSSDB-SERVER
              value: "gaussdb-used-server:8088"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              protocol: TCP
          resources:
            requests:
              memory: "256Mi"
              cpu: "250m"
            limits:
              memory: "256Mi"
              cpu: "250m"
      imagePullSecrets:
        - name: default-secret
      restartPolicy: Always
  1. gaussdb-demo-server 模块
apiVersion: v1
kind: Service
metadata:
  name: gaussdb-used-server
spec:
  selector:
    app: gaussdb-used-pods
  ports:
    - protocol: TCP
      port: 8088
      targetPort: 8088

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gaussdb-used
  labels:
    app: gaussdb-used-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gaussdb-used-pods
  template:
    metadata:
      name: gaussdb-used
      labels:
        app: gaussdb-used-pods
    spec:
      containers:
        - name: gaussdb-used-container
          image: swr.cn-north-4.myhuaweicloud.com/wmwei/gaussdb-used-server:0.0.1
          env:
            - name: EK_SERVER
              value: "eureka-server:8761"
            - name: DB_PASSWORD
              valueFrom:
                configMapKeyRef:
                  key: DB_PASSWORD
                  name: opengauss
            - name: DB_URL
              valueFrom:
                configMapKeyRef:
                  key: DB_URL
                  name: opengauss
            - name: DB_USERNAME
              valueFrom:
                configMapKeyRef:
                  key: DB_USERNAME
                  name: opengauss
            - name: DB_DRIVER
              valueFrom:
                configMapKeyRef:
                  key: DB_DRIVER
                  name: opengauss
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8088
              protocol: TCP
          resources:
            requests:
              memory: "256Mi"
              cpu: "250m"
            limits:
              memory: "256Mi"
              cpu: "250m"
      imagePullSecrets:
        - name: default-secret
      restartPolicy: Always

5. 部署代码

  1. CodeArts控制台–创建项目–代码托管–新建仓库
    图片上传失败,等后面更新
  2. CodeArt控制台–持续交付–编译构建–新建任务
  • 任务一:上传kubernetes yaml至OBS,通过预置插件“上传文件到OBS”
    图片上传失败,等后面更新
  • 任务二:构建项目并上传镜像至SWR仓库,通过预置插件“通过dockerfile制作镜像并推送至SWR仓库”
    图片上传失败,等后面更新
  1. CodeArt控制台–持续交付–部署–新建任务
  • 任务:部署镜像至ECC,通过kubernetes manifest插件,执行上传到OBS的kubernetes yaml文件
  1. 部署执行过程
  • 步骤一:执行构建任务一,上传kubernetes yaml至OBS
  • 步骤二:执行构建任务二,构建项目并上传镜像至SWR仓库
  • 步骤三:发布任务,部署镜像至ECC
  • 最后:通过gateway网关服务访问gaussdb demo提供api

开发总结

本文主要是结合Mendmix cloud开源框架和华为GaussDB数据库,搭建微服开发脚手架,整合华为云CCE,SWR,OBS,CodeArts实现微服务容器化部署,持续集成,自动构建,一键发布等功能。
demo地址https://gitee.com/wmwei/mendmix-cloud-demo
博客地址https://bbs.huaweicloud.cn/blogs/439256

产品名称 产品类型 数据库引擎版本 内核引擎版本 实例类型 部署形态 备注
云数据库 GaussDB 基础版 V2.0-8.* 505.1.* 集中式 1主2备 推荐

产品名称 集群类型 集群版本 集群规模 备注
云容器引擎 CCE CCE Standard 集群 V1.29 50 推荐

产品名称 CPU架构 实例类型 公共镜像 镜像版本 备注
弹性云服务器 鲲鹏计算 鲲鹏通用计算增强型 Huawei Cloud EulerOS Huawei Cloud EulerOS 2.0 标准版 64位 ARM版(10GiB) 推荐

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。