当前位置: 首页 > news >正文

实践003-Gitlab CICD编译构建

文章目录

    • 后端Java编译
      • 后端Java项目编译jar包
      • 后端Java构建为镜像
    • 前端VUE项目构建
      • 前端项目构建镜像

后端Java编译

后端Java项目编译jar包

直接使用流水线进行快速编译。

[root@gitclient apiserver]# vim .gitlab-ci.yml
stages:- compilecompile:stage: compileimage: maven:3.8.5-openjdk-17script:- mvn clean- mvn compile- mvn package -Dmaven.test.skip=true- ls targetonly:- maintags:- study-runner

提交流水线:

[root@gitclient apiserver]# git add .
[root@gitclient apiserver]# git commit -m "Compile Java to jar"
[root@gitclient apiserver]# git push origin main

查看编译结果,可知以成功编译出jar包。
197

此编译 jar 包后续需要封装为容器镜像,因此需要将编译的结果作为产物进行共享。
修改流水线如下后,重新提交流水线:

[root@gitclient apiserver]# vim .gitlab-ci.yml
stages:- compilecompile:stage: compileimage: uhub.service.ucloud.cn/imxhy/maven:3.8.5-openjdk-17artifacts:paths:- target/apiservice-0.0.1-SNAPSHOT.jarscript:- mvn clean- mvn compile- mvn package -Dmaven.test.skip=true- ls targetonly:- maintags:- study-runner

提交流水线:

[root@gitclient apiserver]# git add .
[root@gitclient apiserver]# git commit -m "Compile and Share Java to jar"
[root@gitclient apiserver]# git push origin main

查看流水线:

198

后端Java构建为镜像

编写相应的Dockerfile文件,将jar封装为对应的容器镜像。

[root@gitclient apiserver]# vim Dockerfile
FROM uhub.service.ucloud.cn/imxhy/maven:3.8.5-openjdk-17MAINTAINER xhy@itzgr.cnRUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezoneEXPOSE 8080WORKDIR /opt/apiservice/COPY target/apiservice-0.0.1-SNAPSHOT.jar ./ENTRYPOINT ["java","-jar","/opt/apiservice/apiservice-0.0.1-SNAPSHOT.jar"]

使用Dockerfile构建镜像的步骤可以直接合入到流水线中,即增加build阶段。
提前在gitlab中创建ALIYUN_USER和ALIYUN_PASSWORD变量,配置阿里云镜像推送的账号和密码。

[root@gitclient apiserver]# vim .gitlab-ci.yml
stages:- compile- buildcompile:stage: compileimage: uhub.service.ucloud.cn/imxhy/maven:3.8.5-openjdk-17artifacts:paths:- target/apiservice-0.0.1-SNAPSHOT.jarscript:- mvn clean- mvn compile- mvn package -Dmaven.test.skip=true- ls targetonly:- maintags:- study-runnerbuild:stage: buildimage: uhub.service.ucloud.cn/imxhy/executor:v1.9.0-debugneeds:- compilescript:- ls target- IMAGE_TAG=$(echo "${CI_COMMIT_TIMESTAMP}" | sed 's/T/_/g; s/-//g; s/://g' | cut -c1-15)- IMAGE_TAG_TO_INSTALL=${CI_COMMIT_TAG:-$IMAGE_TAG}- mkdir -p /kaniko/.docker- echo "{\"auths\":{\"registry.cn-hangzhou.aliyuncs.com\":{\"auth\":\"$(echo -n ${ALIYUN_USER}:${ALIYUN_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json- cat /kaniko/.docker/config.json- >/kaniko/executor--context "${CI_PROJECT_DIR}"--dockerfile "${CI_PROJECT_DIR}/Dockerfile"--destination "registry.cn-hangzhou.aliyuncs.com/xhyimages/apiservice:${IMAGE_TAG_TO_INSTALL}"--registry-mirror "https://dbzucv6w.mirror.aliyuncs.com"only:- main- tagstags:- study-runner

提交流水线:

[root@gitclient apiserver]# git add .
[root@gitclient apiserver]# git commit -m "Compile and Share and Build Java to jar"
[root@gitclient apiserver]# git push origin main

提示:如上流水线直接将构建的镜像推送到阿里云镜像仓库,便于后期直接使用。

查看流水线:

199

确认推送成功:

200

前端VUE项目构建

前端项目构建镜像

前端VUE项目可以直接构建为容器镜像,不需要编译。

编写如下 Dockerfile ,构建对应的容器镜像。

[root@gitclient webui]# vim Dockerfile
FROM uhub.service.ucloud.cn/imxhy/node:23.11.0MAINTAINER xhy@itzgr.cnRUN npm install -g @vue/cliWORKDIR /opt/webui/COPY . ./RUN npm installENTRYPOINT ["npm","run","serve"]

编写流水线:

[root@gitclient webui]# vim .gitlab-ci.yml
stages:- buildbuild:stage: buildimage: uhub.service.ucloud.cn/imxhy/executor:v1.9.0-debugscript:- IMAGE_TAG=$(echo "${CI_COMMIT_TIMESTAMP}" | sed 's/T/_/g; s/-//g; s/://g' | cut -c1-15)- IMAGE_TAG_TO_INSTALL=${CI_COMMIT_TAG:-$IMAGE_TAG}- mkdir -p /kaniko/.docker- echo "{\"auths\":{\"registry.cn-hangzhou.aliyuncs.com\":{\"auth\":\"$(echo -n ${ALIYUN_USER}:${ALIYUN_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json- cat /kaniko/.docker/config.json- >/kaniko/executor--context "${CI_PROJECT_DIR}"--dockerfile "${CI_PROJECT_DIR}/Dockerfile"--destination "registry.cn-hangzhou.aliyuncs.com/xhyimages/webui:${IMAGE_TAG_TO_INSTALL}"--registry-mirror "https://dbzucv6w.mirror.aliyuncs.com"only:- main- tagstags:- study-runner

提交流水线:

[root@gitclient webui]# git add .
[root@gitclient webui]# git commit -m "Build webui to docker image"
[root@gitclient webui]# git push origin main

提示:如上流水线直接将构建的镜像推送到阿里云镜像仓库,便于后期直接使用。

查看流水线:

202

确认推送成功:

203


文章转载自:

http://l9nCQYQJ.hmbtb.cn
http://38CsZyBe.hmbtb.cn
http://bWXVVoIc.hmbtb.cn
http://6MppjZNx.hmbtb.cn
http://AvAhbpRO.hmbtb.cn
http://3WOFvFoC.hmbtb.cn
http://qbslDVjR.hmbtb.cn
http://Dukp0vl5.hmbtb.cn
http://JiMhjeih.hmbtb.cn
http://vtIhEvr5.hmbtb.cn
http://enzuIQFi.hmbtb.cn
http://OjGh6YHX.hmbtb.cn
http://ID1Ykd2F.hmbtb.cn
http://CnjJ0FJG.hmbtb.cn
http://qqYN1gqb.hmbtb.cn
http://WThTJ1uC.hmbtb.cn
http://edcQDG8Z.hmbtb.cn
http://Acqzj61h.hmbtb.cn
http://jw8FfxAp.hmbtb.cn
http://3DyB5uTe.hmbtb.cn
http://CeoZhWQp.hmbtb.cn
http://YFgWSPCm.hmbtb.cn
http://xS28Czuf.hmbtb.cn
http://wjjnlBH1.hmbtb.cn
http://4ZzC6hpm.hmbtb.cn
http://CvylwNiq.hmbtb.cn
http://7j4PxxcR.hmbtb.cn
http://8VgyWoiz.hmbtb.cn
http://6hAqyWoa.hmbtb.cn
http://14BE09kS.hmbtb.cn
http://www.dtcms.com/a/176064.html

相关文章:

  • 隐私计算技术及其在数据安全中的应用:守护数据隐私的新范式
  • python 闭包获取循环数据经典 bug
  • 滑动窗口——长度最小子数组
  • Go 并发错误处理利器:深入理解 errgroup
  • Kafka的消息保留策略是怎样的? (基于时间log.retention.hours或大小log.retention.bytes,可配置删除或压缩策略)
  • 【前端基础】7、CSS的字体属性(font相关)
  • 《Python星球日记》 第47天:聚类与KMeans
  • 学习笔记:黑马程序员JavaWeb开发教程(2025.3.30)
  • 项目模拟实现消息队列第二天
  • spring 事务实现原理
  • RabbitMq学习(第一天)
  • C++中的位运算符:与、或、异或详解
  • 阿里云2核2g安装nexus
  • shell脚本--2
  • 如何在大型项目中解决 VsCode 语言服务器崩溃的问题
  • 【shardingsphere分布式主键无效】
  • Kubernetes(k8s)学习笔记(八)--KubeSphere定制化安装
  • C 语言编码规范
  • Selenium使用指南
  • 21. LangChain金融领域:合同审查与风险预警自动化
  • 802.11s Mesh 组网框架流程
  • 排序算法——桶排序
  • 一个电平转换电路导致MCU/FPGA通讯波形失真的原因分析
  • 阿里云codeup以及本地gitclone+http
  • AB测试面试题
  • 年化50.1%,回撤23%|从数据加载,因子分析到lightGBM因子合成,智能策略开发全流程(附python代码下载)
  • livedata使用,完整的livedata的Demo
  • 缓存菜品-04.功能测试
  • IEC103 转 ModbusTCP 网关
  • MapReduce架构-打包运行