Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
add ci cd setting (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuke Kato authored Jan 17, 2019
1 parent 045fa07 commit 03a23e3
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 22 deletions.
228 changes: 207 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,227 @@
version: 2
machine:
golang:
version: 1.11
jobs:
build:
alias:
default: &default
working_directory: /go/src/github.com/yahoojapan/ngtd
docker:
- image: circleci/golang:1.11
- image: circleci/golang:1.11.4
environment:
GO15VERNDOREXPERIMENT: 1
GOPATH: "/go"
GO111MODULE: "on"
LD_LIBRARY_PATH: /usr/local/lib
NGT_VERSION: 1.4.5
GO111MODULE: "on"
REPO_NAME: "yahoojapan"
IMAGE_NAME: "ngtd"
GITHUB_API: "https://api.github.com/"
DOCKER_USER: "kpango"
- image: redis
environment:
TEST_RESULTS: /tmp/test-results
setup_remote_docker: &setup_remote_docker
version: 18.06.0-ce
docker_layer_caching: true

version: 2
jobs:
test:
<<: *default
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- restore_cache:
key: gosum-{{ .Branch }}-{{ checksum "go.sum" }}
- run:
name: install dependencies
command: |
sudo apt-get update
sudo apt-get install cmake
sudo -E make deps
- run:
name: install go tools
name: preparation
command: |
go mod vendor
- run:
name: run tests
command: |
rm -rf example
go test -v -race -covermode=atomic -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
bash <(curl -s https://codecov.io/bash)
- store_artifacts:
path: ./coverage.html
- save_cache:
key: gosum-{{ .Branch }}-{{ checksum "go.sum" }}
paths:
- ./vendor
build:
<<: *default
steps:
- setup_remote_docker: *setup_remote_docker
- checkout
- run:
name: check docker version
command: |
go get -u -v github.com/jstemmer/go-junit-report
docker version
- run:
name: build
name: docker image build
command: |
mkdir -p $TEST_RESULTS
go build -ldflags="-s -w" -v
# env DOCKER_BUILDKIT=1 docker build -t ${REPO_NAME}/${IMAGE_NAME}:latest .
docker build -t ${REPO_NAME}/${IMAGE_NAME}:latest .
- run:
name: save image
command: |
docker image save ${REPO_NAME}/${IMAGE_NAME}:latest > ./docker-image.tar
- persist_to_workspace:
root: .
paths:
- .
publish_nightly:
<<: *default
steps:
- setup_remote_docker: *setup_remote_docker
- attach_workspace:
at: .
- run:
name: test
name: load image from tar
command: |
trap "go-junit-report < ${TEST_RESULTS}/go-test.out > ${TEST_RESULTS}/go-test-report.xml" EXIT
./coverage.sh | tee ${TEST_RESULTS}/go-test.out
docker load -i ./docker-image.tar
- run:
name: tag to latest
command: |
docker tag ${REPO_NAME}/${IMAGE_NAME}:latest ${REPO_NAME}/${IMAGE_NAME}:nightly
- run:
name: docker login
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- run:
name: push image to registory
command: |
docker push ${REPO_NAME}/${IMAGE_NAME}
publish:
<<: *default
steps:
- setup_remote_docker: *setup_remote_docker
- attach_workspace:
at: .
- run:
name: load image from tar
command: |
docker load -i ./docker-image.tar
- run:
name: tag to latest
command: |
docker tag ${REPO_NAME}/${IMAGE_NAME}:latest ${REPO_NAME}/${IMAGE_NAME}:$CIRCLE_TAG
- run:
name: docker login
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- run:
name: push image to registory
command: |
docker push ${REPO_NAME}/${IMAGE_NAME}
versioning:
<<: *default
steps:
- checkout
- run:
name: check
command: |
mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
LAST_COMMIT=`git log -1 --pretty=%B`
VERSION=`git describe --abbrev=0 --tags`
touch ./.tag
if [ ! -z "`git diff $VERSION`" -o -z "$VERSION" ]; then
VERSION=${VERSION:-'0.0.0'}
MAJOR="${VERSION%%.*}"; VERSION="${VERSION#*.}"
MINOR="${VERSION%%.*}"; VERSION="${VERSION#*.}"
PATCH="${VERSION%%.*}"; VERSION="${VERSION#*.}"
if echo $LAST_COMMIT | grep "\[\(major\|MAJOR\)\]" > /dev/null; then
MAJOR=$((MAJOR+1))
echo "$MAJOR.0.0" > ./.tag
elif echo $LAST_COMMIT | grep "\[\(minor\|MINOR\)\]" > /dev/null; then
MINOR=$((MINOR+1))
echo "$MAJOR.$MINOR.0" > ./.tag
elif echo $LAST_COMMIT | grep "\[\(patch\|PATCH\)\]" > /dev/null; then
PATCH=$((PATCH+1))
echo "$MAJOR.$MINOR.$PATCH" > ./.tag
fi
fi
- persist_to_workspace:
root: .
paths:
- .
push:
<<: *default
steps:
- attach_workspace:
at: .
- run:
name: push tag and check PR body
command: |
mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
TAG=`cat ./.tag`
if [ ! -z "$TAG" ]; then
echo $TAG
git tag $TAG
git push https://${GITHUB_ACCESS_TOKEN}:[email protected]/${REPO_NAME}/${IMAGE_NAME} --tags
# git push [email protected]:${REPO_NAME}/${IMAGE_NAME} --tags
fi
- persist_to_workspace:
root: .
paths:
- .
gh_release:
<<: *default
steps:
- attach_workspace:
at: .
- run:
name: release
command: |
mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
TAG=`cat ./.tag`
if [ ! -z "$TAG" ]; then
echo "Create release: ${TAG}"
curl -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" \
-X POST \
-d "{\"tag_name\": \"${TAG}\"}" \
${GITHUB_API}repos/${REPO_NAME}/${IMAGE_NAME}/releases
fi
workflows:
version: 2
build:
jobs:
- test
- build
- publish_nightly:
requires:
- test
- build
filters:
branches:
only:
- master
- versioning:
filters:
branches:
only:
- master
- push:
requires:
- versioning
- gh_release:
requires:
- push
release:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /[0-9]+\.[0-9]+\.[0-9]+/
- publish:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /[0-9]+\.[0-9]+\.[0-9]+/

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NGTD: Serving [NGT](https://github.com/yahoojapan/NGT) over HTTP or gRPC. [![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![release](https://img.shields.io/github/release/yahoojapan/ngtd.svg)](https://github.com/yahoojapan/ngtd/releases/latest) [![CircleCI](https://circleci.com/gh/yahoojapan/ngtd.svg?style=shield)](https://circleci.com/gh/yahoojapan/ngtd) [![codecov](https://codecov.io/gh/yahoojapan/ngtd/branch/master/graph/badge.svg)](https://codecov.io/gh/yahoojapan/ngtd) [![Go Report Card](https://goreportcard.com/badge/github.com/yahoojapan/ngtd)](https://goreportcard.com/report/github.com/yahoojapan/ngtd) [![GoDoc](http://godoc.org/github.com/yahoojapan/ngtd?status.svg)](http://godoc.org/github.com/yahoojapan/ngtd) [![Join the chat at https://gitter.im/yahoojapan/ngtd](https://badges.gitter.im/yahoojapan/ngtd.svg)](https://gitter.im/yahoojapan/ngtd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
# NGTD: Serving [NGT](https://github.com/yahoojapan/NGT) over HTTP or gRPC. [![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0) [![release](https://img.shields.io/github/release/yahoojapan/ngtd.svg?style=flat-square)](https://github.com/yahoojapan/ngtd/releases/latest) [![CircleCI](https://circleci.com/gh/yahoojapan/ngtd.svg)](https://circleci.com/gh/yahoojapan/ngtd) [![codecov](https://codecov.io/gh/yahoojapan/ngtd/branch/master/graph/badge.svg)](https://codecov.io/gh/yahoojapan/ngtd) [![Go Report Card](https://goreportcard.com/badge/github.com/yahoojapan/ngtd)](https://goreportcard.com/report/github.com/yahoojapan/ngtd) [![GolangCI](https://golangci.com/badges/github.com/yahoojapan/ngtd.svg?style=flat-square)](https://golangci.com/r/github.com/yahoojapan/ngtd) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b03d543ee4a9448ba6d25f94f4989ba4)](https://www.codacy.com/app/i.can.feel.gravity/ngtd?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=yahoojapan/ngtd&amp;utm_campaign=Badge_Grade) [![GoDoc](http://godoc.org/github.com/yahoojapan/ngtd?status.svg)](http://godoc.org/github.com/yahoojapan/ngtd)

Description
-----------
Expand Down

0 comments on commit 03a23e3

Please sign in to comment.