GitLab CICD小记

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"

效果展示:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值