Gitlab-ci.yml

Source: Internet
Author: User
Tags docker run
This is a creation in Article, where the information may have evolved or changed.

A few days ago to do a docker run runner, now want to seem a bit out of the way. The real thing is to pack a Docker image, test it in the mirror, pass the test through to the mirror repository, post it to the test cluster for integration testing, and finally publish it to the production environment.
You are now done testing by packaging the test image and then generating the production image. In order to reduce the size of the production image (Golang image will be nearly 700m,golang:alpine mirror 250M, and Mutil+stage way to package to Alpine base package, only about 10M . Here is a detailed example of a file.
In a project, there is generally only one dockerfile, can not meet the requirements, found that the use of-f dockefile to specify a different file for packaging, but dockerfile.test this with the suffix method is problematic, should be used dockerfiletest this way. See Docker Build

One, package Docker image

First install Docker CE, refer to Docker installation
The Gitlab-runner user is then given Docker execution permissions, or the package will prompt for no permissions.

sudo usermod -aG docker gitlab-runnersudo -u gitlab-runner -H docker info

Very troublesome, how to test first, test pass and then package?
Does the test use a Docker runner to do the test and then use the Shell runner to package the upload release?

The DOCKERFILETEST,DOCKERFILEPROD,GITLAB-CI.YML code under the project root directory is as follows:

# DockerfileTestFROM golang:alpineMAINTAINER panzulong "panzulong@gmail.com"WORKDIR /go/srcCOPY src /go/srccmd ["go","test"]
# DockerfileProd# build product binFROM golang:alpineMAINTAINER panzulong "panzulong@gmail.com"WORKDIR /go/srcCOPY src /go/srcRUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .# build product imageFROM alpine:latestWORKDIR /root/COPY --from=0 /go/src/app .EXPOSE 9090ENTRYPOINT ["./app"]

Gitlab-ci.yml

  # This file was a template, and might need editing before it works on your project.stages:-Go-test-bui Ld-image go-test:stage:go-test Script:-Docker build-f dockerfiletest-t test-student:v0.1.        #把测试专用的dockerfile放到src目录中-docker Run--rm test-student:v0.1 #进行测试, if you do not follow through the following, if you continue to execute after_script through the following: -Docker RMI test-student:v0.1 Tags:-shellbuild-image:stage:build-image before_script:-Docke R login-u Panzl-p * * * * * registry.cacec.com.cn script:-Docker build-f dockerfileprod-t registry.cacec.com.cn        /ms/student:v0.1. -Docker push Registry.cacec.com.cn/ms/student:v0.1-docker images after_script:-Docker Images|gre P None|awk ' {print $} ' |xargs Docker RMI #为了删除中间生成的那个镜像文件 Tags:-Shell  
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.