Skip to content
Snippets Groups Projects
Commit 265a103e authored by tgs266's avatar tgs266
Browse files

deployment updates

parent 6ea103f9
No related branches found
No related tags found
No related merge requests found
FROM golang:1.16.8-bullseye
## We create an /app directory within our
## image that will hold our application source
## files
RUN mkdir /app
## We copy everything in the root directory
## into our /app directory
ADD . /app
## We specify that we now wish to execute
## any further commands inside our /app
## directory
WORKDIR /app
## we run go build to compile the binary
## executable of our Go program
RUN go build -o main .
## Our start command which kicks off
## our newly created binary executable
CMD ["/app/main"]
\ No newline at end of file
...@@ -16,4 +16,8 @@ To rebuild swagger: `swag init` ...@@ -16,4 +16,8 @@ To rebuild swagger: `swag init`
Call `go test -covermode=count -coverprofile=coverage.out ./...` Call `go test -covermode=count -coverprofile=coverage.out ./...`
To generate code coverage html page, call `go tool cover -html=coverage.out` To generate code coverage html page, call `go tool cover -html=coverage.out`
Swagger [Here](http://localhost:8080/api/weather/gdd-swagger/index.html#/) Swagger [Here](http://localhost:8080/api/weather/gdd-swagger/index.html#/)
\ No newline at end of file
## Docker
To build the image: `docker build -t dawn/dawn-weather .`
\ No newline at end of file
package config package common
import ( import (
"github.com/spf13/viper" "log"
"os" "os"
"github.com/spf13/viper"
) )
func GetConfig() { func GetConfig(configName string) {
viper.SetConfigName("local") viper.SetConfigName("local")
viper.SetConfigType("yaml") viper.SetConfigType("yaml")
viper.AddConfigPath(".") viper.AddConfigPath(".")
...@@ -14,6 +16,19 @@ func GetConfig() { ...@@ -14,6 +16,19 @@ func GetConfig() {
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {
log.Fatalln("Env local not found")
os.Exit(1)
}
viper.SetConfigName(configName)
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("./config/")
viper.AutomaticEnv()
err = viper.MergeInConfig()
if err != nil {
log.Fatalln("Env " + configName + " not found")
os.Exit(1) os.Exit(1)
} }
} }
...@@ -19,3 +19,13 @@ func (ctx DawnCtx) DEBUG(message string) { ...@@ -19,3 +19,13 @@ func (ctx DawnCtx) DEBUG(message string) {
func (ctx DawnCtx) TRACE(message string) { func (ctx DawnCtx) TRACE(message string) {
TRACE(ctx.FiberCtx, message) TRACE(ctx.FiberCtx, message)
} }
func BuildCtx(c *fiber.Ctx) DawnCtx {
return DawnCtx{
FiberCtx: c,
}
}
func (ctx DawnCtx) BodyParser(out interface{}) error {
return ctx.FiberCtx.BodyParser(out)
}
...@@ -92,7 +92,7 @@ func LogRequest(message RequestLog) { ...@@ -92,7 +92,7 @@ func LogRequest(message RequestLog) {
fmt.Println(logString) fmt.Println(logString)
} }
func New() fiber.Handler { func FiberLogger() fiber.Handler {
return func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error {
errHandler := c.App().Config().ErrorHandler errHandler := c.App().Config().ErrorHandler
......
app:
logLevel: DEBUG
db:
uri: "mongodb://host.docker.internal:27017/"
app:
logType: json
logLevel: INFO
swagger: false
db:
uri: "mongodb://host.docker.internal:27017/"
...@@ -5,32 +5,32 @@ go 1.16 ...@@ -5,32 +5,32 @@ go 1.16
require ( require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/andybalholm/brotli v1.0.3 // indirect github.com/andybalholm/brotli v1.0.3 // indirect
github.com/ansrivas/fiberprometheus/v2 v2.1.2 // indirect github.com/ansrivas/fiberprometheus/v2 v2.1.2
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/arsmn/fiber-swagger/v2 v2.15.0 // indirect github.com/arsmn/fiber-swagger/v2 v2.15.0
github.com/bradfitz/slice v0.0.0-20180809154707-2b758aa73013 // indirect github.com/bradfitz/slice v0.0.0-20180809154707-2b758aa73013
github.com/coreos/etcd v3.3.10+incompatible // indirect github.com/coreos/etcd v3.3.10+incompatible // indirect
github.com/coreos/go-etcd v2.0.0+incompatible // indirect github.com/coreos/go-etcd v2.0.0+incompatible // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.3 // indirect github.com/go-openapi/spec v0.20.3 // indirect
github.com/go-openapi/swag v0.19.15 // indirect github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible // indirect github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/gofiber/adaptor/v2 v2.1.9 // indirect github.com/gofiber/adaptor/v2 v2.1.9 // indirect
github.com/gofiber/fiber/v2 v2.16.0 github.com/gofiber/fiber/v2 v2.16.0
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0
github.com/klauspost/compress v1.13.3 // indirect github.com/klauspost/compress v1.13.3 // indirect
github.com/mailru/easyjson v0.7.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/common v0.30.0 // indirect github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.2 // indirect github.com/prometheus/procfs v0.7.2 // indirect
github.com/spf13/viper v1.8.1 // indirect github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0 // indirect github.com/stretchr/testify v1.7.0 // indirect
github.com/swaggo/swag v1.7.1 // indirect github.com/swaggo/swag v1.7.1
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
github.com/valyala/fasthttp v1.28.0 // indirect github.com/valyala/fasthttp v1.28.0
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
go.mongodb.org/mongo-driver v1.7.1 // indirect go.mongodb.org/mongo-driver v1.7.1
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf // indirect golang.org/x/net v0.0.0-20210917221730-978cfadd31cf // indirect
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 // indirect golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 // indirect
......
...@@ -5,13 +5,12 @@ import ( ...@@ -5,13 +5,12 @@ import (
"dawn-weather/config" "dawn-weather/config"
"dawn-weather/controllers" "dawn-weather/controllers"
"dawn-weather/persistence" "dawn-weather/persistence"
"flag"
"strconv" "strconv"
"github.com/ansrivas/fiberprometheus/v2" "github.com/ansrivas/fiberprometheus/v2"
swagger "github.com/arsmn/fiber-swagger/v2" swagger "github.com/arsmn/fiber-swagger/v2"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover" "github.com/gofiber/fiber/v2/middleware/recover"
"github.com/gofiber/fiber/v2/middleware/requestid" "github.com/gofiber/fiber/v2/middleware/requestid"
"github.com/gofiber/fiber/v2/utils" "github.com/gofiber/fiber/v2/utils"
...@@ -33,10 +32,10 @@ func registerSwagger(app *fiber.App) { ...@@ -33,10 +32,10 @@ func registerSwagger(app *fiber.App) {
} }
func registerCors(app *fiber.App) { func registerCors(app *fiber.App) {
app.Use(cors.New(cors.Config{ // app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:3000, http://localhost:4200, http://localhost:5000, http://localhost:12321", // AllowOrigins: "http://localhost:3000, http://localhost:4200, http://localhost:5000, http://localhost:12321",
AllowHeaders: "Origin, Content-Type, Accept", // AllowHeaders: "Origin, Content-Type, Accept",
})) // }))
} }
func registerLogging(app *fiber.App) { func registerLogging(app *fiber.App) {
...@@ -49,7 +48,7 @@ func registerLogging(app *fiber.App) { ...@@ -49,7 +48,7 @@ func registerLogging(app *fiber.App) {
ContextKey: "requestId", ContextKey: "requestId",
})) }))
app.Use(logger.New()) app.Use(common.FiberLogger())
} }
func registerPrometheus(app *fiber.App) { func registerPrometheus(app *fiber.App) {
...@@ -91,6 +90,7 @@ func createFiberConfig() fiber.Config { ...@@ -91,6 +90,7 @@ func createFiberConfig() fiber.Config {
} }
func CreateFiberApp() *fiber.App { func CreateFiberApp() *fiber.App {
app := fiber.New(createFiberConfig()) app := fiber.New(createFiberConfig())
app.Use(recover.New()) app.Use(recover.New())
registerCors(app) registerCors(app)
...@@ -101,6 +101,12 @@ func CreateFiberApp() *fiber.App { ...@@ -101,6 +101,12 @@ func CreateFiberApp() *fiber.App {
return app return app
} }
var flagVal *string
func init() {
flagVal = flag.String("env", "local", "environment (local, prod)")
}
// @title Dawn GDD Service // @title Dawn GDD Service
// @version 1.0 // @version 1.0
// @description All operations for GDD/Freezing Date data // @description All operations for GDD/Freezing Date data
...@@ -109,7 +115,8 @@ func CreateFiberApp() *fiber.App { ...@@ -109,7 +115,8 @@ func CreateFiberApp() *fiber.App {
// @host localhost:8080 // @host localhost:8080
// @BasePath / // @BasePath /
func main() { func main() {
config.GetConfig() flag.Parse()
common.GetConfig(*flagVal)
persistence.CreateDBSession() persistence.CreateDBSession()
app := CreateFiberApp() app := CreateFiberApp()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment