소스 검색

更新打包文件

lgy 4 년 전
부모
커밋
02a751b223
6개의 변경된 파일116개의 추가작업 그리고 0개의 파일을 삭제
  1. 14 0
      docker/Dockerfile
  2. 6 0
      docker/deploy.sh
  3. 4 0
      docker/entrypoint.sh
  4. 79 0
      docker/pipeline.txt
  5. 12 0
      docker/zkt-project-alarm.yml
  6. 1 0
      pom.xml

+ 14 - 0
docker/Dockerfile

@@ -0,0 +1,14 @@
+#FROM openjdk:8-jdk-alpine 文件下载会出现空指针错误
+FROM java:8
+ARG WORKER_HOME
+RUN apt-get install -y --no-install-recommends tzdata && rm -rf /var/lib/apt/lists/*
+RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime	&& echo 'Asia/Shanghai' > /etc/timezone
+RUN mkdir -p $WORKER_HOME/config
+COPY *.jar $WORKER_HOME/
+COPY entrypoint.sh $WORKER_HOME/
+COPY *.yml $WORKER_HOME/config/
+COPY *.properties $WORKER_HOME/config/
+#EXPOSE 9931
+WORKDIR $WORKER_HOME
+RUN ls
+ENTRYPOINT ["sh","./entrypoint.sh"]

+ 6 - 0
docker/deploy.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+docker stop zkt-project-alarm
+docker rm zkt-project-alarm
+docker rmi zkt-project-alarm
+docker-compose --env-file ./docker/.env -f ./docker/zkt-project-alarm.yml up -d
+docker logout labisenlin.persagy.com

+ 4 - 0
docker/entrypoint.sh

@@ -0,0 +1,4 @@
+#!/bin/bash
+echo "entrypoint run..."
+#注意此处目录为 pipeline 中定义的目录
+java -jar -Xms2048m -Xmx2048m -Dfile.encoding=utf-8 zkt-project-alarm.jar

+ 79 - 0
docker/pipeline.txt

@@ -0,0 +1,79 @@
+pipeline { //pipeline 顶层
+    //any 在任何可用的agent上执行Pipeline或stage
+    agent any
+    //environment 自定义的环境变量
+     environment {
+        	//本项目此三个变量值如下,修改jenkins打包即可,其余不动
+            //PROGRAM_ID=integrated-eureka
+            //APPLICATION_NAME=integrated-eureka
+            //PROJECT_JAR_PATH=integrated-eureka
+
+            PROGRAM_ID = "$PROGRAM_ID"     							//项目名称
+            APPLICATION_NAME = "$PROGRAM_ID"     				    //项目应用名-镜像名称
+            WORKSPACE = "/root/jenkins"    							//jenkins home 宿主机路径
+            PROJECT_JAR_PATH = "$PROJECT_JAR_PATH"					//项目打包后所在相对路径
+            PROJECT_ROOT_PATH = "zkt-alarm"							//项目根路径名称
+            CONTAINER_HOME = "$CONTAINER_HOME"   				    //容器内的基本路径
+            WORKER_HOME = "$CONTAINER_HOME/$APPLICATION_NAME"   	//项目运行所在路径-容器内的路径
+
+            DEPLOY_FILE_PATH = "docker"				//部署文件所在路径
+            MAVEN_PACKAGE_PATH = "$WORKSPACE/workspace/$PROGRAM_ID"		//maven打包根路径
+            IMAGE_REPOSITORY_PREFIX="labisenlin.persagy.com"
+            DOCKER_IMAGE = "$IMAGE_REPOSITORY_PREFIX/$IMAGE_REPOSITORY_PROJECT/$APPLICATION_NAME:$VERSION"	//镜像全路径
+            BACKUP_PATH = "$JENKINS_HOME/program-backup/$PROGRAM_ID/$VERSION"	//备份路径
+        }
+    //不允许并行执行Pipeline,可用于防止同时访问共享资源等
+    options {
+        disableConcurrentBuilds()
+    }
+    stages {
+        //部署流程一:从SVN或者Git上拉取项目程序代码
+        stage('git checkout') {
+            steps {
+                checkout([$class: 'GitSCM', branches: [[name: '*/$GIT_BRANCH']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'zkt-git-server', url: 'http://39.106.8.246:3003/persagy/persagy-zkt-project-alarm.git']]])
+            }
+        }
+        //部署流程二:Java程序进行maven打包
+        stage('maven build') {
+            steps {
+                sh 'cd $WORKSPACE'
+                sh 'mvn clean install -Dmaven.test.skip=true -f $MAVEN_PACKAGE_PATH/pom.xml'
+            }
+        }
+        //部署流程三:根据项目dockerfile创建项目的docker镜像
+        stage('image buid') {
+            steps {
+                sh 'chmod -R +x ./$DEPLOY_FILE_PATH/'
+                sh 'rm -rf ./$DEPLOY_FILE_PATH/*.jar && cp ./target/*.jar ./$DEPLOY_FILE_PATH'
+                sh 'docker build -f ./$DEPLOY_FILE_PATH/Dockerfile --build-arg WORKER_HOME=$WORKER_HOME -t $DOCKER_IMAGE ./$DEPLOY_FILE_PATH'
+            }
+        }
+        //部署流程四:项目推送到本地私有仓库
+        stage('repository push') {
+            steps {
+                //-H tcp://192.168.64.16:9999
+                sh 'docker login $IMAGE_REPOSITORY_PREFIX -u $DOCKER_USERNAME -p $DOCKER_PASSWORD'
+                sh 'docker push  $DOCKER_IMAGE'
+                //只打镜像的话,将其打开
+                sh 'docker logout $IMAGE_REPOSITORY_PREFIX'
+                sh 'docker rmi $DOCKER_IMAGE'
+            }
+        }
+        //部署流程五:项目版本本地备份
+        stage('backup') {
+            steps {
+                sh 'rm -rf $BACKUP_PATH/'
+                sh 'mkdir -p  $BACKUP_PATH/'
+                sh 'cp ./target/*.jar $BACKUP_PATH/'
+            }
+        }
+        //部署流程六:项目docker部署运行
+        stage('deploy') {
+            steps {
+                sh 'rm -rf /root/jenkins/workspace/zkt-project-alarm/docker/.env'
+                sh 'echo "tag = $VERSION" >> /root/jenkins/workspace/zkt-project-alarm/docker/.env'
+                sh 'ssh -tt root@192.168.64.16 "rm -rf /mnt/zkt/zkt-project-alarm/ && mkdir -p  /mnt/zkt/zkt-project-alarm/ && scp -r root@192.168.64.18:/root/jenkins/workspace/zkt-project-alarm/docker/ /mnt/zkt/zkt-project-alarm/docker/ && cd /mnt/zkt/zkt-project-alarm/ && sh ./docker/deploy.sh " '
+            }
+        }
+    }
+}

+ 12 - 0
docker/zkt-project-alarm.yml

@@ -0,0 +1,12 @@
+version: '3'
+services:
+  zkt-project-alarm:
+    image: labisenlin.persagy.com/integrated-public/zkt-alarm:${tag}
+    container_name: zkt-project-alarm
+    restart: always
+    ports:
+      # 服务暴露端口号,按环境调整,
+      - 9984:9984
+    volumes:
+      # zkt-project-alarm.yml 文件同级放config文件夹,文件夹下有 要包含application.yml文件
+      - ./config/:${WORKER_HOME}/config/

+ 1 - 0
pom.xml

@@ -145,6 +145,7 @@
    </dependencies>
 
    <build>
+       <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>