[TASK] add autodeployment
This commit is contained in:
parent
d73c5d0cd9
commit
c05dad026a
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
|
@ -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;
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue