1。运行一个runner
docker run --name runner -d -v /var/run/docker.sock:/var/run/docker.sock -v /gitlab-runner/config/:/etc/gitlab-runner gitlab/gitlab-runner:ubuntu-v14.6.1
2.进入容器启动一个runner
gitlab-runner register \
--non-interactive \
--executor "docker" \
--docker-image "golang:alpine" \
--url "http://192.168.8.10/" \
--registration-token "bTYW9wdU_M9nv1Kx_4Vi" \
--description "node-runner" \
--tag-list "docker,golang" \
--run-untagged="true" \
--locked="false" \
--access-level="not_protected"
3 .vim /gitlab-runner/config/config.toml 添加以下参数
volumes = ["/var/run/docker.sock:/var/run/docker.sock","/cache"]
如下 重启生效
docker restart runner
最后YAML
cache:
paths:
- app
stages:
- package
- docker_build
- deploy
package build_job3:
stage: package
tags:
- golang
script:
- export GO111MODULE=on
- export GOPROXY=https://goproxy.cn
- go mod init app
- go mod tidy
- go build .
only:
- main
docker_build_job2:
image: docker:stable
stage: docker_build
tags:
- golang
script:
- docker build -t $HK:$CI_COMMIT_SHORT_SHA .
- docker login --username=$DOCKER_NAME --password=$DOCKER_PW $HK
- docker push $HK:$CI_COMMIT_SHORT_SHA
deploy_job3:
image: docker:stable
stage: deploy
tags:
- golang
script:
- docker pull $HK:$CI_COMMIT_SHORT_SHA
- docker rm -f web
- docker run -d --name web -p8080:80 $HK:$CI_COMMIT_SHORT_SHA
only:
- main
现在估计是版本原因吧,docker in docker已经不生效了,以前的版本是dockers in dockers生效的现在不知道为什么不行了,所以看了官网也是推荐这个方式 官网参考
|