docker安装gitlab并部署CICD
摘要
本文主要实现了在docker下安装gitlab,将gitlab绑定在宿主机的180端口,将gitlab的clone的URL添加指定端口号;部署了CI/CD,并公布了测试项目。
安装docker[1]
- 删除旧版本的docker(如果未安装则忽略)
sudo apt-get remove docker docker-engine docker.io containerd runc
安装依赖
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加仓库
# x86_64
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable" # armf
sudo add-apt-repository \
"deb [arch=armhf] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable" # arm64
sudo add-apt-repository \
"deb [arch=arm64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
安装
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
docker换源
注册阿里云账号
选择容器镜像服务

执行命令
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://uy81mm79.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker安装gitlab[2] [3]
创建运行目录
sudo mkdir /opt/gitlab_docker
cd /opt/gitlab_docker
安装docker-compose
sudo apt install docker-compose
编写docker-compose.yml
version: '3.1'
services:
gitlab:
image: 'gitlab/gitlab-ce'
container_name: "gitlab"
restart: always
privileged: true
hostname: 'gitlab'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.196.1'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['smtp_enable'] = true
gitlab_rails['gitlab_shell_ssh_port'] = 22
ports:
- '181:80'
- '180:180'
- '1443:443'
- '22:22'
volumes:
- /opt/gitlab_docker/config:/etc/gitlab
- /opt/gitlab_docker/data:/var/opt/gitlab
- /opt/gitlab_docker/logs:/var/log/gitlab
安装gitlab镜像
sudo docker-compose up -d
修改文件配置
sudo vim /opt/gitlab_docker/config/gitlab.rb
修改
nginx['listen_port']nginx['listen_port'] = 180
修改
external_urlexternal_url 'http://192.168.196.1:180'
重新启动
sudo docker exec -it $CONTINER_ID gitlab-ctl restart
CI/CD依赖
使用docker安装gitlab-runner也是可以的,但是感觉有bug,可能会不成功,这里介绍了我成功的方法。
安装gitlab-runner
找到对应包下载安装。下载地址https://gitlab-runner-downloads.s3.amazonaws.com/latest/index.html.
sudo dpkg -i gitlab-runner_amd64.deb
启动运行gitlab-runner
# 允许开机自启动
systemctl enable gitlab-runner
# 启动服务
systemctl start gitlab-runner
项目测试
创建项目
新建项目,项目文件如下:

.gitlab-ci.yml
# This file is a template, and might need editing before it works on your project.
# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: ubuntu:bionic
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
# before_script:
# - apt update && apt -y install make autoconf
script:
- g++ hello.cpp -o mybinary
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- chmod +x runmytests.sh
- ./runmytests.sh
hello.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
return 0;
}
runmytests.sh
./mybinary
项目文件说明
.gitlab-ci.yml就是自动化测试的配置文件,相关内容可参见[4],建议大家仔细阅读该配置文件即可理解该项目。
gitlab-runner注册
查找api


注册
执行命令:
sudo gitlab-runner register
输入相关参数,下面内容引用自[2:1]
# 输入 GitLab 地址
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.199.109/
# 输入 GitLab Token
Please enter the gitlab-ci token for this runner:
1Lxq_f1NRfCfeNbE5WRh
# 输入 Runner 的说明
Please enter the gitlab-ci description for this runner:
可以为空
# 设置 Tag,可以用于指定在构建规定的 tag 时触发 ci
Please enter the gitlab-ci tags for this runner (comma separated):
deploy
# 这里选择 true ,可以用于代码上传后直接执行(根据版本,也会没有此选项)
Whether to run untagged builds [true/false]:
true
# 这里选择 false,可以直接回车,默认为 false(根据版本,也会没有此选项)
Whether to lock Runner to current project [true/false]:
false
# 选择 runner 执行器,这里我们选择的是 shell
Please enter the executor: virtualbox, docker+machine, parallels, shell, ssh, docker-ssh+machine, kubernetes, docker, docker-ssh:
shell
重启gitlab-runner
systemctl restart gitlab-runner
自动测试
此时,应该是已经自动进行了测试了:

参考文献
注意:[2:2]是[3:1]的视频笔记,因此需要配合[3:2]使用。
docker安装gitlab并部署CICD的更多相关文章
- 解决 Windows Docker 安装 Gitlab Volume 权限问题
本文首发于我的个人博客,解决 Windows Docker 安装 Gitlab Volume 权限问题 ,欢迎访问! 记录一下 Windows10 下 Docker 安装 Gitlab 的步骤. Ca ...
- Docker安装Gitlab
一.Ubuntu16.4上Docker安装Gitlab 1.安装docker 参见:https://docs.docker.com/engine/installation/linux/ubuntuli ...
- 利用docker安装gitlab
安装docker 安装 virtualbox 下载 dockertoolbox并安装 官网的服务器一直连不上, 幸亏还有这个 https://get.daocloud.io/toolbox/ 比 ht ...
- docker 安装gitlab
# docker 安装gitlab # 一.安装镜像(官网文档) export GITLAB_HOME=/srv/gitlab # 必须先设置它,它就是你存储代码仓库的位置.以后要移植的时候直接把这个 ...
- Docker安装GitLab与Runner(网关),常规设置,自动化用到k8s+token
[转]图文详解k8s自动化持续集成之GitLab CI/CD Windows里面使用Debian命令行工具完成 和Docker网络相关的命令 查看某一个容器的网络 docker inspect 容器I ...
- centos7下使用docker安装gitlab
环境背景: Docker化已经成为一种热门,记录一下使用docker引擎安装gitlab的过程. 测试环境: 系统 软件 依赖 CentOS 7.4 GitLab(latest) docker-ce ...
- Debian9 使用 Docker 安装 gitlab完整过程
一. 安装Docker CE (参考 官网指南) 1. 卸载老版本 sudo apt-get remove docker docker-engine docker.io 2. Update the ...
- docker安装Tomcat软件,部署项目
1 搜索tomcat镜像 $ sudo docker search tomcat NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tom ...
- Centos7 docker安装GitLab
*先决条件系统已安装Docker 1.查询GitLab镜像 docker search gitlab 2.现在GitLab镜像 3.创建文件夹 mkdir -p /software/gitlab/co ...
随机推荐
- 数据可视化之powerBI基础(一) 如何查看PowerBI图表背后的数据
https://zhuanlan.zhihu.com/p/64405494 图表很直观,但有时候我们不仅想看图,也想更进一步查看生成该图表的明细数据,在PowerBI中有三种方式. (一)在图表上单击 ...
- Linux05 /nginx
Linux05 /nginx 目录 Linux05 /nginx 1. nginx安装.配置 2. nginx的多虚拟主机功能 3. nginx的访问日志功能,404页面功能 4. nginx的反向代 ...
- bzoj3446[Usaco2014 Feb]Cow Decathlon*
bzoj3446[Usaco2014 Feb]Cow Decathlon 题意: FJ有n头奶牛.FJ提供n种不同的技能供奶牛们学习,每头奶牛只能学习一门技能,每门技能都要有奶牛学习. 第i头奶牛学习 ...
- log4j系统日志(转载)
地址:http://www.codeceo.com/log4j-usage.html 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录.在a ...
- linux 安装 mysql8
1. 下载地址: https://dev.mysql.com/downloads/file/?id=484922 2. 安装 mysql80-community-release-el7-3.noarc ...
- 牛客练习赛66A题解
思路 令 \(sq=\sqrt x\) ,则答案必然在 $ sq^2$ 和 $ (sq+1)^2 $ 之间,两者比较一下谁离 \(x\) 最近,就是答案了. 代码 #include <bits/ ...
- [日常摘要] -- zookeeper篇
概览 设计目标 是将那些复杂且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集,并以一系列简单易用的接口提供给用户使用 简介 是一个典型的分布式数据一致性解决方案,分布式应用程序可以基于Z ...
- 为什么在SpringBoot+maven的项目中,所引入的依赖包可以不指定依赖的版本号?
当在Springboot项目中引入了spring-boot-starter-parent,则可以不用引入依赖包版本号,比如: <parent> <groupId>org.spr ...
- C#计算数组的算术平均数、几何平均数、调和平均数、平方平均数和中位数
1.函数实现 0)打印数组 /// <summary> /// 打印数组 /// </summary> /// <param name="arr"&g ...
- 你的JavaBean是否真的需要实现Serializable
众所周知 如果一个对象需要进行网络传输,那么该对象就需要实现Serializable接口,为了防止反序列失败,该对象需提供一个默认的serialVersionUID(该值在反序列化的时候会进行校验校验 ...