栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

GitLab CICD小记

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

GitLab CICD小记

GitLab CICD小记

GitLab功能及优势安装需求docker安装GitLab runner(类Jenkins slave)aws对象存储保存作业产物GitLab 作为软件包仓库和容器镜像仓库(支持对象存储)GitLab runner docker安装

GitLab功能及优势

从端到端的管理(包含代码审查、问题跟踪、动态订阅、易于扩展 项目wiki、权限管理、内置CICD)

安装需求

https://docs.gitlab.cn/jh/install/requirements.html

docker安装

https://docs.gitlab.cn/jh/install/docker.html

mkdir /data/gitlab/logs -p && mkdir /data/gitlab/config -p && mkdir /data/gitlab/data -p

export GITLAB_HOME=/data/gitlab

docker run --detach 
  --hostname 10.18.255.76:8090 
  --env GITLAB_OMNIBUS_CONFIG="external_url 'http://10.18.255.76:8090'; gitlab_rails['gitlab_ssh_host'] = 10.18.255.76; gitlab_rails['gitlab_shell_ssh_port'] = 222" 
  --publish 8443:443 --publish 8090:80 --publish 222:22 
  --name gitlab 
  --restart always 
  --volume $GITLAB_HOME/config:/etc/gitlab 
  --volume $GITLAB_HOME/logs:/var/log/gitlab 
  --volume $GITLAB_HOME/data:/var/opt/gitlab 
  --shm-size 256m 
  gitlab-jh.tencentcloudcr.com/omnibus/gitlab-jh:latest

访问极狐GitLab URL,使用用户名 root 和来自以下命令的密码登录:
docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

GitLab runner(类Jenkins slave)

开源,运行作业并将结果发回gitlab与gitlabCI结合使用使用Go编写,可在linux、mac、windows上运行gitlab runner版本要与gitlab版本同步可配置任意数量的runnner aws对象存储保存作业产物

gitlab_rails['artifacts_enabled'] = true
gitlab_rails['artifacts_object_store_enabled'] = true
gitlab_rails['artifacts_object_store_remote_directory'] = "artifacts"
gitlab_rails['artifacts_object_store_connection'] = {
  'provider' => 'AWS',
  'region' => 'eu-central-1',
  'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
  'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY'
}

如果您使用 AWS IAM 配置文件,请省略 AWS 访问密钥和秘密访问密钥/值对。 例如:

gitlab_rails['artifacts_object_store_connection'] = {
  'provider' => 'AWS',
  'region' => 'eu-central-1',
  'use_iam_profile' => true
}
GitLab 作为软件包仓库和容器镜像仓库(支持对象存储)

支持常见格式:go、maven、npm、pypi、helm charts等
https://docs.gitlab.cn/jh/administration/packages/

作为容器镜像仓库:
https://docs.gitlab.cn/jh/administration/packages/container_registry.html

GitLab runner docker安装

参考:
https://docs.gitlab.com/runner/install/
https://blog.csdn.net/wanger5354/article/details/122422513

docker run -itd --restart=always --name gitlab-runner 
-v /data/gitlab-runner/config:/etc/gitlab-runner 
-v /var/run/docker.sock:/var/run/docker.sock  gitlab/gitlab-runner:latest

获取注册令牌,进入容器执行 gitlab-runner register 时会用到,如下所示

# docker exec -it gitlab-runner bash
root@86776be27cab:/# gitlab-runner register
Runtime platform                                    arch=amd64 os=linux pid=35 revision=5316d4ac version=14.6.0
Running in system-mode.                            
                                                   
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://10.18.255.76:8090/
Enter the registration token:
pgidxuuYMhCb8QHZMFKH
Enter a description for the runner:
[86776be27cab]: run1
Enter tags for the runner (comma-separated):
default
Registering runner... succeeded                     runner=pgidxuuY
Enter an executor: custom, parallels, virtualbox, docker+machine, docker-ssh+machine, kubernetes, docker, docker-ssh, shell, ssh:
docker
Enter the default Docker image (for example, ruby:2.6):
docker:18
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded! 
root@86776be27cab:/# gitlab-runner restart
Runtime platform                                    arch=amd64 os=linux pid=49 revision=5316d4ac version=14.6.0
root@86776be27cab:/# gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=97 revision=5316d4ac version=14.6.0
Listing configured runners                          ConfigFile=/etc/gitlab-runner/config.toml
run1                                                Executor=docker Token=zwxrx54W9r9xvDzxn4dp URL=http://10.18.255.76:8090/

顺利的话可以在gitlab 菜单-管理员-管理中心-概览-runner中看到了,状态(在线)。接着在项目main分支里增加.gitlab-ci.yml文件,输入如下内容,即可自动触发流水线

stages:
  - maven
  - build
  - deploy
  
maven_job:
  stage: maven
  tags:
    - default
  only:
    - main
  script:
    - echo "This is the first maven job"
    
build_job:
  stage: build
  tags:
    - default
  only:
    - main
  script:
    -  echo "This is the first build job"

deploy_job:
  stage: deploy
  tags:
    - default
  only:
    - main
  script:
    - echo "This is the first deploy job"
    - echo "hahaha"

效果展示:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/757285.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号