• 云计算_CI/CD_devOps_集成_Gitlab


    Git和Gitlab

    开发多年,git不能说特别熟悉,至少了解不少,
            常用的  git config git status,git add  ,git commit ,git push ,git clone, git pull,git init等,
      在多年前的自建的博客中就已经用的很顺手了,,对底层的概念也做过大致的研究,
      而现在则要根据项目,重现研习一下,git在项目中的使用了
    Gitlab基于Git,但不停留在Git上,有自己特有的一些概念和使用
    

    GitLab CI/CD DevOps

     GitLab-CI与GitLab Runner
     集成工作自动化
        自动化的构建(包括编译,发布,自动化测试) 
    	  合并代码---->安装依赖---->编译---->测试---->发布	  
    过程
        Gitlab 中工程的仓库代码发生变动时,GitLab就会将这个变动通知GitLab-CI。
    	GitLab-CI 会找出与这个工程相关联的 GitLab-Runner,并通知这些Runner 
    	GitLab-Runner 把代码更新到本地并执行预定义好的执行脚本
    pipeline
        一个简单的管道通常包括三个阶段:build、test、deploy	
    

    Git glossary

    术语  git help glossary
    远程 remote repository
         remote  origin
    	  branch master
    本地 local repository
       本地工作区: working directory
       本地暂存区: Staging Area    一般存放在 .git 目录下的 index 文件(.git/index)中
                git  commit 
    	版本库:工作区有一个隐藏目录 .git
    	
    进一步了解
         git checkout
    	 
    	 git help glossary
    本地常用操作
        	 git diff
    		 git commit
    		 git reset      将…恢复原位
    		 git rm  git mv  git log
    		 
    		 RESET:重启系统、复位系统
         分支操作
    	     创建分支命令   git branch (branchname)
    		      列出分支  git branch
    		 切换分支命令   git checkout (branchname)
    		 创建并切换分支 git checkout -b (branchname) 命令来创建新分支并立即切换到该分支下,从而在该分支中操作
    		 删除分支       git branch -d (branchname)
    		 合并分支命令   git merge
    		                git 
    			
              rebase 合并多个commit为一个完整commit	
                 git rebase -i HEAD~3 
                  pick:保留该commit(缩写:p)  squash:将该commit和前一个commit合并(缩写:s)	
                  drop:我要丢弃该commit(缩写:d)	
                  reword:保留该commit,但我需要修改该commit的注释(缩写:r) 
    			     edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e)			
    		 git revert HEAD  撤销提交
    		 git reset HEAD   丢弃提交
    		 
    	HEAD	 HEAD指向所在的分支--HEAD指针总是通过分支指针,间接的指向了当前分支的最新提交--前分支的别名					
    	commit id  
    	git tag  
    	       如果你达到一个重要的阶段,并希望永远记住那个特别的提交快照,你可以使用 git tag 给它打上标签
    		   指向某个 commit 的指针,某个commit绑在一起   
    

    GitLab glossary

    权限管理及Merge Request
     GitLab的Merge Request   
     GitLab中的角色分为以下5种:Guest、Reporter、Developer、Maintainer、Owner	
         Maintainer能够push代码到受保护分支,
    	 而Developer只能创建Merge Requests
      jobs issues	 
      Gitlab UI
          Settings -> Repository -> Protected Branches	
      Merger Request
          Merge method: Merge commit / merge commit with semi-linear history /fast-forward merge
    	  Merge options
    	  Merge checks
    	  Merge suggestions
    	  Squash commits when Mergeing
          
     Source branch	   Target branch 
    	  Git stash		 
    GitLab  Web页面
     Sma
       Project Information
       Repository: Files Commits  Branch Tags
                    Contributors 
       Issues List  Board  Milestones
       Merege requests: New merge request  / edit merge requests
       CI/CD : Pipelines Editor Jobs Schedules
       Deployments
       Settings : GEneral    Integrations Repository CI/CD
       
      应用: Settings-->CI/CD-->Runners页面可以查看到是否有可用的Runner。
             Lint 的嵌入式调试工具,该工具可以验证 .gitlab-ci.yml 文件的内容  项目 -> CI/CD -> Pipelines
    

    DevOps-工作模式

    01.分支管理模式: 把项目的开发分为四个阶段:开发、测试、预发布和发布
          commit之前不喜欢pull下最新代码 导致会有merge commit,经常也会遇到冲突
    02.Merge Request模式--开源长采用	
         gitlab上发起merge request 将自己的分支合并到feature分支上并且指定review的人员 Review通过后由其merge
    	 merge request的作用其实就是多了一层review 由指定的人员review之后再merge
    	 git rebase 变基rebase这个操作重新选定当前提交的根节点	 
    Gitlab  Branch和Tag
            Issue 议题  Milestone 里程碑
        用 milestone 标识阶段目标,对阶段性目标进行细化,化整为零成一个个的 issues	
        用issues 一个议题表示一个功能、一个bug、一个建议	
           Comment和Discussion		 
    		
     DevOps
        Plan Create Verify Release
        Configure Manage Monitor Secure	
     多分支
        对于多分支的代码库,将代码从一个分支转移到另一个分支是常见需求
    	   需要另一个分支的所有代码变动,那么就采用合并(git merge)
    	   只需要部分代码变动(某几个提交),这时可以采用 Cherry pick-指定的提交(commit)应用于其他分支。	   
     Git flow	 
     Github flow -- Pull Request  是github的概念,不是git的概念 请对方做一个git fetch拿到request中的代码commits,然后git merge一下到某个分支上。
     Gitlab flow -- Merge Requests
        基于"版本发布"的,目标是一段时间以后产出一个新版本
        网站项目是"持续发布",代码一有变动,就部署一次	 
    	  protected branch
    ##Gitlab支持软件开发的全流程
    

    Gitlab触发 CI pipeline

     1.GitLab代码提交或推送触发CI pipeline,需要满足以下2点条件:
      01.仓库根目录下存在有 .gitlab-ci.yml 文件
      02.该项目有可用的 GitLab Runner
      
     2.一次构建任务-Types of pipelines
       Pipelines for Merge Requests
          Merge request pipelines run for merge requests only (rather than for every commit).
       pipelines for tags        
       
     
     3.variables
        01.预定义变量
    	    有值
    		特定条件下有值  CI_COMMIT_TAG  The commit tag name. Available only in pipelines for tags.
    	02.自定义变量
    	    Variable type variables
    	    File type variables:
    	作业包括外部YAML文件。也可用:include:local,include:file,include:template,和include:remote。
    	tags 关键词是用于指定Runner
    	only  只有在**分支可以运行
    	
    04.shell脚本
        export MO_NAME=`echo ${CI_COMMIT_TAG}|cut -d # -f 1`
        export TG_VERSION=`echo ${CI_COMMIT_TAG}|cut -d # f 2 -`
    	eval MOE_VERSION=\${${MO_NAME}_VERSION} && export MOE_VERSION
    	eval MOE_VERSION=\${${MO_NAME}_VERSION} | export MOE_VERSION 管道符是有输出的情况,这种事同时成立,使用and符号
    05.调用Dockerfile文件
      .Dockerfile中使用其定义的变量,同时使用自定义的entrypoint.sh,注意定义变量的scope 作用域
    

    Tag

       git tag
      .gitlab-ci.yml file
       config.toml file
    
        git tag
     .gitlab-ci.yml file
     only
     except
     rules
     config.toml file
      config.toml
        [[runners]]
          name   url  token
        environment  executor  shell tags
    

    开发配置

     Docker镜像仓库-- harbor-- 原始镜像, 发布版本镜像
    	对象存储
    	Gitlab
    	Gitlab-runner
    # 传感器和数据格式
        数据定义	
    # 编码风格
         ### 编程语言-代码
    	 ### 代码格式
    	 ### 变量命名规则: 文件(夹)命名  静态常量命名  类名  类(class)成员变量命名
    # 环境
        环境
    	    Linux 版本 gcc
    		Docker 版本
    		ROS版本
    		Cmake 版本
    		Nvidia-Driver  Cuda11.1/Cudnn8.0.5
        环境变量
    	环境检查--Linux Ros Cmake python 
    	           protobuf
    			   ROS http://wiki.ros.org/melodic/Installation/Ubuntu
    			   Eigen 是一个基于C++模板的线性代数库 
    			           https://eigen.tuxfamily.org/index.php?title=Main_Page
             			   http://eigen.tuxfamily.org/dox/AsciiQuickReference.txt
    					   Eigen is a pure template library defined in the headers, doesn't have any dependencies other than the C++ standard library.
    			   Ceres solver 是谷歌开发的一款用于非线性优化的库,
    			      在谷歌的开源激光雷达slam项目cartographer中被大量使用
    				  Ceres Solver   is an open source C++ library for modeling and solving large, complicated optimization problems.
    				  参考 http://www.ceres-solver.org/
    			   g2o  图优化库
    			   lidar_align  传感器标定
    			          https://github.com/ethz-asl/lidar_align 
    				  依赖 sudo apt-get install libnlopt-dev
    			      nlopt是MIT一大神编写的针对非线性函数优化库,里面包含许多成熟的优化函数。全称nonlinear --Dependency for [lidar_align]
    			      https://nlopt.readthedocs.io/en/latest/
    			  opencv  视觉   https://opencv.org/	 https://docs.opencv.org/				   
    			  The Point Cloud Library (PCL)
    			       https://pcl.readthedocs.io/projects/tutorials/en/master/
    			  sensor_msgs/PointCloud2
       			        http://docs.ros.org/en/jade/api/sensor_msgs/html/msg/PointCloud2.html
    			  gtest,测试框架,是在不同平台上(Linux,Mac OS X,Windows,Cygwin,Windows CE和Symbian)为编写C++测试而生成
    		图优化 图优化本质上是一个优化问题,所以我们先来看优化问题是什么。
    

    GitLab CI/CD DevOps

    GitLab-CI与GitLab Runner
    集成工作自动化
        自动化的构建(包括编译,发布,自动化测试) 
    	  合并代码---->安装依赖---->编译---->测试---->发布
    	  
    过程
        Gitlab 中工程的仓库代码发生变动时,GitLab就会将这个变动通知GitLab-CI。
    	GitLab-CI 会找出与这个工程相关联的 GitLab-Runner,并通知这些Runner 
    	GitLab-Runner 把代码更新到本地并执行预定义好的执行脚本
    
    pipeline
        一个简单的管道通常包括三个阶段:build、test、deploy	
    

    1.DOCKER_AUTH_CONFIG

    01. docker login --uername $username --password $password
      命令完成以后,会生成如下文件~/.docker/config.json
      格式:
        {
          "auths": {
                 "https://index.docker.io/v1/": {
                         "auth": "XXXXX",
                        "email": "<your-email>"
              }
          },
    	  "HttpHeaders":{
    	       "User-Agent":"Docker-Client"
    	  }
        }
     内容 
        是你刚刚输入的用户名密码的加密后的输出(based64-encoded 
      
    02.Access an image from a private Container Registry
     To access private container registries, the GitLab Runner process can use:
       A DOCKER_AUTH_CONFIG CI/CD variable.
       A DOCKER_AUTH_CONFIG environment variable set in the runner’s config.toml file.
       A config.json file in $HOME/.docker directory of the user running the process. 
          If the --user flag is provided to run the child processes as unprivileged user, the home directory of the main runner process user is used.
    https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#define-an-image-from-a-private-container-registry
    
    gitlab-runner/config/config.toml 
        environment =  ["DOCKER_AUTH_CONFIG={\"auths\": {\"harbor.test.com\": { \"auth\": \"XXXXX\"}}}"]
    

    2.docker build

      命令用于使用 Dockerfile 创建镜像。
      --build-arg=[] :设置镜像创建时的变量;
      --no-cache :创建镜像的过程不使用缓存
      --rm :设置镜像成功后删除中间容器
      使用当前目录的 Dockerfile 创建镜像,标签为 runoob/ubuntu:v1。
      docker build -t runoob/ubuntu:v1 .
       . 表示当前目录地址
       -t 选项来docker build新的镜像以便于标记构建的镜像
       -f Dockerfile 文件的位置:
      $ docker build -f /path/to/a/Dockerfile .
    

    参考

     https://docs.gitlab.com/ee/topics/use_gitlab.html
     https://docs.gitlab.com/ee/topics/build_your_application.html
  • 相关阅读:
    闪电侠 Netty 小册里的骚操作
    面试被问烂的 Spring IOC(求求你别再问了)
    面试问烂的 Spring AOP 原理、SpringMVC 过程(求求你别问了)
    使用 Cglib 实现多重代理
    Redis 初次见面
    Apollo 10 — adminService 全量发布
    Apollo 9 — adminService 主/灰度版本发布
    简析限流算法
    Dubbo 源码分析
    Dubbo 源码分析
  • 原文地址:https://www.cnblogs.com/ytwang/p/15989190.html
Copyright © 2020-2023  润新知