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