码迷,mamicode.com
首页 > 其他好文 > 详细

GitLab+jenkins+docker发布.md

时间:2019-07-22 20:18:29      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:back   art   bae   project   margin   middle   spl   tor   net   

@[TOC]

http://192.168.2.5:181/view/all/newJob 构建一个maven项目ht-micro-record-service-note-provider
添加jenkins主机公钥到gitlab,并生成全局凭据
1.Username with password root/123456
2.SSH Username with private key Enter Directly,添加gitlab服务器私钥

parent.relativePath修改为,发布单个服务时设定一个空值将始终从仓库中获取,不从本地路径获取

基础服务

<build>
    <finalName>ht-micro-record-commons-domain</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>exec</classifier>  <!--被依赖的包加该配置-->
                <mainClass>com.ht.micro.record.commons.CommonsMapperApplication</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

微服务提供者

<build>
    <finalName>ht-micro-record-service-note-consumer</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.ht.micro.record.service.consumer.NoteConsumerServiceApplication</mainClass>
            </configuration>
        </plugin>
        <!-- docker的maven插件,官网 https://github.com/spotify/docker-maven-plugin -->
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.13</version>
            <configuration>
                <imageName>192.168.2.5:5000/${project.artifactId}:${project.version}</imageName>
                <baseImage>jdk1.8</baseImage>
                <entryPoint>["java", "-jar","/${project.build.finalName}.jar"]</entryPoint>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
                <dockerHost>http://192.168.2.5:2375</dockerHost>
            </configuration>
        </plugin>
    </plugins>
</build>

Jenkins

export app_name="ht-micro-record-service-note-consumer"
export app_version="1.0.0-SNAPSHOT"
sh /usr/local/docker/ht-micro-record/deploy.sh

#!/bin/bash

DATE=`date +%F-%H-%M-%S`
last_app_name=`echo "$app_name-$app_version-$DATE"`
if docker ps | grep $app_name;then
  docker stop $app_name
  docker rename $app_name $last_app_name
  docker run -di --name=$app_name --net=host 192.168.2.5:5000/$app_name:$app_version

elif docker ps -a | grep $app_name;then
  docker start $app_name
else
  docker run -di --name=$app_name --net=host 192.168.2.5:5000/$app_name:$app_version
fi

vim /usr/local/bin/dokill

docker images | grep -e $*|awk ‘{print $3}‘|sed ‘2p‘|xargs docker rmi
chmod a+x /usr/local/bin/dokill
dokill tensquare_recruit

技术图片
enter description here

技术图片
技术图片
技术图片

Q1:Failed to execute goal on project : Could not resolve dependencies for

对最父级项目clean install,再最子项目clean install

Q2: repackage failed: Unable to find main class -> [Help 1]

构建显示缺少主类

public class CommonsApplication {
    public static void main(String[] args) {


    }
}

详情见:
https://github.com/OneJane/blog
https://www.jianshu.com/u/b2a63c970be4

GitLab+jenkins+docker发布.md

标签:back   art   bae   project   margin   middle   spl   tor   net   

原文地址:https://www.cnblogs.com/codewj/p/11227859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!