echo '==============开始构建前端代码==================='
cd 项目跟目录
echo '==============安装检查开发依赖包================='
npm install
echo '==============编译打包线上版本资源==============='
npm run build
echo '==============前端自动化构建完成================='
cd 项目跟目录/dist
docker build -t hfdockerhub.com.cc:1443/hfocean/jenkins-${APP_NAME}:${BUILD_NUMBER} .
docker push hfdockerhub.com.cc:1443/hfocean/jenkins-${APP_NAME}:${BUILD_NUMBER}
下面两个文件的namespace要替换成自己k8s服务器分配的命名空间,而且要一致
配置deployment.json
{
"kind": "Deployment",
"apiVersion": "apps/v1",
"metadata": {
"name": "${APP_NAME}-deployment",
"namespace": "k8s的命名空间",
"labels": {
"k8s-app": "${APP_NAME}"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"k8s-app": "${APP_NAME}"
}
},
"template": {
"metadata": {
"name": "${APP_NAME}",
"labels": {
"k8s-app": "${APP_NAME}"
}
},
"spec": {
"containers": [
{
"name": "app",
"image": "hfdockerhub.com.cc:1443/hfocean/jenkins-${APP_NAME}:${BUILD_NUMBER}",
"resources": {},
"imagePullPolicy": "IfNotPresent",
"securityContext": {
"privileged": false,
"procMount": "Default"
},
"ports":
[{ "containerPort": 8080,
"targetPort": 8080
}],
"volumeMounts":[
]
}
],
"volumes":[],
"type": "NodePort",
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"schedulerName": "default-scheduler"
}
},
"strategy": {
"type": "RollingUpdate",
"rollingUpdate": {
"maxUnavailable": "25%",
"maxSurge": "25%"
}
},
"revisionHistoryLimit": 10,
"progressDeadlineSeconds": 600
}
}
配置service.json
{
"apiVersion":"v1",
"kind":"Service",
"metadata":{
"namespace":"k8s的命名空间",
"name":"${APP_NAME}-service",
"labels":{
"k8s-service":"${APP_NAME}"
}
},
"spec":{
"selector":{
"k8s-app": "${APP_NAME}"
},
"ports":[
{"port":8080,"targetPort":8080}
],
"type":"NodePort"
}
}