First, the preparatory work
Second, the Environment configuration
Third, submit the update and automatically deploy to the server, test address: http://182.61.57.121:8000
First, the preparatory work
Gitlab Environment (for convenience, use of the official custodian warehouse)
Installed docker
and gitlab-runner
Environment Cloud server (used here CentOS 7 64位
)
Project code, here I use Golang as the development language, other development language is the same operation process
Code. png
Dockerfile
File
FROM golang:latestMAINTAINER Razil "412657308@qq.com"WORKDIR $GOPATH/src/kun.com/cicd-demoCOPY . $GOPATH/src/kun.com/cicd-demoRUN go build .EXPOSE 8000ENTRYPOINT ["./cicd-demo"]
gitlab-ci.yml
File, Syntax view
stages: - deploydocker-deploy: stage: deploy # 执行Job内容 script: # 通过Dockerfile生成cicd-demo镜像 - docker build -t cicd-demo . # 删除已经在运行的容器 - if [ $(docker ps -aq --filter name= cicd-demo) ]; then docker rm -f cicd-demo;fi # 通过镜像启动容器,并把本机8000端口映射到容器8000端口 - docker run -d -p 8000:8000 --name cicd-demo cicd-demo tags: # 执行Job的服务器 - kun only: # 只有在master分支才会执行 - master
Second, the Environment configuration
1. Runner server that performs deployment tasks for project registrations
Because I have already configured, so the following Runner,runner label is more runner perform the task when the identity of the distinction, the subsequent deployment process I will use the label instead of the kun
test
server to perform the job, the following configuration process.
1.gitlab Setup Runner.jpg
2. Cloud Server Registration Runner
2. Server configuration. png
Iii. Submission of updates and automatic deployment to the server
After the runner is registered successfully, the GIT command commits the update to the Master branch, and the job task is performed as long as the master branch is modified.
3.1. Submit the code to the GIT Master branch. png
3.2. Wait for the job task to complete. Png4. View the job execution task process. png
At this point, the link http://182.61.57.121:8000 can be accessed to the server already deployed code and can be accessed normally.
4. Test results. png
Extension: By practicing Gitflow workflow, you can have a convenient and efficient system continuous integration program.