Gitlab+docker quickly build CI/CD automated deployment

Source: Internet
Author: User
Tags docker ps docker run

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

    1. Gitlab Environment (for convenience, use of the official custodian warehouse)

    2. Installed docker and gitlab-runner Environment Cloud server (used here CentOS 7 64位 )

    3. Project code, here I use Golang as the development language, other development language is the same operation process

      Code. png

    4. DockerfileFile

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"]
    1. gitlab-ci.ymlFile, 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.