• Gitlab搭建以及CI/CD


    1,gitlab runner安装以及配置

    Download and install binary
    # Download the binary for your system
    sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
    
    # Give it permissions to execute
    sudo chmod +x /usr/local/bin/gitlab-runner
    
    # Create a GitLab CI user
    sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
    
    # Install and run as service
    sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
    sudo gitlab-runner start
    Command to register runner
    sudo gitlab-runner register --url https://gitlab.bdynamics.com.cn/ --registration-token $REGISTRATION_TOKEN

    2,指定runner clone仓库的地址 

    sudo vi /etc/gitlab-runner/config.toml
    
    指定 clone_url = "http://127.0.0.1/"

    3,gitlab 安装以及指定https/http方式运行

     sudo vi /etc/gitlab/gitlab.rb

    external_url 'https://gitlab.bdynamics.com.cn'
    ##nginx['ssl_certificate'] = "/home/penglei/opt/bdynamics.com.cn.pem"
    nginx['ssl_certificate'] = "/home/penglei/opt/Nginx/1_bdynamics.com.cn_bundle.crt"
    nginx['ssl_certificate_key'] = "/home/penglei/opt/Nginx/2_bdynamics.com.cn.key"

    sudo gitlab-ctl reconfigure

    sudo gitlab-ctl restart

    nginx配置

    /var/opt/gitlab/nginx/conf 增加  gitlab-http.conf 内容

      listen *:80;
    
    
      server_name gitlab.bdynamics.com.cn;

    然后再 /var/opt/gitlab/nginx/conf/nginx.conf中添加

      include /var/opt/gitlab/nginx/conf/gitlab-http.conf;
      include /var/opt/gitlab/nginx/conf/gitlab-https.conf;

    sudo gitlab-ctl nginx restart  (此时不要sudo gitlab-ctl reconfigure,reconfigure会重写配置 /var/opt/gitlab/nginx/conf/nginx.conf)

    4,gtest 与CI/CD

    CICD配置文件 .gitlab-ci.yml    (script中命令所在目录就是源码的根目录,源码会由gitlab runner自动拉取,stages 也可以定义多个,这样可以把代码静态检查等加入到CI/CD里

    stages:
        - buildtest
    
    buildtest:
        stage: buildtest
        script:
            - rm buildx86 -rf
            - mkdir buildx86
            - cd buildx86
            - cmake ..
            - make -j4
            - make all_test

    项目cmake参考,根目录的cmake

    cmake_minimum_required (VERSION 2.8)
    
    project (my_app)
    
    enable_testing()
    add_custom_target(all_test ${CMAKE_CTEST_COMMAND} -V)
    set_property(GLOBAL PROPERTY ROOT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
    set_property(GLOBAL PROPERTY COMMON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
    
    
    add_executable(my_app ${DIR_SRCS})
    
    target_link_libraries(my_app 
                    pthread
                    dl
                    m
                    )

    测试代码对应的cmake

    aux_source_directory(. DIR_LIB_SRCS)
    ## singleton test
    add_executable(singleton_test test/singleton_test.cpp)
    
    target_link_libraries(singleton_test
                    core_base
                    ${GTEST_LIB}
                    pthread
                    )
    add_test(singleton_test singleton_test
            )

    测试代码示例singleton_test.cpp:

    TEST(singletonTest, create_singleton_test) {
        std::cout << Singleton<TestNoDestroy>::instance().name() << std::endl;;
        std::cout << Singleton<TestDestroy>::instance().name() << std::endl;;
    }

     

  • 相关阅读:
    吉他谱----see you again
    web----tcp三次握手
    python shell 执行
    python jieba
    NLP gensim 相似度计算
    linux shell expect 自动交互脚本
    docker 安装镜像
    数据库 MySQL 数据导入导出
    爬虫 puppeteer
    Linux ssh相关
  • 原文地址:https://www.cnblogs.com/rayfloyd/p/14798381.html
Copyright © 2020-2023  润新知