diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000000000000000000000000000000..185a8f30114de8ce43b23954d8d6632c5ab039d2 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,108 @@ +pipeline { + agent any + environment { + def ENV = 'dev' + //def MODULE = "dmqk-cloud-${ITEM}-service" + def DOCKERFILE_PATH = '/data/dockerfile' + def REGISTRY_GIT_URL = 'gebangfeng' + def TKE_REGISTRY_GIT_URL = 'gebangfeng' + def buildName = "#${BUILD_NUMBER} 环境: ${ENV} 分支:${BRANCH} 项目名:${ITEMS}" + _time = sh(script: "echo `date '+%Y%m%d%H%M%S'`", returnStdout: true).trim() + def APP_VERSION = "${VERSION}-${_time}" + def K8S_NAMESPACE = 'gebangfeng-test' + def BRANCH = 'develop' + } + stages { + stage('mvn Build') { + when { + expression { + currentBuild.result == null || currentBuild.result == 'SUCCESS' + } + } + steps { + dir("${WORKSPACE}/springboot-web-demo") { + //load nvm + // Run Maven on a Unix agent. + sh ''' + JAVA_HOME=/usr/local/java-11-openjdk-11.0.15.0.9-2.el7_9.x86_64 + MAVEN_HOME=/usr/local/apache-maven-3.8.5 + MAVEN_OPTS="-Xmx1g" + PATH=$PATH:$JAVA_HOME/bin + PATH=$PATH:$MAVEN_HOME/bin + CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar + ulimit -n 65535 + mvn -v + mvn clean package -Dmaven.test.skip=true + ''' + + } + } + } + + stage('进入构建阶段') { + steps { + script { + for (ITEM in ITEMS.tokenize(',')) { + env.APP_NAME = "${ITEM}" + stage("${ITEM} Docker Image Build") { + dir("${WORKSPACE}/${ITEM}") { + sh '''docker build -t $REGISTRY_GIT_URL/$APP_NAME:$APP_VERSION . + ''' + } + } + stage("${ITEM} Push Image") { + sh '''docker login + docker push $REGISTRY_GIT_URL/$APP_NAME:$APP_VERSION + docker rmi $REGISTRY_GIT_URL/$APP_NAME:$APP_VERSION''' + } + stage("${ITEM} update deployment images") { + sh ''' + DEPLOYMENT_TPL='k8s-deployment.tpl' + APP_PORT='8080' + IMAGE_TAG="${APP_VERSION}" + sed -e "s#{JOB_ANME}#${JOB_NAME}#g;s#{BUILD_NUMBER}#${BUILD_NUMBER}#g;;s#{IMAGE_URL}#${TKE_REGISTRY_GIT_URL}/${APP_NAME}#g;s#{IMAGE_TAG}#${IMAGE_TAG}#g;s#{APP_NAME}#${APP_NAME}#g;s#{SPRING_PROFILE}#${ENV}#g;s#{APP_PORT}#${APP_PORT}#g;s#{NAMESPACE}#${K8S_NAMESPACE}#g" ${DEPLOYMENT_TPL} > k8s-deployment-${APP_NAME}.yml + kubectl config use-context cls-8adaiswp-100021034644-context-default + kubectl apply -f k8s-deployment-${APP_NAME}.yml --namespace=${K8S_NAMESPACE} + ''' + sh 'echo update' + } + stage("${ITEM} update k8s service") { + sh ''' + APP_PORT='8080' + sed -e "s#{APP_NAME}#${APP_NAME}#g;s#{APP_PORT}#${APP_PORT}#g;s#{NAMESPACE}#${K8S_NAMESPACE}#g" k8s-service.tpl > k8s-service-${APP_NAME}.yaml + kubectl config use-context cls-8adaiswp-100021034644-context-default + kubectl apply -f k8s-service-${APP_NAME}.yaml --namespace=${K8S_NAMESPACE} + + ''' + sh 'echo svc update' + } + } + } + } + } + + stage('update buildName') { + when { + expression { + currentBuild.result == null || currentBuild.result == 'SUCCESS' + } + } + steps { + sh "echo $ENV" + buildName "#${BUILD_NUMBER} 环境: ${ENV} 分支:${BRANCH} 项目名:${ITEMS} tag: ${APP_VERSION}" + } + } + } + post{ + success{ + sh ''' + /usr/local/scripts/jenkins-check.sh ${JOB_NAME} ${ITEMS} ${K8S_NAMESPACE} '0' ${BUILD_NUMBER} ${BUILD_USER_ID} ${BUILD_URL} "${COMMENT}" + ''' + } + failure{ + sh ''' + /usr/local/scripts/jenkins-check.sh ${JOB_NAME} ${ITEMS} ${K8S_NAMESPACE} '1' ${BUILD_NUMBER} ${BUILD_USER_ID} ${BUILD_URL} "${COMMENT}" + ''' + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..61faa3f8400e4ed1e14b6c5eaa1b7ae11bc21efd --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# ec-service-deployment + +ec-service部署集成 \ No newline at end of file diff --git a/k8s-deployment.tpl b/k8s-deployment.tpl new file mode 100644 index 0000000000000000000000000000000000000000..9a10f7e4a626bc99dedceee2ddae4df787f10d7f --- /dev/null +++ b/k8s-deployment.tpl @@ -0,0 +1,75 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + deployment.kubernetes.io/revision: "5" + description: {APP_NAME} + generation: 5 + labels: + k8s-app: {APP_NAME} + qcloud-app: {APP_NAME} + jenkins-job: {JOB_ANME} + jenkins-build-id: "{BUILD_NUMBER}" + name: {APP_NAME} + namespace: {NAMESPACE} +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 10 + selector: + matchLabels: + k8s-app: {APP_NAME} + qcloud-app: {APP_NAME} + jenkins-job: {JOB_ANME} + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + type: RollingUpdate + template: + metadata: + annotations: + eks.tke.cloud.tencent.com/root-cbs-size: "20" + eks.tke.cloud.tencent.com/security-group-id: sg-00pu6lkj + creationTimestamp: null + labels: + k8s-app: {APP_NAME} + qcloud-app: {APP_NAME} + jenkins-job: {JOB_ANME} + jenkins-build-id: "{BUILD_NUMBER}" + spec: + affinity: {} + containers: + - env: + - name: TZ + value: Asia/Shanghai + image: {IMAGE_URL}:{IMAGE_TAG} + imagePullPolicy: Always + livenessProbe: + failureThreshold: 3 + initialDelaySeconds: 300 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: {APP_PORT} + timeoutSeconds: 1 + name: {APP_NAME} + readinessProbe: + failureThreshold: 3 + initialDelaySeconds: 100 + periodSeconds: 10 + successThreshold: 1 + tcpSocket: + port: {APP_PORT} + timeoutSeconds: 1 + resources: + limits: + cpu: 500m + memory: 1024Mi + requests: + cpu: 250m + memory: 256Mi + dnsPolicy: ClusterFirst + imagePullSecrets: + - name: qcloudregistrykey + restartPolicy: Always diff --git a/k8s-service.tpl b/k8s-service.tpl new file mode 100644 index 0000000000000000000000000000000000000000..4437ace5461a0975a4580714ce8b9673a2c9c167 --- /dev/null +++ b/k8s-service.tpl @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + k8s-app: {APP_NAME} + qcloud-app: {APP_NAME} + name: {APP_NAME} + namespace: {NAMESPACE} +spec: + ports: + - name: {APP_NAME} + port: {APP_PORT} + protocol: TCP + targetPort: {APP_PORT} + selector: + k8s-app: {APP_NAME} + qcloud-app: {APP_NAME} + sessionAffinity: None + type: ClusterIP diff --git a/springboot-web-demo/Dockerfile b/springboot-web-demo/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..411e166552f5682227579b0dc829bf771e65be85 --- /dev/null +++ b/springboot-web-demo/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:8-jre-alpine +RUN touch /8.txt +COPY target/springboot-web-demo-1.0-SNAPSHOT.jar /springboot-web-demo.jar + +ENTRYPOINT ["java","-jar","springboot-web-demo.jar"] diff --git a/springboot-web-demo/pom.xml b/springboot-web-demo/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..984be3ebb30213e84b9db3f4fcce8c7d53adb57f --- /dev/null +++ b/springboot-web-demo/pom.xml @@ -0,0 +1,35 @@ + + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + com.mooc + springboot-web-demo + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/springboot-web-demo/src/main/java/com/mooc/demo/ServiceApplication.java b/springboot-web-demo/src/main/java/com/mooc/demo/ServiceApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..60fad2202fd513d07ada1d6213f244b5d9fab770 --- /dev/null +++ b/springboot-web-demo/src/main/java/com/mooc/demo/ServiceApplication.java @@ -0,0 +1,17 @@ +package com.mooc.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Created by Michael on 2018/9/29. + */ +@SpringBootApplication +public class ServiceApplication { + + public static void main(String args[]) { + + SpringApplication.run(ServiceApplication.class, args); + + } +} diff --git a/springboot-web-demo/src/main/java/com/mooc/demo/controller/DemoController.java b/springboot-web-demo/src/main/java/com/mooc/demo/controller/DemoController.java new file mode 100644 index 0000000000000000000000000000000000000000..065c4c354a1f158020388592428560004cc0c986 --- /dev/null +++ b/springboot-web-demo/src/main/java/com/mooc/demo/controller/DemoController.java @@ -0,0 +1,20 @@ +package com.mooc.demo.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * Created by Michael on 2018/9/29. + */ + +@RestController +public class DemoController { + + @RequestMapping("/hello") + public String sayHello(@RequestParam String name) { + + return "Hello "+name+"! I'm springboot-web-demo controller!"; + + } +} diff --git a/springboot-web-demo/src/main/resources/applications.properties b/springboot-web-demo/src/main/resources/applications.properties new file mode 100644 index 0000000000000000000000000000000000000000..a462b0c12782eb7fb88ee16e4062a204111cf41f --- /dev/null +++ b/springboot-web-demo/src/main/resources/applications.properties @@ -0,0 +1,2 @@ +server.name=springboot-web-demo +server.port=8080 \ No newline at end of file diff --git a/springboot-web-demo/target/classes/applications.properties b/springboot-web-demo/target/classes/applications.properties new file mode 100644 index 0000000000000000000000000000000000000000..a462b0c12782eb7fb88ee16e4062a204111cf41f --- /dev/null +++ b/springboot-web-demo/target/classes/applications.properties @@ -0,0 +1,2 @@ +server.name=springboot-web-demo +server.port=8080 \ No newline at end of file diff --git a/springboot-web-demo/target/classes/com/mooc/demo/ServiceApplication.class b/springboot-web-demo/target/classes/com/mooc/demo/ServiceApplication.class new file mode 100644 index 0000000000000000000000000000000000000000..06a167a4c85ab4f94b19a4619522022048efeea8 Binary files /dev/null and b/springboot-web-demo/target/classes/com/mooc/demo/ServiceApplication.class differ diff --git a/springboot-web-demo/target/classes/com/mooc/demo/controller/DemoController.class b/springboot-web-demo/target/classes/com/mooc/demo/controller/DemoController.class new file mode 100644 index 0000000000000000000000000000000000000000..d78bb6960a96a9ac1480ce0e85972883aeecc8ad Binary files /dev/null and b/springboot-web-demo/target/classes/com/mooc/demo/controller/DemoController.class differ diff --git a/springboot-web-demo/target/maven-archiver/pom.properties b/springboot-web-demo/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..ba797904cc5d72ebb63474c33d9277865a99c87c --- /dev/null +++ b/springboot-web-demo/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.5 +groupId=com.mooc +artifactId=springboot-web-demo +version=1.0-SNAPSHOT diff --git a/springboot-web-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/springboot-web-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..2279cd42ae2977afa5794d3c903dc772f6d3d73e --- /dev/null +++ b/springboot-web-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com/mooc/demo/controller/DemoController.class +com/mooc/demo/ServiceApplication.class diff --git a/springboot-web-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/springboot-web-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..74d40731a1dad7ef195f70aee06b1667db052e40 --- /dev/null +++ b/springboot-web-demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +/root/mooc-k8s-demo/springboot-web-demo/src/main/java/com/mooc/demo/controller/DemoController.java +/root/mooc-k8s-demo/springboot-web-demo/src/main/java/com/mooc/demo/ServiceApplication.java diff --git a/springboot-web-demo/target/springboot-web-demo-1.0-SNAPSHOT.jar b/springboot-web-demo/target/springboot-web-demo-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..c73ec46c81b6564f48ec39a680a509899a0eb50c Binary files /dev/null and b/springboot-web-demo/target/springboot-web-demo-1.0-SNAPSHOT.jar differ diff --git a/springboot-web-demo/target/springboot-web-demo-1.0-SNAPSHOT.jar.original b/springboot-web-demo/target/springboot-web-demo-1.0-SNAPSHOT.jar.original new file mode 100644 index 0000000000000000000000000000000000000000..c0f0c920ad433a2af8028110174abc71edb4ad41 Binary files /dev/null and b/springboot-web-demo/target/springboot-web-demo-1.0-SNAPSHOT.jar.original differ diff --git a/springboot-web-demo1/Dockerfile b/springboot-web-demo1/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..d3586e885e4c60b241a6b27e0925afc81334372a --- /dev/null +++ b/springboot-web-demo1/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:8-jre-alpine +RUN touch /8.txt +COPY target/springboot-web-demo-1.0-SNAPSHOT.jar /springboot-web-demo.jar + +ENTRYPOINT ["java","-jar","springboot-web-demo.jar1"] diff --git a/springboot-web-demo1/pom.xml b/springboot-web-demo1/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..984be3ebb30213e84b9db3f4fcce8c7d53adb57f --- /dev/null +++ b/springboot-web-demo1/pom.xml @@ -0,0 +1,35 @@ + + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + com.mooc + springboot-web-demo + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/springboot-web-demo1/src/main/java/com/mooc/demo/ServiceApplication.java b/springboot-web-demo1/src/main/java/com/mooc/demo/ServiceApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..60fad2202fd513d07ada1d6213f244b5d9fab770 --- /dev/null +++ b/springboot-web-demo1/src/main/java/com/mooc/demo/ServiceApplication.java @@ -0,0 +1,17 @@ +package com.mooc.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Created by Michael on 2018/9/29. + */ +@SpringBootApplication +public class ServiceApplication { + + public static void main(String args[]) { + + SpringApplication.run(ServiceApplication.class, args); + + } +} diff --git a/springboot-web-demo1/src/main/java/com/mooc/demo/controller/DemoController.java b/springboot-web-demo1/src/main/java/com/mooc/demo/controller/DemoController.java new file mode 100644 index 0000000000000000000000000000000000000000..065c4c354a1f158020388592428560004cc0c986 --- /dev/null +++ b/springboot-web-demo1/src/main/java/com/mooc/demo/controller/DemoController.java @@ -0,0 +1,20 @@ +package com.mooc.demo.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * Created by Michael on 2018/9/29. + */ + +@RestController +public class DemoController { + + @RequestMapping("/hello") + public String sayHello(@RequestParam String name) { + + return "Hello "+name+"! I'm springboot-web-demo controller!"; + + } +} diff --git a/springboot-web-demo1/src/main/resources/applications.properties b/springboot-web-demo1/src/main/resources/applications.properties new file mode 100644 index 0000000000000000000000000000000000000000..a462b0c12782eb7fb88ee16e4062a204111cf41f --- /dev/null +++ b/springboot-web-demo1/src/main/resources/applications.properties @@ -0,0 +1,2 @@ +server.name=springboot-web-demo +server.port=8080 \ No newline at end of file diff --git a/springboot-web-demo1/target/classes/applications.properties b/springboot-web-demo1/target/classes/applications.properties new file mode 100644 index 0000000000000000000000000000000000000000..a462b0c12782eb7fb88ee16e4062a204111cf41f --- /dev/null +++ b/springboot-web-demo1/target/classes/applications.properties @@ -0,0 +1,2 @@ +server.name=springboot-web-demo +server.port=8080 \ No newline at end of file diff --git a/springboot-web-demo1/target/classes/com/mooc/demo/ServiceApplication.class b/springboot-web-demo1/target/classes/com/mooc/demo/ServiceApplication.class new file mode 100644 index 0000000000000000000000000000000000000000..06a167a4c85ab4f94b19a4619522022048efeea8 Binary files /dev/null and b/springboot-web-demo1/target/classes/com/mooc/demo/ServiceApplication.class differ diff --git a/springboot-web-demo1/target/classes/com/mooc/demo/controller/DemoController.class b/springboot-web-demo1/target/classes/com/mooc/demo/controller/DemoController.class new file mode 100644 index 0000000000000000000000000000000000000000..d78bb6960a96a9ac1480ce0e85972883aeecc8ad Binary files /dev/null and b/springboot-web-demo1/target/classes/com/mooc/demo/controller/DemoController.class differ diff --git a/springboot-web-demo1/target/maven-archiver/pom.properties b/springboot-web-demo1/target/maven-archiver/pom.properties new file mode 100644 index 0000000000000000000000000000000000000000..ba797904cc5d72ebb63474c33d9277865a99c87c --- /dev/null +++ b/springboot-web-demo1/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.8.5 +groupId=com.mooc +artifactId=springboot-web-demo +version=1.0-SNAPSHOT diff --git a/springboot-web-demo1/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/springboot-web-demo1/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..2279cd42ae2977afa5794d3c903dc772f6d3d73e --- /dev/null +++ b/springboot-web-demo1/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com/mooc/demo/controller/DemoController.class +com/mooc/demo/ServiceApplication.class diff --git a/springboot-web-demo1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/springboot-web-demo1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000000000000000000000000000000000000..74d40731a1dad7ef195f70aee06b1667db052e40 --- /dev/null +++ b/springboot-web-demo1/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +/root/mooc-k8s-demo/springboot-web-demo/src/main/java/com/mooc/demo/controller/DemoController.java +/root/mooc-k8s-demo/springboot-web-demo/src/main/java/com/mooc/demo/ServiceApplication.java diff --git a/springboot-web-demo1/target/springboot-web-demo-1.0-SNAPSHOT.jar b/springboot-web-demo1/target/springboot-web-demo-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..c73ec46c81b6564f48ec39a680a509899a0eb50c Binary files /dev/null and b/springboot-web-demo1/target/springboot-web-demo-1.0-SNAPSHOT.jar differ diff --git a/springboot-web-demo1/target/springboot-web-demo-1.0-SNAPSHOT.jar.original b/springboot-web-demo1/target/springboot-web-demo-1.0-SNAPSHOT.jar.original new file mode 100644 index 0000000000000000000000000000000000000000..c0f0c920ad433a2af8028110174abc71edb4ad41 Binary files /dev/null and b/springboot-web-demo1/target/springboot-web-demo-1.0-SNAPSHOT.jar.original differ diff --git a/test.txt b/test.txt new file mode 100644 index 0000000000000000000000000000000000000000..30d74d258442c7c65512eafab474568dd706c430 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +test \ No newline at end of file