GitLab CI/CD使用runner实现自动化部署前端Vue2 后端.Net 7 Zr.Admin项目

1、查看gitlab版本

建议安装的runner版本和gitlab保持一致

2、查找runner

执行

yum list gitlab-runner --showduplicates | sort -r

找到符合gitlab版本的runner,我这里选择 14.9.1版本

如果执行出现找不到下载源,添加官方仓库

执行

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash

3、安装runner

执行

yum install -y  gitlab-runner-14.9.1

查看安装runner的版本

执行

gitlab-runner -v

重启runner

执行

gitlab-runner restart

4、注册runner

进入项目信息页面

获取注册runner命令和注册所需的token

查看注册命令

真实的token,在进入获取注册命令页面之前的地方

注册runner

执行

sudo gitlab-runner register --url http://192.168.100.155:8088/ --registration-token GR1348941XFxw7VY3HN8qiyT-zXiT

上面的命令是从 Show runner installation instructions 页面复制,每个人的都不一样

执行命令后,会提示各个对应信息,直接复制给出的提示信息值即可

在要输入tags时,要记录输入的tags值,这个tags值对应流水线gitlab-ci.yml文件中的tags属性对应值

执行器executor一般为shell

注册完查看runner

执行

gitlab-runner list

页面上查看注册好的runner

可以再次编辑runner

点击编辑按钮

编辑页面显示的信息就是之前执行注册命令时填写的信息

5、CI/CD(创建gitlab-cli.yml)

进入CI/CD菜单,点击Editor进入gitlab-cli.yml编辑页面

查看创建的gitlab-ci.yml

执行gitlab-ci.yml文件定义的内容

查看执行过程的详细信息

点击 job的 Status列(passed那里),进入查看执行信息

6、gitlab-cli.yml 解析

# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages# 定义执行步骤,放在前面的先执行
# 这里的执行顺序为 build->test->deploy
stages:          # List of stages for jobs, and their order of execution- build- test- deploy#执行步骤详细内容
#stage:build 对应build步骤
build-job:       # This job runs in the build stage, which runs first.stage: build #对应执行步骤tags: # 指定的执行runner- zr-runner-0script: #执行脚本- echo "Compiling the code..."- echo "Compile complete."#stage:test 对应test步骤
unit-test-job:   # This job runs in the test stage.stage: test    # It only starts when the job in the build stage completes successfully.tags: - zr-runner-0script:- echo "Running unit tests... This will take about 60 seconds."- sleep 60- echo "Code coverage is 90%"#stage:test 对应test步骤
lint-test-job:   # This job also runs in the test stage.stage: test    # It can run at the same time as unit-test-job (in parallel).tags: - zr-runner-0script:- echo "Linting code... This will take about 10 seconds."- sleep 10- echo "No lint issues found."#stage:deploy deploy
deploy-job:      # This job runs in the deploy stage.stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.tags: - zr-runner-0script:- echo "Deploying application..."- echo "Application successfully deployed."

7、自动部署Zr.Admin项目

# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages# 定义执行步骤,放在前面的先执行
# 这里的执行顺序为 build->test->deploy
stages:          # List of stages for jobs, and their order of execution- build-net7- build-vue2- deploy#执行步骤详细内容
#stage:build 对应build步骤
build-job-net7:       # This job runs in the build stage, which runs first.stage: build-net7 #对应执行步骤tags: # 指定的执行runner- zr-runner-0script: #执行脚本- echo "Compiling the code..."#停止容器- docker stop $(docker ps -a | grep 'zr-admin' | awk '{print $1}') || true#删除容器- docker rm $(docker ps -a | grep 'zr-admin' | awk '{print $1}') || true#删除镜像- docker rmi $(docker images | grep zr-admin | awk '{print $3}') || true#构建docker-  cd /lsp/code/zradmin/- docker build -f Dockerfile -t zr-admin .- echo "Compile complete."# 设置GIT_STRATEGY为none来避免拉取代码variables:GIT_STRATEGY: nonebuild-job-vue2:       # This job runs in the build stage, which runs first.stage: build-vue2 #对应执行步骤tags: # 指定的执行runner- zr-runner-0script: #执行脚本- echo "Compiling the code..."- cd /lsp/code/zradmin/ZR.Vue/- npm cache clean --force- npm install --unsafe-perm=true --allow-root- npm run build:prod- echo "Compile complete."# 设置GIT_STRATEGY为none来避免拉取代码variables:GIT_STRATEGY: nonecache:paths:- node_modules/artifacts:paths:- dist/#stage:deploy deploy
deploy-job:      # This job runs in the deploy stage.stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.tags: - zr-runner-0script:- echo "Deploying application..."- echo "启动后端..."- docker run --net=host -p 8888:80 zr-admin- echo "启动后端成功"- echo "启动前端"- systemctl restart nginx- echo "启动前端成功"- echo "Application successfully deployed."

由于存在调试代码,设置了执行任务不需要更新代码

  # 设置GIT_STRATEGY为none来避免拉取代码

  variables:

    GIT_STRATEGY: none

如果在执行的过程中出现 权限问题

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

执行

#查看是否将docker加入用户组
groups#如果没有,加入
sudo usermod -aG docker $USER#给插件赋权
sudo chmod 666 /var/run/docker.sock

然后查看runner的权限

执行

#如果执行下面语句报错,就是有权限问题
sudo -u gitlab-runner -H docker info#然后执行下面这句
sudo usermod -aG docker gitlab-runner

如果runner是解决权限问题之前创建的,建议在赋权之后重新创建runner

执行完上面的命令,还出现权限问题,重启系统再试试!!!

如果还不行,就将runner改成root权限,默认安装完runner,用的是gitlab-runner用户

具体操作参考gitlab-runner执行权限不足

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/1258.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

56_多级缓存实现

1.查询Tomcat 拿到商品id后,本应去缓存中查询商品信息,不过目前我们还未建立Nginx、Redis缓存。因此,这里我们先根据商品id去Tomcat查询商品信息。此时商品查询功能的架构如下图所示。 需要注意的是,我们的OpenResty是在虚拟机,Tomcat是在macOS系统(或Windows系统)上,…

【STM32-学习笔记-9-】SPI通信

文章目录 SPI通信Ⅰ、SPI通信概述1、SPI技术规格2、SPI应用 3、硬件电路移位示意图 Ⅱ、SPI时序基本单元①、起始条件②、终止条件③、交换一个字节(模式0)④、交换一个字节(模式1)⑤、交换一个字节(模式2)…

小米vela系统(基于开源nuttx内核)——如何使用信号量进行PV操作

如何使用信号量进行PV操作 前言信号量1. 信号量简介2. NuttX中信号量的创建与使用2.1 Nuttx信号量的初始化和销毁2.2 信号量的等待和发布 3. 信号量的实际应用:下载任务示例3.1 实际代码3.2 代码说明3.3 执行说明 4. 信号量的优势与应用场景5. 常见应用场景&#xf…

MySQL Binlog 同步工具go-mysql-transfer Lua模块使用说明

一、go-mysql-transfer go-mysql-transfer是一款MySQL实时、增量数据同步工具。能够实时解析MySQL二进制日志binlog,并生成指定格式的消息,同步到接收端。 go-mysql-transfer具有如下特点: 1、不依赖其它组件,一键部署 2、集成多种…

灌区闸门自动化控制系统-精准渠道量测水-灌区现代化建设

项目背景 本项目聚焦于黑龙江某一灌区的现代化改造工程,该灌区覆盖广阔,灌溉面积高达7.5万亩,地域上跨越6个乡镇及涵盖17个村庄。项目核心在于通过全面的信息化建设,强力推动节水灌溉措施的实施,旨在显著提升农业用水的…

vue2修改表单只提交被修改的数据的字段传给后端接口

效果: 步骤一、 vue2修改表单提交的时候,只将修改的数据的字段传给后端接口,没有修改得数据不传参给接口。 在 data 对象中添加一个新的属性,用于存储初始表单数据的副本,与当前表单数据进行比较,找出哪些…

LiveNVR监控流媒体Onvif/RTSP常见问题-二次开发接口jquery调用示例如何解决JS|axios调用接口时遇到的跨域问题

LiveNVR二次开发接口jquery调用示例如何解决JS|axios调用接口时遇到的跨域问题 1、接口调用示例2、JS调用遇到跨域解决示例3、axios请求接口遇到跨域问题3.1、post请求3.2、get请求 4、RTSP/HLS/FLV/RTMP拉流Onvif流媒体服务 1、接口调用示例 下面是完整的 jquery 调用示例 $.a…

RTDETR融合[WACV 2024]的MetaSeg中的gmb模块

RT-DETR使用教程: RT-DETR使用教程 RT-DETR改进汇总贴:RT-DETR更新汇总贴 《MetaSeg: MetaFormer-based Global Contexts-aware Network for Efficient Semantic Segmentation》 一、 模块介绍 论文链接:https://arxiv.org/abs/2408.07576 代…

TensorFlow Quantum快速编程(基本篇)

一、TensorFlow Quantum 概述 1.1 简介 TensorFlow Quantum(TFQ)是由 Google 开发的一款具有开创性意义的开源库,它宛如一座桥梁,巧妙地将量子计算与 TensorFlow 强大的机器学习功能紧密融合。在当今科技飞速发展的时代,传统机器学习虽已取得诸多瞩目成就,然而面对日益…

Spring Boot 2 学习全攻略

Spring Boot 2 学习资料 Spring Boot 2 学习资料 Spring Boot 2 学习资料 在当今快速发展的 Java 后端开发领域,Spring Boot 2 已然成为一股不可忽视的强大力量。它简化了 Spring 应用的初始搭建以及开发过程,让开发者能够更加专注于业务逻辑的实现&am…

深度学习笔记11-优化器对比实验(Tensorflow)

🍨 本文为🔗365天深度学习训练营中的学习记录博客🍖 原作者:K同学啊 目录 一、导入数据并检查 二、配置数据集 三、数据可视化 四、构建模型 五、训练模型 六、模型对比评估 七、总结 一、导入数据并检查 import pathlib,…

HBuilderX打包ios保姆式教程

1、登录苹果开发者后台并登录已认证开发者账号ID Sign In - Apple 2、创建标识符(App ID)、证书,描述文件 3、首先创建标识符,用于新建App应用 3-1、App的话直接选择第一个App IDs,点击右上角继续 3-2、选择App&#x…

计算机网络 (39)TCP的运输连接管理

前言 TCP(传输控制协议)是一种面向连接的、可靠的传输协议,它在计算机网络中扮演着至关重要的角色。TCP的运输连接管理涉及连接建立、数据传送和连接释放三个阶段。 一、TCP的连接建立 TCP的连接建立采用三次握手机制,其过程如下&…

2 XDMA IP中断

三种中断 1. Legacy 定义:Legacy 中断是传统的中断处理方式,使用物理中断线(例如 IRQ)来传递中断信号。缺点: 中断线数量有限,通常为 16 条,限制了可连接设备的数量。中断处理可能会导致中断风…

22、PyTorch nn.Conv2d卷积网络使用教程

文章目录 1. 卷积2. python 代码3. notes 1. 卷积 输入A张量为: A [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ] \begin{equation} A\begin{bmatrix} 0&1&2&3\\\\ 4&5&6&7\\\\ 8&9&10&11\\\\ 12&13&14&15 \end{b…

基于微信小程序的汽车销售系统的设计与实现springboot+论文源码调试讲解

第4章 系统设计 一个成功设计的系统在内容上必定是丰富的,在系统外观或系统功能上必定是对用户友好的。所以为了提升系统的价值,吸引更多的访问者访问系统,以及让来访用户可以花费更多时间停留在系统上,则表明该系统设计得比较专…

【ROS2】☆ launch之Python

☆重点 ROS1和ROS2其中一个很大区别之一就是launch的编写方式。在ROS1中采用xml格式编写launch,而ROS2保留了XML 格式launch,还另外引入了Python和YAML 编写方式。选择哪种编写取决于每位开发人员的爱好,但是ROS2官方推荐使用Python方式编写…

Facebook 隐私变革之路:回顾与展望

在数字时代,个人隐私的保护一直是社交平台面临的重大挑战之一。作为全球最大的社交网络平台,Facebook(现为Meta)在处理用户隐私方面的变革,历经了多次调整与完善。本文将回顾Facebook在隐私保护方面的历程,…

P10打卡——pytorch实现车牌识别

🍨 本文为🔗365天深度学习训练营中的学习记录博客🍖 原作者:K同学啊 1.检查GPU from torchvision.transforms import transforms from torch.utils.data import DataLoader from torchvision import datasets import torchvisio…

Pycharm连接远程解释器

这里写目录标题 0 前言1 给项目添加解释器2 通过SSH连接3 找到远程服务器的torch环境所对应的python路径,并设置同步映射(1)配置服务器的系统环境(2)配置服务器的conda环境 4 进入到程序入口(main.py&#…