从一张图看Devops全流程
本帖最后由 adminlily 于 2020-1-22 09:02 编辑一、持续交付工具链全图
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2htejJ1a3Jpam0uanBlZw?x-oss-process=image/format,png
上图源自网络。上图很清晰地列出了CD几个阶段使用的工具。
CD的工具链很长,但并不是每个模块所有工具都那么流行;换言之,我们在每个模块用好一种工具就足够了。
Build
在SCM的模块中:Git系列用的比较多,如Gitlab;
在CI模块中:Jenkins显然是最流行的;
在Build模块中:Maven、docker用的较多;
Test在Testing模块中:Junit、Jmeter用的较多;
Deploy在配置管理模块中:前些年Puppet比较火,这两年Ansible用的比较多;、在Artifact管理中:Dockerhub是在线的,docker registry是离线的。Openshift的集成镜像仓库用的就是docker registry技术。Quay是CoreOS的镜像仓库工具,有在线也有离线的,相信后续会被整合到Openshift中。
Run在Cloud/IaaS/PaaS模块中:这两年PaaS的活跃程度超过IaaS,我接触比较多的是其中的Openshift。
在编排模块中:K8S目前是主流,无可争议。
在BI/Monitoring/Logging中:EFK之前用的比较多,但大家普遍看好普罗米修斯。
二、红帽的Devops全图
20200117213004819.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d3ZDA1MDE=,size_16,color_FFFFFF,t_70
上图是一个比较典型的Devops流程。包括产品立项、需求分析、应用设计、开发、测试、持续发布、生产运维、回顾阶段。
其中,Openshift可以涵盖中间5个阶段,CloudForms可以覆盖第七个阶段。只有第一个阶段目前红帽产品堆栈无法覆盖。
我们将整个流程进一步技术细节化:
2020011721294721.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d3ZDA1MDE=,size_16,color_FFFFFF,t_70
Eclipse IDE工具红帽官网可以下载;Gitlab、Nexus、Jenkins、Openscap、EFK这些工具,红帽官网提供安加固过的容器镜像。
而整个流程串起来,可以通过Jenkins和S2I一起完成的。关于这方面,主要有两种方式:在源码外构建pipeline部署、在源码中构建pipeline部署。
三、在源码外构建pipeline部署应用--流程说明
在源码外构建pipeline的方式,是jenkins的pipeline调用Openshift的S2I、BC、DC等。代码构建是在Openshift中完成;
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2tldG11cTkzbXYuanBlZw?x-oss-process=image/format,png
本实验是根据EAP的基础镜像,构建一个基于Maven编译的应用,编译成功后,生成应用镜像,并在OCP中部署这个应用。
在在本实验中,应用代码地址库链接、应用名称的变量,通过OCP的应用模板导入;bc和dc的操作,均由ocp完成。在bc阶段,项目中会有build pod,
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3UzajI0Z3F3Z3cucG5n?x-oss-process=image/format,png
在dc阶段,项目中会有deploy pod。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3BqZHIxNXhmNXkucG5n?x-oss-process=image/format,png
为了能够通过pipeline显示阶段,在OCP中引入jenkins plugin,jenkins plugin的脚本定义了build和deploy两个阶段。而两个阶段的任务执行,分别是调用bc和dc。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1LzZncmpuc3A4Z2cucG5n?x-oss-process=image/format,png
因此,整个代码构建和部署,实际上均由OCP完成。Jenkins只是用来显示执行阶段。也可以根据需要,增加审批流。
两个yaml文件
创建两个yaml文件,一个是openshift-tasks-no-trigger.yaml,一个是pipeline-bc.yaml。
第一个文件创建jkp-tasks引用的bc、dc、routes、rc等资源。
第二个文件创建一个pipeline,定义应用的build和deploy阶段。
第一个文件:
apiVersion: v1kind: Templatelabels:template: openshift-tasks-no-trigger
模板名称metadata:name: openshift-tasks-no-triggerobjects:- apiVersion: v1kind: ImageStreammetadata:labels:application: ${APPLICATION_NAME}name: ${APPLICATION_NAME}
创建的应用image stream名称- apiVersion: v1kind: Servicemetadata:annotations:description: The web server's http port.labels:application: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:ports:- port: 8080targetPort: 8080selector:deploymentConfig: ${APPLICATION_NAME}- apiVersion: v1id: ${APPLICATION_NAME}-httpkind: Routemetadata:annotations:description: Route for application's http service.labels:application: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:to:name: ${APPLICATION_NAME}- apiVersion: v1kind: BuildConfigmetadata:labels:application: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:output:to:kind: ImageStreamTagname: ${APPLICATION_NAME}:latest将build成功的镜像打成latest的image stream tag。source:git:ref: ${SOURCE_REF}uri: ${SOURCE_URL}type: Gitstrategy:sourceStrategy:forcePull: truefrom:kind: ImageStreamTagname: jboss-eap70-openshift:1.4namespace: openshift
构建应用的基础镜像type: Sourcetriggers:- github:secret: kJZLvfQr3hZgtype: GitHub- generic:secret: kJZLvfQr3hZgtype: Generic- imageChange: {}type: ImageChange- type: ConfigChange- apiVersion: v1kind: DeploymentConfigmetadata:labels:application: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:replicas: 1selector:deploymentConfig: ${APPLICATION_NAME}strategy:resources: {}rollingParams:intervalSeconds: 1maxSurge: 25%maxUnavailable: 25%timeoutSeconds: 600updatePeriodSeconds: 1type: Rollingtemplate:metadata:labels:application: ${APPLICATION_NAME}deploymentConfig: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:containers:- env:- name: MY_POD_IPvalueFrom:fieldRef:apiVersion: v1fieldPath: status.podIP- name: OPENSHIFT_KUBE_PING_LABELSvalue: application=${APPLICATION_NAME}- name: OPENSHIFT_KUBE_PING_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespace- name: HORNETQ_CLUSTER_PASSWORDvalue: kJZLvfQr3hZg- name: JGROUPS_CLUSTER_PASSWORDvalue: kJZLvfQr3hZgimage: ${APPLICATION_NAME}imagePullPolicy: AlwayslivenessProbe:failureThreshold: 3httpGet:path: /ws/demo/healthcheckport: 8080scheme: HTTPinitialDelaySeconds: 45periodSeconds: 45successThreshold: 1timeoutSeconds: 1name: ${APPLICATION_NAME}ports:- containerPort: 8778name: jolokiaprotocol: TCP- containerPort: 8080name: httpprotocol: TCP- containerPort: 8888name: pingprotocol: TCPreadinessProbe:failureThreshold: 3httpGet:path: /ws/demo/healthcheckport: 8080scheme: HTTPinitialDelaySeconds: 20periodSeconds: 5successThreshold: 1timeoutSeconds: 1terminationGracePeriodSeconds: 60triggers:- type: ConfigChangeparameters:- description: The name for the application.name: APPLICATION_NAMErequired: truevalue: tasks
提示输入应用名称- description: Git source URI for applicationname: SOURCE_URLrequired: truevalue: lbroudoux/openshift-tasks
提示输入源码地- description: Git branch/tag referencename: SOURCE_REFvalue: master
提示输入源码 branch地址
第二个文件
apiVersion: v1kind: BuildConfigmetadata:annotations:pipeline.alpha.openshift.io/uses: '[{"name": "jkp-tasks", "namespace": "", "kind": "DeploymentConfig"}]'labels:name: jkp-tasks-pipelinename: jkp-tasks-pipelinespec:strategy:jenkinsPipelineStrategy:jenkinsfile: |-node('maven') {stage 'build'openshiftBuild(buildConfig: 'jkp-tasks', showBuildLogs: 'true')定义构建阶段,构建阶段是触发应用的buildConfigstage 'deploy'openshiftDeploy(deploymentConfig: 'jkp-tasks')定义构建阶段,构建阶段是触发应用的deploymentConfig}type: JenkinsPipelinetriggers:- github:secret: CzgPZAZ5m2type: GitHub- generic:secret: CzgPZAZ5m2type: Generic
实验验证
根据yaml文件创建应用模板:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2JtcHZjbTEzNHYuanBlZw?x-oss-process=image/format,pngaHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3lxaGJ3MndlZnkuanBlZw?x-oss-process=image/format,png
模板执行成功以后,应用的bc、dc、rc、vip、routes、is等资源就已经创建好了:
# oc get allNAME TYPE FROM LATESTbuildconfigs/jkp-tasks Source Git@master 1NAME TYPE FROM STATUS STARTED DURATIONbuilds/jkp-tasks-1 Source Git@bd32abb Running 2 minutes agoNAME DOCKER REPO TAGS UPDATEDimagestreams/jkp-tasks docker-registry.default.svc:5000/ocp-tasks/jkp-tasksNAME REVISION DESIRED CURRENT TRIGGERED BYdeploymentconfigs/jkp-tasks 1 1 1 configNAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARDroutes/jkp-tasks jkp-tasks-ocp-tasks.apps.example.com jkp-tasks <all> NoneNAME READY STATUS RESTARTS AGEpo/jkp-tasks-1-build 1/1 Running 0 2mpo/jkp-tasks-1-deploy 1/1 Running 0 2mpo/jkp-tasks-1-kj8ds 0/1 ImagePullBackOff 0 2mNAME DESIRED CURRENT READY AGErc/jkp-tasks-1 1 1 0 2mNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEsvc/jkp-tasks 172.30.58.78 <none> 8080/TCP 2m
接下来,创建jenkins pipeline:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3ZldXBna3BiMzAuanBlZw?x-oss-process=image/format,png
pipeline创建成功以后,触发pipeline执行:aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2xyZG03eGw2eGwucG5n?x-oss-process=image/format,pngPipeline已经启动:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2hxYmltYnF0eXcucG5n?x-oss-process=image/format,png
此时会生成bc pod。查看build pod的log,build pod会先拉build image的镜像,再拉代码,然后进行build,成功以后push到OCP的内部镜像仓库。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L21yb3NhMm1uZ2MucG5n?x-oss-process=image/format,pngaHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3NiMmNpcml4N20ucG5n?x-oss-process=image/format,png
pom和jar包下完完毕以后后,开始build:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1Lzl3ZHBndXpkM2cucG5n?x-oss-process=image/format,png
然后将成功的war包拷贝到EAP的部署目录中:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2sxcXZtN2VmdXMuanBlZw?x-oss-process=image/format,png
最后将build成功的应用镜像推送到集成镜像库:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3Z3bTdtbmxqZ2IucG5n?x-oss-process=image/format,png
至此,build阶段完成。
接下来,启动deploy过程:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2lhMnRvMWF2dzcucG5n?x-oss-process=image/format,png
查看jenkins的日志,deploy的阶段,就是触发dc,很快,dc执行完毕,应用部署成功。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3R3MTViMjBhYXAucG5n?x-oss-process=image/format,pngaHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2k4M2txc2k3M2gucG5n?x-oss-process=image/format,png
查看maven的日志,maven pod在此流程中,并不做编译工作,只是监听(该pod是为了pipeline的执行为存在):
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2QzOGxta3ZqZG8uanBlZw?x-oss-process=image/format,png
应用部署成功以后,查看routes:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1LzdhbGlhdjlhMWUucG5n?x-oss-process=image/format,png
通过浏览器,可以访问部署好的镜像:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3BhdzNmMW8wZGMuanBlZw?x-oss-process=image/format,png
方法总结
此种武器主要利用OCP的S2I进行构建,只是通过Jenkins进行阶段显示。Jenkins的build调用OCP应用的bc、deploy调用的OCP应用的dc。当然,我们也可以根据需要增加审批流程,或者将pipeline做得更复杂。
此这种方法的好处在于配置灵活。支持多用开发语言(在base image中增加不通的编译器即可)。通常情况下,红帽Openshift的CI/CD会推荐使用这种方式。
但是对于在很早以前就已经使用Jenkins做CI/CD的客户,可能会有一些学习成本。
四、在源码内构建pipeline
实验中,我们部署的是一个基于JBoss EAP base image的应用,应用代码位于git代码库。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2tjdjFiaGI1c2QuanBlZw?x-oss-process=image/format,png
在上图中,jenkins贯穿整个CI/CD,其中包括:
获取源码----->编译----->生成应用(war包)---->拉取base image---->将应用(war包)与base image合并---->生成App Image---->部署App image。
在本实验中,涉及两个重要的配置文件:openshift-tasks-jenkinsfile和Jenkinsfile。
openshift-tasks-jenkinsfile是创建Jenkins master(执行openshift-tasks-jenkinsfile的模板时,如果项目中没有jenkins的master,会自动触发部署)。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2VzMWdnbjdpYjcucG5n?x-oss-process=image/format,png
而部署openshift-tasks-jenkins file模板的时候,会提示输APPLICATION_NAME、DEV_PROJECT、SOURCE_URL、SOURCE_REF这几个变量,这些变量会被注入到模板中的BuildConfig部分,并进行覆盖。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1LzR4N2J6OGIybmcucG5n?x-oss-process=image/format,png
openshift-tasks-jenkinsfile的BuildConfig部分定义了Jenkins file的地址。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3gxem0zejZnYWYucG5n?x-oss-process=image/format,png
openshift-tasks-jenkinsfile带着这几个参数,继续触发Jenkin file并注入参数。Jenkins file第一行注明了调用maven,因此会触发部署jenkins maven slave pod。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L21kdDBjdTY5MG8ucG5n?x-oss-process=image/format,png
接下来,在jenkins slave pod中,根据Jenkins file定义的应用的'build'、test、deployInDev三个阶段进行执行,应用的bc和dc也在Jenkins File中生成,最终完成一应用的构建。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L20zd2ttYjZubmoucG5n?x-oss-process=image/format,png
接下来,我们先看:openshift-tasks-jenkinsfile完整的文件内容:
apiVersion: v1kind: Templatelabels:template: openshift-tasks-jenkinsfilemetadata:name: openshift-tasks-jenkinsfile
模板的名称
objects:- apiVersion: v1kind: BuildConfigBC阶段的定义metadata:annotations:pipeline.alpha.openshift.io/uses: '[{"name": "jkf-tasks", "namespace": "", "kind": "DeploymentConfig"}]'labels:application: ${APPLICATION_NAME}-jenkinsfilename: ${APPLICATION_NAME}-jenkinsfilespec:source:git:ref: ${SOURCE_REF}uri: ${SOURCE_URL}type: Gitstrategy:jenkinsPipelineStrategy:jenkinsfilePath: Jenkinsfiletype: JenkinsPipelinetype: Generic截至到目前,Jenkinsfile的bc定义完成。jenkinsPipelineStrategy和 jenkinsfilePath指定了这个bc阶段会调用的jenkins file的路径。triggers:- github:secret: kJZLvfQr3hZgtype: GitHub- generic:secret: kJZLvfQr3hZgtype: Genericparameters:- description: The name for the application.name: APPLICATION_NAMErequired: truevalue: jkf-tasks通过模板部署应用的时候,提示输入应用的名称,默认名称是jkf-tasks- description: The name of Dev projectname: DEV_PROJECTrequired: truevalue: ocp-tasks通过模板部署应用的时候,提示输入Dev project的名称,默认名称是ocp-tasks- description: Git source URI for applicationname: SOURCE_URLrequired: truevalue: lbroudoux/openshift-tasks通过模板部署应用的时候,提示输入SOURCE_URL的名称,默认名称是lbroudoux/openshift-tasks- description: Git branch/tag referencename: SOURCE_REFvalue: master 通过模板部署应用的时候,提示输入SOURCE_REF的名称,默认名称是master。接来下,查看Jenkins file完整的文件内容:node('maven') {代码构建调用maven// define commandsdef mvnCmd = "mvn"// injection of environment variables is not done so set them here...在此阶段注入参数变量对以下默认参数数值进行覆盖(从openshift-tasks-jenkinsfile template部署的时候,输入的参数变量带过来):def sourceRef = "master"def sourceUrl = "lbroudoux/openshift-tasks"def devProject = "ocp-tasks"def applicationName = "jkf-tasks"以上代码定义了编译方式,使用maven、定义了源码的地址、在Openshift上的项目(构建在哪发生)、生成应用的名称。stage 'build'git branch: sourceRef, url: sourceUrlsh "${mvnCmd} clean install -DskipTests=true"以上代码定义了pipeline的构建阶段。调用mvn clean先清理编译环境,然后用mvn install进行构建。stage 'test'sh "${mvnCmd} test"以上代码定义了代码测试阶段stage 'deployInDev'sh "rm -rf oc-build && mkdir -p oc-build/deployments"sh "cp target/openshift-tasks.war oc-build/deployments/ROOT.war"// clean up. keep the image stream以上代码定义了在dev阶段部署操作:将编译好的war包,拷贝到 oc-build/deployments目录下sh "oc project ${devProject}"以上代码调用oc client,切换项目。sh "oc delete bc,dc,svc,route -l application=${applicationName} -n ${devProject}"// create build. override the exit code since it complains about existing imagestream以上代码清空项目中的内容。sh "oc new-build --name=${applicationName} --image-stream=jboss-eap70-openshift --binary=true --labels=application=${applicationName} -n ${devProject} || true"// build image以上代码根据jboss-eap70-openshift的base image,创建bcsh "oc start-build ${applicationName} --from-dir=oc-build --wait=true -n ${devProject}"以上代码执行构建,即根据上一步指定的base image,加上本地oc-build目录下的内容(ROOT.war),生成应用的镜像。// deploy imagesh "oc new-app ${applicationName}:latest -n ${devProject}"sh "oc expose svc/${applicationName} -n ${devProject}"}以上代码根据上一步生成的镜像,部署应用,并为应用创建root。当然,在做maven编译的时候,需要用到pom文件,由于内容较多,不再贴出来,地址:stonezyg/openshift-tasks/blob/master/pom.xml。方案验证为了方便理解,将所有操作步骤贴出:首先,根据yaml文件创建openshift-tasks-jenkins file模板。#oc create -f h... te-jenkinsfile.yaml -n ocp-tasksaHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3JteDR4cGNrZjMuanBlZw?x-oss-process=image/format,png
接下来,通过模板部署jenkins master:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3RoYnpqMDR1MHMucG5n?x-oss-process=image/format,png
提示输入参数变量,这些参数,就是最终会传到Jenkinsfile的jenkins slave pod中的。这里,我们使用默认参数值。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2V0MDJuMXRlYXIucG5n?x-oss-process=image/format,png aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1LzdidjJ3Ynd0Y3gucG5n?x-oss-process=image/format,png
接下来,在项目中,会部署一个Jenkins的 master pod:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2xiM2g4bm80dnEucG5n?x-oss-process=image/format,pngaHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2dudXVmM3pqNWIucG5n?x-oss-process=image/format,png
我们可以设置Jenkins Master所指向的slave pod的地址:registry.access. /openshift3/jenkins-slave-maven-rhel7
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2huaTduY3FndWUucG5n?x-oss-process=image/format,png
而Pipeline也被创建成功(根据jenkins file中的定义)
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2dnYmM1cmpjODMucG5n?x-oss-process=image/format,png
接下来,手工触发Pipeline:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1LzUydXYzcGs5Zm0ucG5n?x-oss-process=image/format,png
接下来,我们关注Jenkins上的日志输出,由于信息较多,我只列出关键内容:
获取代码:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3NhZWs5dHlmbTMucG5n?x-oss-process=image/format,png
下载maven相关的pom文件:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3lxdnhoZng5cnoucG5n?x-oss-process=image/format,png
下载构建需要的jar包:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3N6Y2U3d3h4bWQucG5n?x-oss-process=image/format,png
下载完所需内容以后,进行Build,我们可以看一下build主任务:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L25jaGFlczRwN3EucG5n?x-oss-process=image/format,png
Build成功:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3E0NWxxYW1pOHkucG5n?x-oss-process=image/format,png
接下来进入test阶段,下面内容可以看出,test阶段是调用mvn test的命令:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3NmdGdpd3d2Mm0ucG5n?x-oss-process=image/format,png
test成功:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2EwYW9uZmk2MjEucG5n?x-oss-process=image/format,png
接下来是的devInDev阶段:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L210ZmM0bzE4dnYucG5n?x-oss-process=image/format,png
在这个阶段,Jenkins会调用openshift的命令,创建bc和dc:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3RpaWx4bjA4MGsucG5n?x-oss-process=image/format,png
部署应用并为应用创建routes:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2F1ODcwZmUwdmUucG5n?x-oss-process=image/format,png
截至到目前,pipeline执行完毕,应用也部署成功。我们将视角切换到Openshift的界面,pipeline已经执行成功。
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L2tweXBoeGljaXoucG5n?x-oss-process=image/format,png
接下来,我们通过浏览器访问应用的routes:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L24wajZldW03d3EucG5n?x-oss-process=image/format,png
可以看到应用部署已经成功:
aHR0cHM6Ly9hc2sucWNsb3VkaW1nLmNvbS9odHRwLXNhdmUveWVoZS0xMDkzODg1L3J2c2swZzBsaHguanBlZw?x-oss-process=image/format,png
方法总结
此种武器主要利用Jenkins进行代码的构建、应用的部署。对于较为复杂的应用编译,使用此种方法较为合适。另外,很多IT程度较高的客户,在docker大火之前,就已经基于Jenkins实现CI/CD了。这种情况下,如果新引入Openshift平台,使用此方法较可以延续以前的IT运维习惯,学习成本也相对较低(不需要大量修改现有的Jenkins)。
此这种方法的劣势在于对于Slave Pod有一定要求,不同于开发语言,需要使用不同的slave pod。此外,很多时候,我们也需要对slave pod的镜像做一定的定制,如增加一些rpm包等。
页:
[1]