1. GitLab Docker 镜像库配置
//开启 docker 存储库
$ vim /etc/gitlab/gitlab.rb...registry_external_url 'https://gitlabtest.xiodi.cn:4567'...registry_nginx['enable'] = trueregistry_nginx['ssl_certificate'] = "/etc/gitlab/ssl/1_gitlabtest.xiodi.cn_bundle.crt"registry_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/2_gitlabtest.xiodi.cn.key"...
//更改存储库路径,默认为 /var/opt/gitlab/gitlab-rails/shared/registry
gitlab_rails['registry_path'] = "/path/to/registry/storage"
//存储库路径支持 s3 存储
registry['storage'] = {'s3' => {'accesskey' => 's3-access-key','secretkey' => 's3-secret-key-for-access-key','bucket' => 'your-s3-bucket','region' => 'your-s3-region','regionendpoint' => 'your-s3-regionendpoint'}}
//重启服务后,gitlab 页面如下

2. Docker 构建
由于 docker-in-docker 需要 privileged,所以要修改 runner。
$ vim /data/etc/gitlab-runner/config.toml...[runners.docker]tls_verify = falseimage = "harbor.xiodi.cn/tools/alpine:3.11"privileged = true...$ docker restart gitlab-runner2
需要先把前面测试的 CI_REGISTRY 变量去掉。
//.gitlab.ci.yml
variables:REGISTRY: $CI_REGISTRY/edu-java-demo/edu-java-springMAVEN_OPTS: "-Dmaven.repo.local=.m2"stages:- test- build- packagetest:stage: testimage: harbor.xiodi.cn/tools/openjdk:11.0.6tags:- docker- host20133-dockerscript:- chmod +x ./mvnw && ./mvnw testcache:key: maven-repo-cachepaths:- .m2build:stage: buildimage: harbor.xiodi.cn/tools/openjdk:11.0.6tags:- docker- host20133-dockerscript:- chmod +x ./mvnw && ./mvnw packagecache:key: maven-repo-cachepaths:- .m2artifacts:paths:- target/*.jarexpire_in: 1 weekdocker-package:stage: packageimage: harbor.xiodi.cn/tools/docker:18.09.9services:- docker:18.09-dindtags:- docker- host20133-dockervariables:REGISTRY_VERSION: $CI_COMMIT_SHORT_SHAscript:- export- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY- docker build -t $REGISTRY:$CI_COMMIT_SHORT_SHA -f Dockerfile .- docker push $REGISTRY:$CI_COMMIT_SHORT_SHA
3. Docker 镜像查看

