Travis CIãå©ç¨ããç¶ç¶çãªææç©ã®é ç½®
ããã«ã¡ã¯ã @suzu_v ã§ãã Advent Calendar 2015 18æ¥ç® ä¼è¼ã®ãç¥ãã - VOYAGE GROUP techlog ã¨ã®ãã¨ã ã£ãã®ã§ä»£æã§æ¸ãã¦ã¿ã¾ãã*1
ãã¾ç§ãæå±ãã¦ãã fluct ã§ã¯CIã®ä¸é¨ã«Travis CIãå©ç¨ãã¦ãã¾ããç¨éã¨ãã¦ã¯ã
- ç¶ç¶çãªãã¹ã
- ç¶ç¶çãªãã«ã
ã¨ããã¨ãããæ å½ãã¦ãã¾ããä»æ¥ã¯ç°¡åã«ã
ã®ç´¹ä»ããã¾ãã
Travis Artifacts
travis-ci/artifacts ã¯Travis CIã®ã¢ããªã³ã¨ãã¦å©ç¨ããã¦ãããã®ã§ããã«ãæ¸ã¿ã®artifactsãæ±ããã¨ãã§ãã¾ããç§ãã¡ã¯ä¸é¨ã®ããããAPIãµã¼ãã®å®è£ ã«ã¤ãã¦ãTravis CIãå©ç¨ãããã«ãåã³s3ã¸ã®è»¢éãè¡ã£ã¦ãã¾ãã
ããã¸ã§ã¯ãæ§æã¯æ¦ã以ä¸ã®ããã«ãªã£ã¦ãã¾ãããã®å ´åGoã®ã¢ããªã§ãã
github.com/your-username/your-reponame .travis.yml Gomfile Gomfile.lock Makefile ci.mk cmd/myapp.go kuke.go kuke_test.go
.travis.yml
ã«ã¯ä»¥ä¸ã®ããã«è¨å®ãã¦ãã¾ãã
sudo: false language: go go: - 1.5.2 before_script: - export PATH=$HOME/gopath/bin:$PATH install: make -f ci.mk deps script: - make -f ci.mk test - make -f ci.mk build addons: artifacts: paths: - $(git ls-files -o --exclude-standard | tr "\n" ":") debug: true bucket: your-bucket target-paths: artifacts/$TRAVIS_REPO_SLUG/$TRAVIS_BRANCH s3_region: "ap-northeast-1"
ãã®ããã«ãã㨠s3://your-bucket/artifacts/your_user_name/your_repo_name/branch_name
以ä¸ã«ãã«ãç©ãå±éããã¾ããä¾ãã° github.com/suzuken/gs
ã®masterãã©ã³ãã®ãã«ãã«å¯¾ãã¦ã¯ s3://your-bucket/artifacts/suzuken/gs/master
以ä¸ã«ææç©(artifacts)ãé
ç½®ããã¾ããPull Requestãåºããå ´åã«ãåæ§ã§ããããã¯ãã©ã³ããã¨ã®artifactãs3ã«é
ç½®ããã¾ãããã¹ãããããµã¼ãå´ã§ã¯ãã®artifactã aws s3 cp
ãªã©ã§åå¾ããå©ç¨ãããã¨ãã§ãã¾ããã¡ãªã¿ã«ãã©ã³ã以å¤ã«ãcommit hashãtagãã¨ã«åºããã¨ãããã¨ãã§ãã¾ãã詳ãã㯠travis-ci/artifacts ãã¿ã¦ãã ããã
git ls-files -o --exclude-standard | tr "\n" ":"
ã¨ããã®ã¯ãã£ããããã¨ãgit管çä¸ã§ã¯ç¡ããã¡ã¤ã«ãããªã¹ããããã¨ãããã¨ããã¦ãã¾ãããããããã¨ã§ãã«ãããããã®ã ãs3ã¸ã®ã¢ãããã¼ã対象ã«ãããã¨ãã§ãã¾ãã
ci.mk
ã¨ããã®ã¯CIç¨ã®Makefileã§ããMakefile
ã¯éçºç¨ã«ã ci.mk
ã¯CIã§ä½¿ãããã«ãã¨åãã¦ãã¾ããå®éã«ãããããã£ã¦ãããã¨ã¯ãã¾ãå¤ããã¾ãããããããããã¨ã§ããã¸ã§ã¯ããã¨ã®CIç¨ã®ãã¯ããæãã¦ããã¨ãããã¨ãããããããªãã¾ããä¾ãã°Javaã®ããã¸ã§ã¯ãã§ããã®ä»çµãã¤ãããã¨ããã¨ãã«ã§ãã make -f ci.mk install test build
ããã°ææç©ãã§ãããã¨ããåã決ãã«ãã¦ããã°ããã®ã§ãã
å®éã« ci.mk
ã®ä¸èº«ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ããï¼ããã¸ã§ã¯ãã«ãã£ã¦è¥å¹²ç°ãªãã¾ãããGoã®ããã¸ã§ã¯ãã ã¨æ¦ã以ä¸ã®ããã«ãªãã¾ããï¼
.PHONY: install build test deps BRANCH := master GOOS := linux GOARCH := amd64 deps: go get github.com/mattn/gom gom install test: gom test -v ./... build: myapp.$(GOOS).$(GOARCH).gz -rm myapp.$(GOOS).$(GOARCH) myapp.$(GOOS).$(GOARCH): GOOS=$(GOOS) GOARCH=$(GOARCH) gom build -ldflags "-X=main.version=$(shell git rev-parse HEAD)" cmd/myapp.go mv myapp $@ myapp.$(GOOS).$(GOARCH).gz: myapp.$(GOOS).$(GOARCH) gzip -f $< clean: -rm -rf myapp.$(GOOS).$(GOARCH) -rm -rf myapp.$(GOOS).$(GOARCH).gz
ä¾åã®ç®¡çã«ã¯ mattn/gom ãå©ç¨ãã¦ãã¾ããGoçã®Bundlerã®ãããªãã®ã§ããs3ã¸ã®è»¢é㯠myapp.linux.arm64.gz
ã ããé
ç½®ãããã¨ãããã¨ã«ãããã®ã§é©å½ã«æ´çãã¦ãã¾ãã
Travis CIããS3ã¸ã®è»¢éã«ã¤ãã¦ã¯credentialãå¿ è¦ã«ãªãã¾ããããã¯Travis CIã®ããã¸ã§ã¯ãè¨å®ã§ãç°å¢å¤æ°ããèªã¿è¾¼ã¾ãããã¨ãã§ãã¾ãã Uploading Artifacts on Travis CI - Travis CI ã«æ¸ãã¦ããã¨ããããªãã¸ããªã®è¨å®ãã以ä¸ãè¨å®ãã¾ãã
ARTIFACTS_KEY=(AWS access key id) ARTIFACTS_SECRET=(AWS secret access key) ARTIFACTS_BUCKET=(S3 bucket name)
Bucketã«ã¤ãã¦ã¯ .travis.yml
ã«è¨å®ãã¦ãããã§ããããTravis CIå´ã§ã¯testãéããªãã¨buildãå®è¡ãããªãããã«ãã¦ããã®ã§ãããã§ãã«ããéã£ããã®ã®ã¿s3ã«é
ç½®ããããã¨ãããã¨ã«ãªãã¾ãã
以ä¸ãç°¡åã§ãã代æã§ãããææ¥ã¯ @qooh0 ããã§ãã
å°ãã¿
*1:決ãã¦Travis CIã®ãã«ããè©°ã¾ã£ã¦ããã®ã§æ¯æãã«æ¸ãã¦ããããã§ã¯ããã¾ããã Travis CI Status - Start delays on legacy precise infrastructure for travis-ci.com (private) builds