您好,登錄后才能下訂單哦!
gitlab,gitlab CI/CD相關(guān)組件以及介紹
GitLab CI / CD是GitLab內(nèi)置的強(qiáng)大工具,允許您將所有連續(xù)方法(持續(xù)集成,交付和部署)應(yīng)用于您的軟件,而無需第三方應(yīng)用程序或集成。
.gitlab-ci.yml
)docker基礎(chǔ)知識
第一步:開發(fā)人員將代碼上傳到代碼倉庫,gitlab 根據(jù)gitlab-ci.yml中的命令,觸發(fā)ci/cd邏輯,通知gitlab-runner進(jìn)行構(gòu)建部署
第二步:gitlab-runner根據(jù).gitlab-ci.yml腳本進(jìn)行代碼檢測,單元測試
第三步: gitlab-runner根據(jù).gitlab-ci.yml腳本進(jìn)行構(gòu)建打包
第四步:gitlab-runner根據(jù).gitlab--ci.yml腳本將代碼部署到相應(yīng)的環(huán)境中
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官網(wǎng)安裝指南
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 預(yù)生產(chǎn)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 生產(chǎn)ip地址
tags:
- shell-prod
only:
- master
when: on_success
修改pom.xml,添加如下代碼
<!--熱部署-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 如果沒有該項(xiàng)配置,devtools不會起作用,即應(yīng)用不會restart -->
<fork>true</fork>
</configuration>
</plugin>
<!--
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.3</version>
<configuration>
<imageName>registry.cn-beijing.aliyuncs.com/qian2018/qianjia_dev:${project.artifactId}
</imageName>
<dockerDirectory>.</dockerDirectory>
<resources>
<resource>
<targetPath>target</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>server</id>
<name>releases</name>
<url>http://nexus地址:9000/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>server</id>
<name>snapshots</name>
<url>http://nexusi地址:9000/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://nexus地址:9000/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<name>maven-public</name>
<url>http://39.106.145.141:9000/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
項(xiàng)目根目錄下添加 Dockerfile文件
FROM registry-vpc.cn-beijing.aliyuncs.com/qian/qianjia_public:oraclejdk
VOLUME /tmp
add target/*.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Pipelines 中文稱為流水線,是分階段執(zhí)行的構(gòu)建任務(wù),一次自動發(fā)布流程就稱為一次流水線,以上邊腳本舉例,安裝依賴、運(yùn)行測試、打包、部署開發(fā)服務(wù)器等整套流程叫做一次流水線
Stages:Stages 表示構(gòu)建階段,一次流水線包括多個stages,在腳本實(shí)例中stages定義了一次流水線的三個階段:第一個階段:運(yùn)行測試,進(jìn)行代碼檢測,第二個階段:打包java程序并生成鏡像,第三個階段:執(zhí)行shell腳本,把容器部署到服務(wù)器
Jobs :表示構(gòu)建的作業(yè)(或稱之為任務(wù)),表示某個 Stage 里面執(zhí)行的具體任務(wù)。我們可以在 Stages 里面定義多個 Jobs
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。