实现项目代码从gitlab到rancher的构建
1.gitlab创建账号密码、创建project&repository
2.将代码git clone到本地并用Intellij Idea修改,写gitlab-ci.yml(1.与buildDockerImages.sh协同创建代码镜像并传到harbor上;2.将代码运行在rancher里的docker runner中):
image: registry.8dat.com/library/docker-gradle:3.3
before_script:
- echo "before_script"
stages:
- deploy
deploy app:
stage: deploy
tags:
- docker
script:
- sh buildDockerImages.sh
- docker run -e CATTLE_ACCESS_KEY=AEB1A520BD4F11C11417 -e CATTLE_SECRET_KEY=MrJtwrTerzRkw7aJpyCFgmoyCeHUyt4mzcouFBFq -e CATTLE_URL=http://10.1.107.211:8080/v1 --rm registry.8dat.com/library/rancher-api:0.1 upgrade 1s99 --auto_complete=true --complete_previous=true --delay_complete=1 --timeout=240
buildDockerImages.sh(将代码做成项目镜像并传到harbor上):
docker login registry.tech.unicomlabs.cn -u robot -p Robot2017
docker build -t registry.tech.unicomlabs.cn/prod/dptuser:0.0.1 -f Dockerfile .
docker tag registry.tech.unicomlabs.cn/prod/dptuser:0.0.1 registry.tech.unicomlabs.cn/prod/dptuser:latest
docker push registry.tech.unicomlabs.cn/prod/dptuser:0.0.1
docker push registry.tech.unicomlabs.cn/prod/dptuser:latest
docker rmi registry.tech.unicomlabs.cn/prod/dptuser:0.0.1
docker rmi registry.tech.unicomlabs.cn/prod/dptuser:latest
3.用intellij Idea打开代码目录,点击commit and push,可同时完成1.代码push到gitlab;2.代码运行在rancher docker runner;3.代码镜像被创建并上传到harbor。
网友评论