GitLab是由GitLabInc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具备wiki和issue跟踪功能。使用Git做为代码管理工具,并在此基础上搭建起来的web服务。html
git
# docker pull gitlab/gitlab-ce:latest # 官方版本是:gitlab/gitlab-ce:latest,为了提高速度咱们这里使用阿里云的仓库 docker pull registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce:latest docker tag registry.cn-hangzhou.aliyuncs.com/imooc/gitlab-ce gitlab/gitlab-ce
运行GitLab容器web
sudo docker run --detach \ --hostname gitlab.example.com \ --env GITLAB_OMNIBUS_CONFIG="external_url 'http://my.domain.com/'; gitlab_rails['lfs_enabled'] = true;" \ --publish 443:443 --publish 80:80 --publish 23:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab \ --volume /srv/gitlab/logs:/var/log/gitlab \ --volume /srv/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce:latest
查看安装日志docker
docker logs --follow gitlab
vim /srv/gitlab/config/gitlab.rb external_url 'http://47.111.84.191/' service docker restart
设置密码
安装完成后登陆80端口访问,进行设置登陆密码,我这里设置 root Root123456 ,而后进行登陆便可shell
PowerShell
。Windows PowerShell
,而后选择Run as administrator
。# https://docs.gitlab.com/runner/register/index.html # 1-运行如下命令 gitlab-runner.exe register # 2-输入您的GitLab实例URL http://47.111.84.191/ # 3-输入您得到的Token # 在项目的 Settings->Pipelines中能够找到 JGGzoYj_uQoxQVGjWnKn # 4-输入Runner的描述,您能够稍后在GitLab的UI中更改 local-win # 5-输入与Runner关联的tags,您能够稍后在GitLab的UI中更改,能够不输入 # 6-输入Runner执行程序: shell
SSH 链接GitLab
官方文档:https://docs.gitlab.com/ee/ssh/README.html#generating-a-new-ssh-key-pair
若是 C:\Users\Administrator\.ssh 目录下有则可使用已经存在的SSH key。
生成SSHvim
ssh-keygen -o -t rsa -b 4096 -C "786744873@qq.com"
SSH 链接 22 端口
正常状况下你已经能够经过git命令来链接咱们部署的gitlab,但这里不同的是咱们把容器的 22端口映射到了 host的 23上,咱们须要指定端口来进链接。windows
ssh -p 23 git@47.111.84.191
C:\Users\Administrator\.ssh>ssh -p 23 git@47.111.84.191 The authenticity of host '[47.111.84.191]:23 ([47.111.84.191]:23)' can't be established. ECDSA key fingerprint is SHA256:DAQttfMOxIIiNqgt/QIvL6tv1pwgPax/fsnBprwZhN0. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[47.111.84.191]:23' (ECDSA) to the list of known hosts. Enter passphrase for key 'C:\Users\Administrator/.ssh/id_rsa': PTY allocation request failed on channel 0 Welcome to GitLab, wyt! Connection to 47.111.84.191 closed.
添加项目初始化网络
# Git global setup git config --global user.name "wyt" git config --global user.email "786744873@qq.com" # Create a new repository git clone git@47.111.84.191:wyt/beta2.git cd beta2 touch README.md git add README.md git commit -m "add README" git push -u origin master # Existing folder # cd existing_folder git init git remote add origin git@47.111.84.191:wyt/beta2.git git add . git commit -m "Initial commit" git push -u origin master # Existing Git repository cd existing_repo git remote rename origin old-origin git remote add origin git@47.111.84.191:wyt/beta2.git git push -u origin --all git push -u origin --tags
编辑.gitlab-ci.yml 执行任务
咱们只须要在根目录添加 .gitlab-ci.yml 输入两行命令便可。dom
rtest: script: - cd User.API - docker-compose up -d --build --force-recreate