genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

[BUGFIX] autodeployment

This commit is contained in:
Martin Geno 2017-05-18 00:34:26 +02:00
parent 978f65eb7d
commit 64379f77ad
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
7 changed files with 52 additions and 35 deletions

View File

@ -6,5 +6,5 @@ install:
- go get github.com/mattn/goveralls
- go get "golang.org/x/tools/cmd/cover"
script:
- ./.test-coverage
- ./.test-coverage travis-ci
- go install github.com/genofire/hs_master-kss-monolith/cmd/stock

View File

@ -26,4 +26,4 @@ deployment:
staging:
branch: master
commands:
- ./deploy.sh STAGING
- ./deploy.sh $HOST_FOR_STAGING $PORT_FOR_STAGING

View File

@ -1,10 +1,20 @@
#!/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;
host=$1
port=$2
remote="circleci@${host}"
echo "deploying..."
ssh -p $port $remote sudo systemctl stop stock;
RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1
scp -q -P $port ~/.go_workspace/bin/stock $remote:~/bin/stock;
RETVAL=$?
sed -ie 's/http:\/\/localhost:8080/https:\/\/stock.pub.warehost.de/g' webroot/static/js/main.js
[ $RETVAL -eq 0 ] && RETVAL=$?
rsync -e "ssh -p $port" -a webroot/ $remote:~/lib/stock/www;
[ $RETVAL -eq 0 ] && RETVAL=$?
rsync -e "ssh -p $port" -a contrib/ $remote:~/lib/stock/contrib;
[ $RETVAL -eq 0 ] && RETVAL=$?
ssh -p $port $remote sudo systemctl start stock;
[ $RETVAL -eq 0 ] && RETVAL=$?
[ $RETVAL -ne 0 ] && exit 1
echo "deployed"

View File

@ -36,6 +36,9 @@ func TestAddGood(t *testing.T) {
_, w = session.JSONRequest("POST", "/api/good/7", good)
assertion.Equal(http.StatusNotFound, w.StatusCode)
_, w = session.JSONRequest("POST", "/api/good/1", true)
assertion.Equal(http.StatusBadRequest, w.StatusCode)
_, w = session.JSONRequest("POST", "/api/good/1", good)
assertion.Equal(http.StatusOK, w.StatusCode)

View File

@ -5,6 +5,7 @@ import (
"net/http"
"testing"
"github.com/genofire/hs_master-kss-monolith/test"
"github.com/stretchr/testify/assert"
)
@ -14,11 +15,10 @@ func TestAuth(t *testing.T) {
PermissionURL = "http://localhost:8080/api-test/session/%s/%d/"
router := http.FileServer(http.Dir("../webroot"))
srv := &http.Server{
Addr: ":8080",
Handler: router,
}
go srv.ListenAndServe()
mock := test.MockTransport{Handler: router}
http.DefaultClient.Transport = &mock
mock.Start()
perm, err := HasPermission("testsessionkey", PermissionCreateGood)
assert.NoError(err)
@ -28,5 +28,5 @@ func TestAuth(t *testing.T) {
assert.NoError(err)
assert.True(perm)
srv.Close()
mock.Close()
}

View File

@ -5,6 +5,7 @@ import (
"net/http"
"testing"
"github.com/genofire/hs_master-kss-monolith/test"
"github.com/stretchr/testify/assert"
)
@ -14,11 +15,9 @@ func TestProductExists(t *testing.T) {
ProductURL = "http://localhost:8080/api-test/product/%d/"
router := http.FileServer(http.Dir("../webroot"))
srv := &http.Server{
Addr: ":8080",
Handler: router,
}
go srv.ListenAndServe()
mock := test.MockTransport{Handler: router}
http.DefaultClient.Transport = &mock
mock.Start()
ok, err := ProductExists(3)
assert.True(ok)
@ -29,11 +28,10 @@ func TestProductExists(t *testing.T) {
assert.True(ok)
assert.NoError(err)
mock.Close()
productExistCache = make(map[int64]boolMicroServiceCache)
ProductURL = "http://localhost:8081/api-test/product/%d/"
ok, err = ProductExists(3)
assert.Error(err)
srv.Close()
}

View File

@ -17,20 +17,27 @@ import (
)
// Pointer to the server
var srv bool
var mock *MockTransport
type mockTransport struct {
handler http.Handler
type MockTransport struct {
Handler http.Handler
running bool
}
func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if !srv {
func (t *MockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if !t.running {
return nil, errors.New("mock a error")
}
w := httptest.NewRecorder()
t.handler.ServeHTTP(w, req)
t.Handler.ServeHTTP(w, req)
return w.Result(), nil
}
func (t *MockTransport) Start() {
t.running = true
}
func (t *MockTransport) Close() {
t.running = false
}
// Function to initialize a test api (with test files of depending microservice)
func Init(t *testing.T) (assertion *assert.Assertions, router *goji.Mux) {
@ -42,23 +49,22 @@ func Init(t *testing.T) (assertion *assert.Assertions, router *goji.Mux) {
})
router = goji.NewMux()
srv = true
mockBackend := http.FileServer(http.Dir("../webroot"))
http.DefaultClient.Transport = &mockTransport{handler: mockBackend}
mock = &MockTransport{Handler: mockBackend, running: true}
http.DefaultClient.Transport = mock
return
}
// Function to close the static webserver
func CloseServer() {
srv = false
mock.Close()
}
// Function to close and stop the whole microservice
func Close() {
database.Close()
srv = false
mock.Close()
}
// Handle a test session with cookies