大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
gitlab,gitlab CI/CD相关组件以及介绍
创新互联建站拥有10余年成都网站建设工作经验,为各大企业提供成都做网站、成都网站设计服务,对于网页设计、PC网站建设(电脑版网站建设)、成都app开发、wap网站建设(手机版网站建设)、程序开发、网站优化(SEO优化)、微网站、主机域名等,凭借多年来在互联网的打拼,我们在互联网网站建设行业积累了很多网站制作、网站设计、网络营销经验,集策划、开发、设计、营销、管理等网站化运作于一体,具备承接各种规模类型的网站建设项目的能力。
GitLab CI / CD是GitLab内置的强大工具,允许您将所有连续方法(持续集成,交付和部署)应用于您的软件,而无需第三方应用程序或集成。
.gitlab-ci.yml
)docker基础知识
第一步:开发人员将代码上传到代码仓库,gitlab 根据gitlab-ci.yml中的命令,触发ci/cd逻辑,通知gitlab-runner进行构建部署
第二步:gitlab-runner根据.gitlab-ci.yml脚本进行代码检测,单元测试
第三步: gitlab-runner根据.gitlab-ci.yml脚本进行构建打包
第四步:gitlab-runner根据.gitlab--ci.yml脚本将代码部署到相应的环境中
docker搭建gitlab
docker run -d --publish 22:22 -p 80:80 -p 443:443 --name gitlab --restart unless-stopped -v /data/gitlab/config:/etc/gitlab -v /data/gitlab/logs:/var/log/gitlab -v /data/gitlab/data:/var/opt/gitlab -v /var/run/docker.sock:/var/run/docker.sock twang2218/gitlab-ce-zh:10.5.4
docker启动gitlab-runner
sudo docker run -d --name gitlab-runner --restart=always -v /data/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:v10.6.0
友情链接:gitlab-runner官网安装指南
gitlab-runner注册到gitlab中
gitlab-runner register
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) :输入gitlab地址\
Please enter the gitlab-ci token for this runner:输入gitlab token
Please enter the gitlab-ci description for this runner:输入runner描述信息\
Please enter the gitlab-ci tags for this runner (comma separated):输入runner tag信息\
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:输入runner的类型\
Please enter the Docker image (eg. ruby:2.1):(如果选择docker需要输入镜像)
.gitlab-ci.ym脚本编写
stages:
- test
- build
- deploy
cache:
paths:
- .m2/
variables:
MAVEN_OPTS: "-Dmaven.repo.local=.m2"
MAVEN_IMAGE: registry.cn-beijing.aliyuncs.com/qian/prod:maven3-jdk8
CONTAINER_NAME: daily_report_java
LAN_REPO: registry-vpc.cn-beijing.aliyuncs.com/qian/prod
WAN_REPO: registry.cn-beijing.aliyuncs.com/qian/prod
DEV_REPO: $WAN_REPO/dev
PRED_REPO: $WAN_REPO/pred
PROD_REPO: $LAN_REPO/prod
test and build image:
image: $MAVEN_IMAGE
stage: test
script:
- mvn package docker:build -q -Dmaven.test.skip=false -Dspring.profiles.active=test sonar:sonar -Dsonar.host.url=http://sonar.allhome.com.cn -Dsonar.login=admin -Dsonar.password=admin -Dsonar.projectName=$CONTAINER_NAME
tags:
- maven
only:
- release
build image:
image: $MAVEN_IMAGE
stage: test
script:
- mvn package docker:build -q -Dmaven.test.skip=true
tags:
- maven
only:
- dev
- master
push image dev:
stage: build
before_script:
- docker login --username=阿里云镜像仓库地址 --password="password" registry-vpc.cn-beijing.aliyuncs.com
script:
- echo $version
- docker tag $DEV_REPO:$CONTAINER_NAME $LAN_REPO/qianjia_dev:$CONTAINER_NAME
- docker push $LAN_REPO/qianjia_dev:$CONTAINER_NAME
tags:
- docker-run
only:
- dev
when: on_success
push image master:
stage: build
before_script:
- docker login --username=阿里云镜像仓库地址 --password="password" registry-vpc.cn-beijing.aliyuncs.com
script:
- docker tag $DEV_REPO:$CONTAINER_NAME $LAN_REPO/qianjia_pred:$CONTAINER_NAME
- docker push $LAN_REPO/qianjia_pred:$CONTAINER_NAME
tags:
- docker-run
only:
- release
when: on_success
push image prod:
stage: build
before_script:
- docker login --username=阿里云镜像仓库地址 --password="password" registry-vpc.cn-beijing.aliyuncs.com
script:
- docker tag $DEV_REPO:$CONTAINER_NAME $LAN_REPO/qianjia_prod:$CONTAINER_NAME
- docker push $LAN_REPO/qianjia_prod:$CONTAINER_NAME
tags:
- docker-run
only:
- master
when: on_success
ssh run on remote machine dev:
stage: deploy
script:
- bash ~/.local/bin/200.sh $CONTAINER_NAME 8801 8801 $DEV_REPO:$CONTAINER_NAME guojia 192.168.10.200
tags:
- shell-200
only:
- dev
when: on_success
ssh run on remote machine master:
stage: deploy
script:
- bash ~/.local/bin/deploy.sh $CONTAINER_NAME 8801 8801 $PRED_REPO:$CONTAINER_NAME zp 预生产ip地址
tags:
- shell-prod
only:
- release
when: on_success
ssh run on remote machine prod:
stage: deploy
script:
- bash ~/.local/bin/deploy.sh $CONTAINER_NAME 8801 8801 $PROD_REPO:$CONTAINER_NAME zp 生产ip地址
tags:
- shell-prod
only:
- master
when: on_success
修改pom.xml,添加如下代码
org.springframework.boot
spring-boot-maven-plugin
true