diff --git a/.test-coverage b/.test-coverage index 045ec05..2142c44 100755 --- a/.test-coverage +++ b/.test-coverage @@ -1,6 +1,8 @@ #!/bin/bash # Issue: https://github.com/mattn/goveralls/issues/20 # Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh +CI=$1 +echo "run for $CI" echo "mode: count" > profile.cov FAIL=0 @@ -20,7 +22,7 @@ done # Failures have incomplete results, so don't send if [ "$FAIL" -eq 0 ]; then - goveralls -service=travis-ci -v -coverprofile=profile.cov + goveralls -v -coverprofile=profile.cov -service=$CI -repotoken=$COVERALLS_REPO_TOKEN fi exit $FAIL diff --git a/README.md b/README.md index a4f6bfd..57d9c5e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Stock-Microservice This is a microservice cutted out of a [Monolith](https://gitlab.com/matthiasstock/monolith). -[![Build Status](https://travis-ci.org/genofire/hs_master-kss-monolith.svg?branch=master)](https://travis-ci.org/genofire/hs_master-kss-monolith) [![Coverage Status](https://coveralls.io/repos/github/genofire/hs_master-kss-monolith/badge.svg?branch=master)](https://coveralls.io/github/genofire/hs_master-kss-monolith?branch=master) [![GoDoc](https://godoc.org/github.com/genofire/hs_master-kss-monolith?status.svg)](https://godoc.org/github.com/genofire/hs_master-kss-monolith) +[![Build Status](https://travis-ci.org/genofire/hs_master-kss-monolith.svg?branch=master)](https://travis-ci.org/genofire/hs_master-kss-monolith) [![CircleCI](https://circleci.com/gh/genofire/hs_master-kss-monolith/tree/master.svg?style=svg)](https://circleci.com/gh/genofire/hs_master-kss-monolith/tree/master) [![Coverage Status](https://coveralls.io/repos/github/genofire/hs_master-kss-monolith/badge.svg?branch=master)](https://coveralls.io/github/genofire/hs_master-kss-monolith?branch=master) [![GoDoc](https://godoc.org/github.com/genofire/hs_master-kss-monolith?status.svg)](https://godoc.org/github.com/genofire/hs_master-kss-monolith) ## Features of this stock mircoservice * The main functionality of the microservice is to store the goods with their storage location and a time stamp, when they where stored. diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..888c0bc --- /dev/null +++ b/circle.yml @@ -0,0 +1,29 @@ +machine: + environment: + GOROOT: "" + PATH: "/usr/local/go/bin:/usr/local/go_workspace/bin:~/.go_workspace/bin:${PATH}" + GOPATH: "${HOME}/.go_workspace" + +dependencies: + override: + - mkdir -p ~/.go_workspace/src/github.com/${CIRCLE_PROJECT_USERNAME} + - ln -s ${HOME}/${CIRCLE_PROJECT_REPONAME} ${HOME}/.go_workspace/src/github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} + - go get -t -d -v ./... + - go install github.com/genofire/hs_master-kss-monolith/cmd/stock + post: + - cp ~/.go_workspace/bin/stock . + - tar -cvzf stock-builded.tar.gz contrib webroot stock + - mv stock-builded.tar.gz $CIRCLE_ARTIFACTS + +test: + pre: + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover + override: + - ./.test-coverage circle-ci + +deployment: + staging: + branch: master + commands: + - ./deploy.sh STAGING diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..006db0a --- /dev/null +++ b/deploy.sh @@ -0,0 +1,10 @@ +#!/bin/bash +host="HOST_FOR_$1" +port="PORT_FOR_$1" +remote="circleci@${!host}" +echo "deploying on: $remote" + +scp -p $port bin/stock $remote:~/bin/stock; +rsync -e "ssh -p $port $host" -a webroot/ $remote:~/lib/stock/www; +rsync -e "ssh -p $port $host" -a contrib/ $remote:~/lib/stock/contrib; +ssh -p $port $remote sudo systemctl restart stock; diff --git a/http/good_show.go b/http/good_show.go index 14960e6..1e649a2 100644 --- a/http/good_show.go +++ b/http/good_show.go @@ -8,12 +8,13 @@ import ( logrus "github.com/Sirupsen/logrus" "goji.io/pat" + "time" + "github.com/genofire/hs_master-kss-monolith/lib/database" lib "github.com/genofire/hs_master-kss-monolith/lib/http" logger "github.com/genofire/hs_master-kss-monolith/lib/log" "github.com/genofire/hs_master-kss-monolith/models" "github.com/genofire/hs_master-kss-monolith/runtime" - "time" ) // Function to list all goods @@ -79,10 +80,8 @@ func getGoodAvailability(w http.ResponseWriter, r *http.Request) { log.Info("done") } - - // Function that returns the freshness of a good -func getGoodFreshness(w http.ResponseWriter, r *http.Request){ +func getGoodFreshness(w http.ResponseWriter, r *http.Request) { log := logger.HTTP(r) id, err := strconv.ParseInt(pat.Param(r, "goodid"), 10, 64) if err != nil { @@ -112,4 +111,4 @@ func getGoodFreshness(w http.ResponseWriter, r *http.Request){ getGoodFreshnessSVG(w, fresh) } log.Info("done") -} \ No newline at end of file +} diff --git a/http/good_show_test.go b/http/good_show_test.go index e359022..d6e499b 100644 --- a/http/good_show_test.go +++ b/http/good_show_test.go @@ -10,7 +10,6 @@ import ( "github.com/genofire/hs_master-kss-monolith/lib/database" "github.com/genofire/hs_master-kss-monolith/models" "github.com/genofire/hs_master-kss-monolith/runtime" - "github.com/genofire/hs_master-kss-monolith/test" ) diff --git a/http/good_temp.go b/http/good_temp.go index cfd5eb9..923d816 100644 --- a/http/good_temp.go +++ b/http/good_temp.go @@ -11,7 +11,7 @@ import ( // Path to the svg image template, that shows the availablity or freshness of a given good // with a traffic light food labeling system -var GoodAvailablityTemplate string +var GoodAvailabilityTemplate string var GoodFreshnessTemplate string // Function to calculate a percent value from a given value and an maximum value @@ -32,8 +32,8 @@ func getGoodAvailablitySVG(w http.ResponseWriter, count int) { "process_radius": tempProcessRadius, }) buf := bytes.NewBuffer(nil) - f, _ := os.Open(GoodAvailablityTemplate) // Error handling elided for brevity. - io.Copy(buf, f) // Error handling elided for brevity. + f, _ := os.Open(GoodAvailabilityTemplate) // Error handling elided for brevity. + io.Copy(buf, f) // Error handling elided for brevity. f.Close() s := string(buf.Bytes()) @@ -43,14 +43,13 @@ func getGoodAvailablitySVG(w http.ResponseWriter, count int) { t.Execute(w, map[string]interface{}{"Count": count}) } - // Function to get the SVG, that shows the freshness with a traffic light food labeling system for a given good func getGoodFreshnessSVG(w http.ResponseWriter, fresh bool) { t := template.New("some") buf := bytes.NewBuffer(nil) f, _ := os.Open(GoodFreshnessTemplate) // Error handling elided for brevity. - io.Copy(buf, f) // Error handling elided for brevity. + io.Copy(buf, f) // Error handling elided for brevity. f.Close() s := string(buf.Bytes()) @@ -58,4 +57,4 @@ func getGoodFreshnessSVG(w http.ResponseWriter, fresh bool) { w.Header().Set("Content-Type", "image/svg+xml") t.Execute(w, map[string]interface{}{"Fresh": fresh}) -} \ No newline at end of file +} diff --git a/test/testrest.go b/test/testrest.go index baf562e..053325e 100644 --- a/test/testrest.go +++ b/test/testrest.go @@ -33,7 +33,11 @@ func Init(t *testing.T) (assertion *assert.Assertions, router *goji.Mux) { Addr: ":8080", Handler: apirouter, } - go srv.ListenAndServe() + go func() { + if err := srv.ListenAndServe(); err != nil { + panic(err) + } + }() return }