第 05章 开发前的准备(5.1)

技术选型

开发环境
   操作系统:Windows 10 Enterprise
   开发工具:Intellij IDEA
   数据库:MySQL 5.7.22
   Java SDK:Oracle JDK 1.8.152
部署环境
   操作系统:Linux Ubuntu Server 16.04 X64
   虚拟化技术:VMware + Docker
项目管理工具
   项目构建:Maven + Nexus
   代码管理:Git + GitLab
   镜像管理:Docker Registry
后台主要技术栈
   核心框架:Spring Boot + Spring Cloud
   视图框架:Spring MVC
   ORM 框架:tk.mybatis 简化 MyBatis 开发
   数据库连接池:Alibaba Druid
   数据库缓存:Redis Sentinel
   消息中间件:RabbitMQ
   接口文档引擎:Swagger2 RESTful 风格 API 文档生成
   全文检索引擎:ElasticSearch
   分布式链路追踪:ZipKin
   分布式文件系统:Alibaba FastDFS
   分布式服务监控:Spring Boot Admin
   分布式协调系统:Spring Cloud Eureka
   分布式配置中心:Spring Cloud Config
   分布式日志系统:ELK(ElasticSearch + Logstash + Kibana)
   反向代理负载均衡:Nginx
自动化运维
  持续集成:GitLab
  持续交付:Jenkins
  容器编排:Kubernetes

创建项目 cbj-dependencies
全局依赖
创建pom.xml



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.0.3.RELEASEversion>
    parent>

    <groupId>com.funtlgroupId>
    <artifactId>cbj-dependenciesartifactId>
    <version>1.0.0-SNAPSHOTversion>
    <packaging>pompackaging>


    <properties>
        
        <java.version>1.8java.version>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>

        
        <spring-cloud.version>Finchley.RELEASEspring-cloud.version>
        <spring-boot-admin.version>2.0.1spring-boot-admin.version>
        <zipkin.version>2.10.1zipkin.version>
        <spring-boot-alibaba-druid.version>1.1.10spring-boot-alibaba-druid.version>
        <spring-boot-mapper.version>2.0.2spring-boot-mapper.version>
        <spring-boot-pagehelper.version>1.2.5spring-boot-pagehelper.version>
        <nekohtml.version>1.9.22nekohtml.version>
        <lombok.version>1.16.18lombok.version>
        <guava.version>25.1-jreguava.version>
        <jackson.version>2.9.6jackson.version>

        
        <mysql.version>5.1.46 mysql.version>

    properties>

    <dependencyManagement>
        <dependencies>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>druid-spring-boot-starterartifactId>
                <version>${spring-boot-alibaba-druid.version}version>
            dependency>

            <dependency>
                <groupId>tk.mybatisgroupId>
                <artifactId>mapper-spring-boot-starterartifactId>
                <version>${spring-boot-mapper.version}version>
            dependency>
            <dependency>
                <groupId>com.github.pagehelpergroupId>
                <artifactId>pagehelper-spring-boot-starterartifactId>
                <version>${spring-boot-pagehelper.version}version>
            dependency>

            
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
            

            
            <dependency>
                <groupId>de.codecentricgroupId>
                <artifactId>spring-boot-admin-starter-serverartifactId>
                <version>${spring-boot-admin.version}version>
            dependency>
            <dependency>
                <groupId>de.codecentricgroupId>
                <artifactId>spring-boot-admin-starter-clientartifactId>
                <version>${spring-boot-admin.version}version>
            dependency>
            

            
            <dependency>
                <groupId>io.zipkin.javagroupId>
                <artifactId>zipkinartifactId>
                <version>${zipkin.version}version>
            dependency>
            <dependency>
                <groupId>io.zipkin.javagroupId>
                <artifactId>zipkin-serverartifactId>
                <version>${zipkin.version}version>
            dependency>
            <dependency>
                <groupId>io.zipkin.javagroupId>
                <artifactId>zipkin-autoconfigure-uiartifactId>
                <version>${zipkin.version}version>
            dependency>
            

            
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
                <version>${mysql.version}version>
                <scope>runtimescope>
            dependency>
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <version>${lombok.version}version>
            dependency>
            <dependency>
                <groupId>com.google.guavagroupId>
                <artifactId>guavaartifactId>
                <version>${guava.version}version>
            dependency>
            

            <dependency>
                <groupId>net.sourceforge.nekohtmlgroupId>
                <artifactId>nekohtmlartifactId>
                <version>${nekohtml.version}version>
            dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.coregroupId>
                <artifactId>jackson-databindartifactId>
                <version>${jackson.version}version>
            dependency>
        dependencies>
    dependencyManagement>

    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <showWarnings>trueshowWarnings>
                configuration>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-jar-pluginartifactId>
                <configuration>
                    <archive>
                        <addMavenDescriptor>falseaddMavenDescriptor>
                    archive>
                configuration>
                <executions>
                    <execution>
                        <configuration>
                            <archive>
                                <manifest>
                                    
                                    <addDefaultImplementationEntries>trueaddDefaultImplementationEntries>
                                    <addDefaultSpecificationEntries>trueaddDefaultSpecificationEntries>
                                    <addClasspath>trueaddClasspath>
                                manifest>
                            archive>
                        configuration>
                    execution>
                executions>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-resources-pluginartifactId>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-install-pluginartifactId>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-clean-pluginartifactId>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-antrun-pluginartifactId>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-dependency-pluginartifactId>
            plugin>
        plugins>

        <pluginManagement>
            <plugins>
                
                <plugin>
                    <groupId>org.apache.maven.pluginsgroupId>
                    <artifactId>maven-javadoc-pluginartifactId>
                    <executions>
                        <execution>
                            <phase>prepare-packagephase>
                            <goals>
                                <goal>jargoal>
                            goals>
                        execution>
                    executions>
                plugin>

                
                <plugin>
                    <groupId>net.alchim31.mavengroupId>
                    <artifactId>yuicompressor-maven-pluginartifactId>
                    <version>1.5.1version>
                    <executions>
                        <execution>
                            <phase>prepare-packagephase>
                            <goals>
                                <goal>compressgoal>
                            goals>
                        execution>
                    executions>
                    <configuration>
                        <encoding>UTF-8encoding>
                        <jswarn>falsejswarn>
                        <nosuffix>truenosuffix>
                        <linebreakpos>30000linebreakpos>
                        <force>trueforce>
                        <includes>
                            <include>**/*.jsinclude>
                            <include>**/*.cssinclude>
                        includes>
                        <excludes>
                            <exclude>**/*.min.jsexclude>
                            <exclude>**/*.min.cssexclude>
                        excludes>
                    configuration>
                plugin>
            plugins>
        pluginManagement>

        
        <resources>
            <resource>
                <directory>src/main/javadirectory>
                <excludes>
                    <exclude>**/*.javaexclude>
                excludes>
            resource>
            <resource>
                <directory>src/main/resourcesdirectory>
            resource>
        resources>
    build>

    <distributionManagement>
        <repository>
            <id>nexus-releasesid>
            <name>Nexus Release Repositoryname>
            <url>http://192.168.0.15:8081/repository/maven-releases/url>
        repository>
        <snapshotRepository>
            <id>nexus-snapshotsid>
            <name>Nexus Snapshot Repositoryname>
            <url>http://192.168.0.15:8081/repository/maven-snapshots/url>
        snapshotRepository>
    distributionManagement>

    <repositories>
        <repository>
            <id>nexusid>
            <name>Nexus Repositoryname>
            <url>http://192.168.0.15:8081/repository/maven-public/url>
            <snapshots>
                <enabled>trueenabled>
            snapshots>
            <releases>
                <enabled>trueenabled>
            releases>
        repository>

        <repository>
            <id>aliyun-reposid>
            <name>Aliyun Repositoryname>
            <url>http://maven.aliyun.com/nexus/content/groups/publicurl>
            <releases>
                <enabled>trueenabled>
            releases>
            <snapshots>
                <enabled>falseenabled>
            snapshots>
        repository>

        <repository>
            <id>sonatype-reposid>
            <name>Sonatype Repositoryname>
            <url>https://oss.sonatype.org/content/groups/publicurl>
            <releases>
                <enabled>trueenabled>
            releases>
            <snapshots>
                <enabled>falseenabled>
            snapshots>
        repository>
        <repository>
            <id>sonatype-repos-sid>
            <name>Sonatype Repositoryname>
            <url>https://oss.sonatype.org/content/repositories/snapshotsurl>
            <releases>
                <enabled>falseenabled>
            releases>
            <snapshots>
                <enabled>trueenabled>
            snapshots>
        repository>

        <repository>
            <id>spring-snapshotsid>
            <name>Spring Snapshotsname>
            <url>https://repo.spring.io/snapshoturl>
            <snapshots>
                <enabled>trueenabled>
            snapshots>
        repository>
        <repository>
            <id>spring-milestonesid>
            <name>Spring Milestonesname>
            <url>https://repo.spring.io/milestoneurl>
            <snapshots>
                <enabled>falseenabled>
            snapshots>
        repository>
    repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>nexusid>
            <name>Nexus Plugin Repositoryname>
            <url>http://192.168.0.15:8081/repository/maven-public/url>
            <snapshots>
                <enabled>trueenabled>
            snapshots>
            <releases>
                <enabled>trueenabled>
            releases>
        pluginRepository>

        <pluginRepository>
            <id>aliyun-reposid>
            <name>Aliyun Repositoryname>
            <url>http://maven.aliyun.com/nexus/content/groups/publicurl>
            <releases>
                <enabled>trueenabled>
            releases>
            <snapshots>
                <enabled>falseenabled>
            snapshots>
        pluginRepository>
    pluginRepositories>
project>

然后创建Docker文件夹
在Docker文件夹下创建文件 Dockerfile

`FROM openjdk:8-jre

MAINTAINER yuyingliang <[email protected]>`

RUN mkdir /app
`

创建.gitlab-ci.yml文件

#步骤
stages:
  - build
  - push

#构建
build:
  stage: build
  script:
    - /usr/local/maven/apache-maven-3.5.3/bin/mvn clean package
    - cd docker
    - docker build -t 192.168.0.39:5000/cbj-dependencies .


#推送
push:
  stage: push
  script:
    - docker push  192.168.0.39:5000/cbj-dependencies

你可能感兴趣的:(微服务架构)