[feature] Added new pipeline. Build and check is server starting up
This commit is contained in:
parent
a19be84c4b
commit
eeaf6e75e8
102
.drone.yml
102
.drone.yml
@ -1,35 +1,85 @@
|
|||||||
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: default
|
name: Code Quality
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: static_check
|
- name: static_check
|
||||||
image: golang:1.17
|
image: golang:1.17
|
||||||
commands:
|
commands:
|
||||||
- go install honnef.co/go/tools/cmd/staticcheck@latest
|
- go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||||
- staticcheck -checks all ./pkg/...
|
- staticcheck -checks all ./pkg/...
|
||||||
volumes:
|
volumes:
|
||||||
- name: env_cache
|
- name: env_cache
|
||||||
path: /go
|
path: /go
|
||||||
|
|
||||||
- name: lint
|
- name: lint
|
||||||
image: golang:1.17
|
image: golang:1.17
|
||||||
commands:
|
commands:
|
||||||
- go install golang.org/x/lint/golint@latest
|
- go install golang.org/x/lint/golint@latest
|
||||||
- golint -set_exit_status ./pkg/...
|
- golint -set_exit_status ./pkg/...
|
||||||
volumes:
|
volumes:
|
||||||
- name: env_cache
|
- name: env_cache
|
||||||
path: /go
|
path: /go
|
||||||
|
|
||||||
- name: vet
|
- name: vet
|
||||||
image: golang:1.17
|
image: golang:1.17
|
||||||
commands:
|
commands:
|
||||||
- go vet ./pkg/...
|
- go vet ./pkg/...
|
||||||
volumes:
|
volumes:
|
||||||
- name: env_cache
|
- name: env_cache
|
||||||
path: /go
|
path: /go
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
|
- name: env_cache
|
||||||
|
temp: {}
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: modules_install
|
||||||
|
image: golang:1.17
|
||||||
|
commands:
|
||||||
|
- go mod tidy && go mod download
|
||||||
|
volumes:
|
||||||
- name: env_cache
|
- name: env_cache
|
||||||
host:
|
path: /go
|
||||||
path: /tmp/drone/envs/vegvisir
|
|
||||||
|
- name: build
|
||||||
|
image: golang:1.17
|
||||||
|
commands:
|
||||||
|
- go build -o /tmp/vegvisir pkg/main.go
|
||||||
|
volumes:
|
||||||
|
- name: tmp_cache
|
||||||
|
path: /tmp
|
||||||
|
- name: env_cache
|
||||||
|
path: /go
|
||||||
|
|
||||||
|
- name: run
|
||||||
|
image: golang:1.17
|
||||||
|
detach: true
|
||||||
|
commands:
|
||||||
|
- echo $(hostname) >> /tmp/server_hostname
|
||||||
|
- /tmp/vegvisir -c ./vegvisir.test.json
|
||||||
|
volumes:
|
||||||
|
- name: tmp_cache
|
||||||
|
path: /tmp
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: golang:1.17
|
||||||
|
commands:
|
||||||
|
# - sleep 5
|
||||||
|
- server_hostname=$(cat /tmp/server_hostname)
|
||||||
|
- "[ $(curl -fsS http://$server_hostname:8080/health | grep OK | wc -l) = 0 ] && { echo 'Not running.'; return 1; } || { echo 'Vegvisir is running.'; return 0; }"
|
||||||
|
volumes:
|
||||||
|
- name: tmp_cache
|
||||||
|
path: /tmp
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: env_cache
|
||||||
|
temp: {}
|
||||||
|
- name: tmp_cache
|
||||||
|
temp: {}
|
||||||
|
44
pkg/handler/http.go
Normal file
44
pkg/handler/http.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// ___ ____ ___ ___
|
||||||
|
// \ \ / / | _ | __| \ \ / / || | __ || || _ |
|
||||||
|
// \ \/ / |___ | |__ \ \/ / || |___ || ||___|
|
||||||
|
// \ / | _ | _ | \ / || __ | || ||\\
|
||||||
|
// \/ |___ |___ | \/ || ____| || || \\
|
||||||
|
//
|
||||||
|
// Copyright (c) 2021 Piotr Biernat. https://pbiernat.dev. MIT License
|
||||||
|
// Repo: https://git.pbiernat.dev/golang/vegvisir
|
||||||
|
|
||||||
|
// Package handler contain handlers for various protocols
|
||||||
|
package handler
|
||||||
|
|
||||||
|
//func (s *Server) httpHandler(ctx *fasthttp.RequestCtx) {
|
||||||
|
// // http := client.NewHttpClient(ctx)
|
||||||
|
//
|
||||||
|
// // move all below logic to concrete handler or sth....
|
||||||
|
// reqURL, sReqURL, sReqMethod := ctx.RequestURI(), string(ctx.RequestURI()), string(ctx.Method())
|
||||||
|
// //log.Println("Incoming request:", sReqMethod, sReqURL)
|
||||||
|
//
|
||||||
|
// found, route := s.router.FindByRequestURL(reqURL)
|
||||||
|
// if !found {
|
||||||
|
// // FIXME: return 404 or 5xx error in response? Maybe define it in concrete Backend config?
|
||||||
|
// ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||||
|
// //ctx.SetConnectionClose()
|
||||||
|
//
|
||||||
|
// log.Println("404:", sReqMethod, sReqURL)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// response, err := s.respCM.Fetch(sReqURL, sReqMethod, route)
|
||||||
|
// if err != nil {
|
||||||
|
// // FIXME: Response read error(sending 500 error response)
|
||||||
|
// ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||||
|
// //ctx.SetConnectionClose() // not sure if change abything with connection: keep-alive/close issue ^^
|
||||||
|
//
|
||||||
|
// log.Println("Response read error(sending 500 error response)", err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// ctx.Response.Header.SetBytesV(fasthttp.HeaderContentType, response.Headers.ContentType())
|
||||||
|
// ctx.SetStatusCode(response.Code)
|
||||||
|
// ctx.SetBodyString(response.Body)
|
||||||
|
// //ctx.SetConnectionClose()
|
||||||
|
//}
|
@ -19,6 +19,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -104,7 +105,15 @@ func (s *Server) mainHandler(ctx *fasthttp.RequestCtx) {
|
|||||||
|
|
||||||
// move all below logic to concrete handler or sth....
|
// move all below logic to concrete handler or sth....
|
||||||
reqURL, sReqURL, sReqMethod := ctx.RequestURI(), string(ctx.RequestURI()), string(ctx.Method())
|
reqURL, sReqURL, sReqMethod := ctx.RequestURI(), string(ctx.RequestURI()), string(ctx.Method())
|
||||||
//log.Println("Incoming request:", sReqMethod, sReqURL)
|
log.Println("Incoming request:", sReqMethod, sReqURL)
|
||||||
|
|
||||||
|
if strings.Contains(sReqURL, "/health") { // quick and tmp fix, hack...
|
||||||
|
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||||
|
ctx.SetContentType("application/json")
|
||||||
|
ctx.SetBodyString("{\"health\":\"OK\"}")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
found, route := s.router.FindByRequestURL(reqURL)
|
found, route := s.router.FindByRequestURL(reqURL)
|
||||||
if !found {
|
if !found {
|
||||||
@ -117,7 +126,6 @@ func (s *Server) mainHandler(ctx *fasthttp.RequestCtx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
response, err := s.respCM.Fetch(sReqURL, sReqMethod, route)
|
response, err := s.respCM.Fetch(sReqURL, sReqMethod, route)
|
||||||
//err, response := s.processUrl(sReqURL, sReqMethod, route)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// FIXME: Response read error(sending 500 error response)
|
// FIXME: Response read error(sending 500 error response)
|
||||||
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||||
@ -132,37 +140,3 @@ func (s *Server) mainHandler(ctx *fasthttp.RequestCtx) {
|
|||||||
ctx.SetBodyString(response.Body)
|
ctx.SetBodyString(response.Body)
|
||||||
//ctx.SetConnectionClose()
|
//ctx.SetConnectionClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (s *Server) processUrl(url, method string, route *cache.RouteCache) (error, *cache.ResponseCache) {
|
|
||||||
// // handle response caching
|
|
||||||
// cacheKey := method + "_" + url
|
|
||||||
// if ok, data := s.respCM.load(cacheKey, &cache.ResponseCache{}); ok {
|
|
||||||
// log.Println("Read resp from cache: ", route.TargetURL, url)
|
|
||||||
//
|
|
||||||
// return nil, data.(*cache.ResponseCache) // FIXME #67 - simplify
|
|
||||||
// } else {
|
|
||||||
// //log.Println("Send req to backend url: ", route.TargetURL, url)
|
|
||||||
// ////start := time.Now()
|
|
||||||
// //bckReq := fasthttp.AcquireRequest()
|
|
||||||
// //bckResp := fasthttp.AcquireResponse()
|
|
||||||
// //defer fasthttp.ReleaseRequest(bckReq)
|
|
||||||
// //defer fasthttp.ReleaseResponse(bckResp)
|
|
||||||
// //
|
|
||||||
// //// copy headers from backend response and prepare request for backend - separate
|
|
||||||
// //bckReq.SetRequestURI(route.TargetURL)
|
|
||||||
// //bckReq.Header.SetMethod(method)
|
|
||||||
// //
|
|
||||||
// //err := fasthttp.Do(bckReq, bckResp)
|
|
||||||
// //if err != nil {
|
|
||||||
// // return err, nil
|
|
||||||
// //}
|
|
||||||
// //
|
|
||||||
// //body, code := bckResp.Body(), bckResp.StatusCode()
|
|
||||||
// ////log.Printf("%s, %s, %d bytes\n", url, time.Since(start), len(body))
|
|
||||||
// //// save response to cache
|
|
||||||
// //respCache := cache.NewResponseCache(url, method, body, code, &bckResp.Header)
|
|
||||||
// //s.respCM.save(cacheKey, respCache)
|
|
||||||
// //
|
|
||||||
// //return nil, respCache
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
19
vegvisir.test.json
Normal file
19
vegvisir.test.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"server": {
|
||||||
|
"address": "0.0.0.0",
|
||||||
|
"port": 8080
|
||||||
|
},
|
||||||
|
"backends": {
|
||||||
|
"news-app": {
|
||||||
|
"prefixURL": "/",
|
||||||
|
"backendAddress": "http://127.0.0.1:3030/api/news",
|
||||||
|
"routes": [{
|
||||||
|
"pattern": "(.*)",
|
||||||
|
"target": "$1"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cache": {
|
||||||
|
"type": "memory"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user