摘要:介紹在本文中,我們將介紹如何使用,和創(chuàng)建一個(gè)簡(jiǎn)單的持續(xù)集成過(guò)程。
介紹
在本文中,我們將介紹如何使用Github,Travis-CI和Docker Hub創(chuàng)建一個(gè)簡(jiǎn)單的持續(xù)集成過(guò)程。
項(xiàng)目這次使用的一個(gè)項(xiàng)目是自己寫的一個(gè)爬蟲(chóng)小程序(https://github.com/Han-Ya-Jun...
項(xiàng)目目錄news_watch_notice ├── cmd //main ├── conf ├── dis ├── Dockerfile ├── Makefile ├── pkg ├── qrcode ├── .travis.yml ├── README.md ├── vendor ├── utilsDockerfile
FROM alpine:3.6 MAINTAINER hanyajun0123@gmail.com RUN apk update && apk add curl bash tree tzdata && cp -r -f /usr/share/zoneinfo/Hongkong /etc/localtime ADD news_watch_notice /usr/bin/ ADD news_watch_notice.sha /usr/bin/ CMD ["news_watch_notice"]makefile
TARGET=news_watch_notice PKG=$(TARGET) TAG=latest IMAGE_PREFIX?=hanyajun IMAGE_PREFIX_PRD=hanyajun TARGET_IMAGE_DEV=$(IMAGE_PREFIX)/$(TARGET):$(TAG) TARGET_IMAGE_PRD=$(IMAGE_PREFIX_PRD)/$(TARGET):$(TAG) all: image $(TARGET): CGO_ENABLED=0 go build -o dist/$(TARGET) $(PKG)/cmd gitlog: target: mkdir -p dist git log | head -n 1 > dist/news_watch_notice.sha docker run --rm -i -v `pwd`:/go/src/$(PKG) -w /go/src/$(PKG) golang:1.11.5 make $(TARGET) image-dev: target cd dist && cp ../Dockerfile ./ && docker build -t $(TARGET_IMAGE_DEV) . push-dev: docker push $(TARGET_IMAGE_DEV) image-prd: target cd dist && cp ../Dockerfile ./ && docker build -t $(TARGET_IMAGE_PRD) . push-prd: docker push $(TARGET_IMAGE_PRD) clean: rm -rf dist .PHONY: image target clean push $(TARGET).travis.yml
language: go go: # 語(yǔ)言版本號(hào) - "1.11.5" # 默認(rèn)使用最新版本,注意,需要 "1.10" 版本的時(shí)候必須表示為字符串形式,如果寫成 1.10 則會(huì)使用 1.1 版本;x表示對(duì)應(yīng)前綴的最新版本 services: - docker #需要的docker環(huán)境 install: - make image-dev #build script: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - make push-dev # pushtravis的配置(https://travis-ci.org) 打開(kāi)項(xiàng)目ci開(kāi)關(guān) 設(shè)置docker hub的用戶和密碼環(huán)境變量(push需要登錄認(rèn)證)
DOCKER_PASSWORD DOCKER_USERNAME提交項(xiàng)目代碼觸發(fā)ci 部分ci日志
docker_mtu docker stop/waiting docker start/running, process 3638 services 0.02s$ sudo service docker start start: Job is already running: docker Updating gimme git.checkout 0.85s$ git clone --depth=50 --branch=master https://github.com/Han-Ya-Jun/news_watch_notice.git Han-Ya-Jun/news_watch_notice Cloning into "Han-Ya-Jun/news_watch_notice"... $ cd Han-Ya-Jun/news_watch_notice $ git checkout -qf e05633a1c6e0c3289c85aedf28461b718fe1af13 $ travis_export_go 1.11.5 github.com/Han-Ya-Jun/news_watch_notice Setting environment variables from repository settings $ export DOCKER_PASSWORD=[secure] $ export DOCKER_USERNAME=[secure] $ export GOBIN=$GOPATH/src/bin 6.93s$ travis_setup_go go version go1.11.5 linux/amd64 $ export GOPATH="/home/travis/gopath" $ export PATH="/home/travis/gopath/bin:/home/travis/.gimme/versions/go1.11.5.linux.amd64/bin:/home/travis/bin:/home/travis/bin:/home/travis/.local/bin:/opt/pyenv/shims:/home/travis/.phpenv/shims:/home/travis/perl5/perlbrew/bin:/home/travis/.nvm/versions/node/v8.9.1/bin:/home/travis/.kiex/elixirs/elixir-1.4.5/bin:/home/travis/.kiex/bin:/home/travis/.rvm/gems/ruby-2.4.1/bin:/home/travis/.rvm/gems/ruby-2.4.1@global/bin:/home/travis/.rvm/rubies/ruby-2.4.1/bin:/home/travis/gopath/bin:/home/travis/.gimme/versions/go1.7.4.linux.amd64/bin:/usr/local/phantomjs/bin:/usr/local/phantomjs:/usr/local/neo4j-3.2.7/bin:/usr/local/maven-3.5.2/bin:/usr/local/cmake-3.9.2/bin:/usr/local/clang-5.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/travis/.rvm/bin:/home/travis/.phpenv/bin:/opt/pyenv/bin:/home/travis/.yarn/bin" $ export GO111MODULE="auto" $ gimme version v1.5.3 $ go version go version go1.11.5 linux/amd64 go.env $ go env GOARCH="amd64" GOBIN="/home/travis/gopath/src/bin" GOCACHE="/home/travis/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/travis/gopath" GOPROXY="" GORACE="" GOROOT="/home/travis/.gimme/versions/go1.11.5.linux.amd64" GOTMPDIR="" GOTOOLDIR="/home/travis/.gimme/versions/go1.11.5.linux.amd64/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build083711362=/tmp/go-build -gno-record-gcc-switches" install 43.66s$ make image-dev mkdir -p dist git log | head -n 1 > dist/news_watch_notice.sha docker run --rm -i -v `pwd`:/go/src/news_watch_notice -w /go/src/news_watch_notice golang:1.11.5 make news_watch_notice Unable to find image "golang:1.11.5" locally 1.11.5: Pulling from library/golang 22dbe790f715: Pulling fs layer 0250231711a0: Pulling fs layer 6fba9447437b: Pulling fs layer c2b4d327b352: Pulling fs layer 619f4932b7ea: Pulling fs layer e2fd6cbd3c6f: Pulling fs layer 1d96446d2b20: Pulling fs layer c2b4d327b352: Waiting e2fd6cbd3c6f: Waiting 1d96446d2b20: Waiting 619f4932b7ea: Waiting 6fba9447437b: Verifying Checksum 6fba9447437b: Download complete 0250231711a0: Download complete 22dbe790f715: Verifying Checksum 22dbe790f715: Download complete c2b4d327b352: Verifying Checksum c2b4d327b352: Download complete 619f4932b7ea: Verifying Checksum 619f4932b7ea: Download complete 1d96446d2b20: Verifying Checksum 1d96446d2b20: Download complete e2fd6cbd3c6f: Verifying Checksum e2fd6cbd3c6f: Download complete 22dbe790f715: Pull complete 0250231711a0: Pull complete 6fba9447437b: Pull complete c2b4d327b352: Pull complete 619f4932b7ea: Pull complete e2fd6cbd3c6f: Pull complete 1d96446d2b20: Pull complete Digest: sha256:342872745847966ab630e9cc5b6980ed3fe7f4e3ea44b10efac995575730c9b8 Status: Downloaded newer image for golang:1.11.5 CGO_ENABLED=0 go build -o dist/news_watch_notice news_watch_notice/cmd cd dist && cp ../Dockerfile ./ && docker build -t [secure]/news_watch_notice:latest . Sending build context to Docker daemon 14.78MB Step 1/6 : FROM alpine:3.6 3.6: Pulling from library/alpine 5a3ea8efae5d: Pulling fs layer 5a3ea8efae5d: Verifying Checksum 5a3ea8efae5d: Download complete 5a3ea8efae5d: Pull complete Digest: sha256:ee0c0e7b6b20b175f5ffb1bbd48b41d94891b0b1074f2721acb008aafdf25417 Status: Downloaded newer image for alpine:3.6 ---> 43773d1dba76 Step 2/6 : MAINTAINER [secure]0123@gmail.com ---> Running in 1f4d4d0db1cb ---> 0eadcccd5d22 Removing intermediate container 1f4d4d0db1cb Step 3/6 : RUN apk update && apk add curl bash tree tzdata && cp -r -f /usr/share/zoneinfo/Hongkong /etc/localtime ---> Running in 7f859dd06afc fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz v3.6.5-39-gbdcdc921e8 [http://dl-cdn.alpinelinux.org/alpine/v3.6/main] v3.6.5-34-gf0ba0b43d5 [http://dl-cdn.alpinelinux.org/alpine/v3.6/community] OK: 8442 distinct packages available (1/11) Installing ncurses-terminfo-base (6.0_p20171125-r1) (2/11) Installing ncurses-terminfo (6.0_p20171125-r1) (3/11) Installing ncurses-libs (6.0_p20171125-r1) (4/11) Installing readline (6.3.008-r5) (5/11) Installing bash (4.3.48-r1) Executing bash-4.3.48-r1.post-install (6/11) Installing ca-certificates (20161130-r2) (7/11) Installing libssh2 (1.8.2-r0) (8/11) Installing libcurl (7.61.1-r2) (9/11) Installing curl (7.61.1-r2) (10/11) Installing tree (1.7.0-r0) (11/11) Installing tzdata (2019a-r0) Executing busybox-1.26.2-r11.trigger Executing ca-certificates-20161130-r2.trigger OK: 17 MiB in 24 packages ---> f923b8dbfbf2 Removing intermediate container 7f859dd06afc Step 4/6 : ADD news_watch_notice /usr/bin/ ---> a855f5307179 Step 5/6 : ADD news_watch_notice.sha /usr/bin/ ---> 9014ba35ce0f Step 6/6 : CMD news_watch_notice ---> Running in 109449b18721 ---> acb6623feb46 Removing intermediate container 109449b18721 Successfully built acb6623feb46 Successfully tagged [secure]/news_watch_notice:latest 0.49s$ echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin Login Succeeded The command "echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin" exited with 0. 5.21s$ make push-dev docker push [secure]/news_watch_notice:latest The push refers to a repository [docker.io/[secure]/news_watch_notice] c0546ad83870: Preparing 869b27ab7e53: Preparing 47b50a8202a0: Preparing 721384ec99e5: Preparing 721384ec99e5: Layer already exists c0546ad83870: Pushed 47b50a8202a0: Pushed 869b27ab7e53: Pushed latest: digest: sha256:74a706f3f8b5b2ead4a7722ca72d8f1eaa450801847662402e4e3e34f4d73158 size: 1157 The command "make push-dev" exited with 0.成功將項(xiàng)目打包成image并推送到docker hub上
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/27838.html
摘要:簡(jiǎn)介是目前新興的開(kāi)源持續(xù)集成構(gòu)建項(xiàng)目,它與,的很明顯的特別在于采用格式,簡(jiǎn)潔清新獨(dú)樹(shù)一幟。目前大多數(shù)的項(xiàng)目都已經(jīng)移入到的構(gòu)建隊(duì)列中,據(jù)說(shuō)每天運(yùn)行超過(guò)次完整構(gòu)建。查看構(gòu)建情況增加逼格首先要是一個(gè)文檔。是由提供的真實(shí)的構(gòu)建情況。 Travis簡(jiǎn)介 Travis CI(continuous integration )是目前新興的開(kāi)源持續(xù)集成構(gòu)建項(xiàng)目,它與jenkins,GO的很明顯的特別在于...
摘要:集成測(cè)試完成后,由運(yùn)維同學(xué)從發(fā)起一個(gè)到分支,此時(shí)會(huì)會(huì)運(yùn)行單元測(cè)試,構(gòu)建鏡像,并發(fā)布到預(yù)發(fā)布環(huán)境測(cè)試人員在預(yù)發(fā)布環(huán)境下再次驗(yàn)證功能,團(tuán)隊(duì)做上線前的其他準(zhǔn)備工作運(yùn)維同學(xué)合并,將為本次發(fā)布的代碼及鏡像自動(dòng)打上版本號(hào)并書(shū)寫,同時(shí)發(fā)布到生產(chǎn)環(huán)境。 云原生 (Cloud Native) 是伴隨的容器技術(shù)發(fā)展出現(xiàn)的的一個(gè)詞,最早出自 Pivotal 公司(即開(kāi)發(fā)了 Spring 的公司)的一本技術(shù)小...
摘要:集成測(cè)試完成后,由運(yùn)維同學(xué)從發(fā)起一個(gè)到分支,此時(shí)會(huì)會(huì)運(yùn)行單元測(cè)試,構(gòu)建鏡像,并發(fā)布到預(yù)發(fā)布環(huán)境測(cè)試人員在預(yù)發(fā)布環(huán)境下再次驗(yàn)證功能,團(tuán)隊(duì)做上線前的其他準(zhǔn)備工作運(yùn)維同學(xué)合并,將為本次發(fā)布的代碼及鏡像自動(dòng)打上版本號(hào)并書(shū)寫,同時(shí)發(fā)布到生產(chǎn)環(huán)境。 云原生 (Cloud Native) 是伴隨的容器技術(shù)發(fā)展出現(xiàn)的的一個(gè)詞,最早出自 Pivotal 公司(即開(kāi)發(fā)了 Spring 的公司)的一本技術(shù)小...
摘要:所以一直沒(méi)能把持續(xù)集成搞起來(lái)。后來(lái)接觸到,所以嘗試了一下把持續(xù)集成搭建在上了,通過(guò)下面這幾步就可以實(shí)現(xiàn)項(xiàng)目有新的提交后自己編譯發(fā)布測(cè)試包到上了。 由于本人精力有限,如果內(nèi)容有更新可能無(wú)法及時(shí)更新其他渠道的內(nèi)容,請(qǐng)移步簡(jiǎn)書(shū) 查看文章 由于之前公司項(xiàng)目一直迭代速度很快,幾乎隔幾天就需要發(fā)布測(cè)試包給同事們進(jìn)行測(cè)試,所以希望把打包Apk這個(gè)工作交給機(jī)器來(lái)做,然后就嘗試了幾種持續(xù)集成的方案,最常...
閱讀 1250·2023-04-26 01:38
閱讀 1462·2021-11-15 11:39
閱讀 3251·2021-09-22 15:43
閱讀 2638·2019-08-30 15:55
閱讀 2047·2019-08-30 14:17
閱讀 2851·2019-08-29 14:16
閱讀 3062·2019-08-26 18:36
閱讀 2607·2019-08-26 12:19