genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

[TASK] add autodeployment

This commit is contained in:
Martin Geno 2017-05-17 21:33:23 +02:00
parent d73c5d0cd9
commit c05dad026a
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
8 changed files with 57 additions and 15 deletions

View File

@ -1,6 +1,8 @@
#!/bin/bash #!/bin/bash
# Issue: https://github.com/mattn/goveralls/issues/20 # Issue: https://github.com/mattn/goveralls/issues/20
# Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh # Source: https://github.com/uber/go-torch/blob/63da5d33a225c195fea84610e2456d5f722f3963/.test-cover.sh
CI=$1
echo "run for $CI"
echo "mode: count" > profile.cov echo "mode: count" > profile.cov
FAIL=0 FAIL=0
@ -20,7 +22,7 @@ done
# Failures have incomplete results, so don't send # Failures have incomplete results, so don't send
if [ "$FAIL" -eq 0 ]; then 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 fi
exit $FAIL exit $FAIL

View File

@ -1,7 +1,7 @@
# Stock-Microservice # Stock-Microservice
This is a microservice cutted out of a [Monolith](https://gitlab.com/matthiasstock/monolith). 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 ## 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. * The main functionality of the microservice is to store the goods with their storage location and a time stamp, when they where stored.

29
circle.yml Normal file
View File

@ -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

10
deploy.sh Executable file
View File

@ -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;

View File

@ -8,12 +8,13 @@ import (
logrus "github.com/Sirupsen/logrus" logrus "github.com/Sirupsen/logrus"
"goji.io/pat" "goji.io/pat"
"time"
"github.com/genofire/hs_master-kss-monolith/lib/database" "github.com/genofire/hs_master-kss-monolith/lib/database"
lib "github.com/genofire/hs_master-kss-monolith/lib/http" lib "github.com/genofire/hs_master-kss-monolith/lib/http"
logger "github.com/genofire/hs_master-kss-monolith/lib/log" 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/models"
"github.com/genofire/hs_master-kss-monolith/runtime" "github.com/genofire/hs_master-kss-monolith/runtime"
"time"
) )
// Function to list all goods // Function to list all goods
@ -79,10 +80,8 @@ func getGoodAvailability(w http.ResponseWriter, r *http.Request) {
log.Info("done") log.Info("done")
} }
// Function that returns the freshness of a good // 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) log := logger.HTTP(r)
id, err := strconv.ParseInt(pat.Param(r, "goodid"), 10, 64) id, err := strconv.ParseInt(pat.Param(r, "goodid"), 10, 64)
if err != nil { if err != nil {

View File

@ -10,7 +10,6 @@ import (
"github.com/genofire/hs_master-kss-monolith/lib/database" "github.com/genofire/hs_master-kss-monolith/lib/database"
"github.com/genofire/hs_master-kss-monolith/models" "github.com/genofire/hs_master-kss-monolith/models"
"github.com/genofire/hs_master-kss-monolith/runtime" "github.com/genofire/hs_master-kss-monolith/runtime"
"github.com/genofire/hs_master-kss-monolith/test" "github.com/genofire/hs_master-kss-monolith/test"
) )

View File

@ -11,7 +11,7 @@ import (
// Path to the svg image template, that shows the availablity or freshness of a given good // Path to the svg image template, that shows the availablity or freshness of a given good
// with a traffic light food labeling system // with a traffic light food labeling system
var GoodAvailablityTemplate string var GoodAvailabilityTemplate string
var GoodFreshnessTemplate string var GoodFreshnessTemplate string
// Function to calculate a percent value from a given value and an maximum value // Function to calculate a percent value from a given value and an maximum value
@ -32,7 +32,7 @@ func getGoodAvailablitySVG(w http.ResponseWriter, count int) {
"process_radius": tempProcessRadius, "process_radius": tempProcessRadius,
}) })
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
f, _ := os.Open(GoodAvailablityTemplate) // Error handling elided for brevity. f, _ := os.Open(GoodAvailabilityTemplate) // 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() f.Close()
@ -43,7 +43,6 @@ func getGoodAvailablitySVG(w http.ResponseWriter, count int) {
t.Execute(w, map[string]interface{}{"Count": count}) 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 // 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) { func getGoodFreshnessSVG(w http.ResponseWriter, fresh bool) {

View File

@ -33,7 +33,11 @@ func Init(t *testing.T) (assertion *assert.Assertions, router *goji.Mux) {
Addr: ":8080", Addr: ":8080",
Handler: apirouter, Handler: apirouter,
} }
go srv.ListenAndServe() go func() {
if err := srv.ListenAndServe(); err != nil {
panic(err)
}
}()
return return
} }