diff --git a/.env.production-atu b/.env.production-atu new file mode 100644 index 0000000..b45a7e0 --- /dev/null +++ b/.env.production-atu @@ -0,0 +1,4 @@ +# 生产环境 +VITE_NODE_ENV=production +VITE_API_BASE_URL=https://api.atuchat.com +VITE_APP_TITLE=@U H5 diff --git a/package.json b/package.json index 036e7d0..bb325a3 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "build:dev": "vite build --mode development && node scripts/generate-version.js", "build:test": "vite build --mode test && node scripts/generate-version.js", "build:prod": "vite build --mode production && node scripts/generate-version.js", + "build:atu-prod": "vite build --mode production-atu && node scripts/generate-version.js", "preview": "vite preview", "lint": "eslint . --fix" }, diff --git a/pipeline-atu b/pipeline-atu new file mode 100644 index 0000000..e84327b --- /dev/null +++ b/pipeline-atu @@ -0,0 +1,66 @@ +pipeline { + + agent { + label "dev" + } + + tools { + nodejs 'node22' + } + + environment { + PATH = "/var/jenkins_home/docker-cli/bin:/var/jenkins_home/kubectl/bin:${env.PATH}" + BUILD_IMAGE = "${sh(script:'echo -n atyou-prod:h5-$(date +%Y%m%dv%H%M%S)', returnStdout: true)}" + ALIYUN_REGISTRY = "tuokemi-con-registry.ap-southeast-1.cr.aliyuncs.com/atyou-prod/h5" + IMAGE_REP_TAG = "" + K8S_NAMESPACE = "prod" + K8S_DEPLOYMENT = "h5" + K8S_APP_LABEL = "h5" + DOCKER_FILE = "Dockerfile-dev" + } + + stages { + stage('Build') { + steps { + sh 'export PATH=$HOME/bin:$PATH && export NODE_HOME=/usr/local/node && export PATH=$NODE_HOME/bin:$PATH && npm config set registry https://registry.npmmirror.com && npm install' + sh 'export PATH=$HOME/bin:$PATH && export NODE_HOME=/usr/local/node && export PATH=$NODE_HOME/bin:$PATH && npm run build:atu-prod' + sh 'du -sh dist' + script { + IMAGE_REP_TAG = "${ALIYUN_REGISTRY}:h5-${sh(script:'date +%Y%m%dv%H%M%S', returnStdout: true).trim()}" + } + echo "---> Image registry tag: ${IMAGE_REP_TAG}" + } + } + stage('Build image') { + steps { + withCredentials([usernamePassword( + credentialsId: 'aliyun-registry', + usernameVariable: 'ALIYUN_USER', + passwordVariable: 'ALIYUN_PASS' + )]) { + sh 'echo $ALIYUN_PASS | docker login --username $ALIYUN_USER --password-stdin tuokemi-con-registry.ap-southeast-1.cr.aliyuncs.com' + } + sh "docker build -f ${DOCKER_FILE} -t ${IMAGE_REP_TAG} ." + } + } + stage('Upload image') { + steps { + sh "docker push ${IMAGE_REP_TAG}" + sh "docker tag ${IMAGE_REP_TAG} ${ALIYUN_REGISTRY}:latest" + sh "docker push ${ALIYUN_REGISTRY}:latest" + sh "docker rmi -f ${IMAGE_REP_TAG} ${ALIYUN_REGISTRY}:latest" + } + } + stage('Apply') { + steps { + sh "kubectl -n ${K8S_NAMESPACE} set image deployment/${K8S_DEPLOYMENT} ${K8S_APP_LABEL}=${IMAGE_REP_TAG.replace('tuokemi-con-registry', 'tuokemi-con-registry-vpc')}" + } + } + } + + post { + always { + cleanWs() + } + } +}