From f77d2bc8cf01da0a37eec9d751a5a702e31164a8 Mon Sep 17 00:00:00 2001 From: pb Date: Thu, 15 Feb 2024 10:52:29 +0100 Subject: [PATCH] Swagger returning only 404s --- Dockerfile | 6 ++++++ docker-compose.backend.yml | 2 +- docker-compose.yml | 3 +++ docker_catalog.json | 5 +++++ local_catalog.json | 5 +++++ main.go | 2 +- routers/router.go | 3 +-- services/init.go | 32 +++++++++----------------------- services/mongo.go | 1 + 9 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 docker_catalog.json create mode 100644 local_catalog.json diff --git a/Dockerfile b/Dockerfile index 8681d6e..7150caf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,15 @@ RUN go get github.com/beego/bee/v2 && go install github.com/beego/bee/v2@master # Generating the swagger RUN timeout 20 bee run -gendoc=true -downdoc=true -runmode=dev || : +RUN ls swagger/ + RUN sed -i 's/http:\/\/127.0.0.1:8080\/swagger\/swagger.json/swagger.json/g' swagger/index.html RUN sed -i 's/https:\/\/petstore.swagger.io\/v2\/swagger.json/swagger.json/g' swagger/index.html +RUN echo '------------------------------------------------------------' +RUN cat 'swagger/index.html' +RUN echo '------------------------------------------------------------' + RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" . FROM scratch diff --git a/docker-compose.backend.yml b/docker-compose.backend.yml index 7d5a181..378e4dd 100644 --- a/docker-compose.backend.yml +++ b/docker-compose.backend.yml @@ -2,7 +2,7 @@ version: '3.4' services: oc-catalog: - image: oc-catalog:latest + image: oc-catalog:debugging restart: always environment: - DOCKER_DCNAME=DC_myDC diff --git a/docker-compose.yml b/docker-compose.yml index 32644f9..11a5bf7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,9 @@ services: - catalog ports: - 8081:8081 + environment: + - ME_CONFIG_BASICAUTH_USERNAME=test + - ME_CONFIG_BASICAUTH_PASSWORD=test volumes: oc-catalog-data: diff --git a/docker_catalog.json b/docker_catalog.json new file mode 100644 index 0000000..9b85dc4 --- /dev/null +++ b/docker_catalog.json @@ -0,0 +1,5 @@ +{ + "MongoURL" : "mongodb://mongo:27017/", + "DCNAME" : "DC_myDC", + "DBPOINT" : "demo_06042021" +} \ No newline at end of file diff --git a/local_catalog.json b/local_catalog.json new file mode 100644 index 0000000..17b5a4b --- /dev/null +++ b/local_catalog.json @@ -0,0 +1,5 @@ +{ + "MongoURL" : "mongodb://127.0.0.1:27017/", + "DCNAME" : "DC_myDC", + "DBPOINT" : "demo_06042021" +} \ No newline at end of file diff --git a/main.go b/main.go index 5d3a37d..607c0d5 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,6 @@ func loadConfig(){ conf.GetConfig().MongoURL = o.GetStringDefault("MongoURL", "mongodb://127.0.0.1:27017") conf.GetConfig().DCNAME = o.GetStringDefault("DCNAME", "DC_myDC") - conf.GetConfig().DBPOINT = o.GetStringDefault("DBPOINT", "demdemo_06042021o") + conf.GetConfig().DBPOINT = o.GetStringDefault("DBPOINT", "demo_06042021") } diff --git a/routers/router.go b/routers/router.go index 58967f1..5fb9cbc 100644 --- a/routers/router.go +++ b/routers/router.go @@ -79,14 +79,13 @@ func Init() { ), ) - beego.AddNamespace(ns) beego.Get("/", func(ctx *context.Context) { ctx.Output.Body([]byte(services.DC_NAME)) }) - // Force regenerate swagger before consuming the data + // Force regenerate swagger before consuming the data // bee.GenerateDocs(".") // Open our jsonFile diff --git a/services/init.go b/services/init.go index 3e54ce5..6f71a0c 100644 --- a/services/init.go +++ b/services/init.go @@ -2,43 +2,29 @@ package services import ( "cloud.o-forge.io/core/oc-catalog/conf" - - "github.com/beego/beego/v2/core/logs" ) func Init() { // Discoveryinit() //First init DC name - config := conf.GetConfig() + // var DBpoint string + // var err error - var DBpoint string - var DC_NAME string - var err error - - DC_NAME = config.DCNAME - - if len(DC_NAME) == 0 { - logs.Critical("DC_NAME URI error: %v", err) - panic(err) - } - - DBpoint = config.DBPOINT - - if len(DBpoint) == 0 { - logs.Critical("DBPOINT URI error: %v", err) - panic(err) - } - + DCName := conf.GetConfig().DCNAME + DBPoint := conf.GetConfig().DBPOINT + // DBpoint = os.Getenv("DOCKER_DBPOINT") // if len(DBpoint) == 0 { // DBpoint, err = beego.AppConfig.String("DBPOINT") // if err != nil { // logs.Critical("DBPOINT URI error: %v", err) // panic(err) // } + // } - logs.Debug("connecting to datacenter db : " + DC_NAME + "-" + DBpoint) - Mongoinit(DC_NAME + "-" + DBpoint) + // Mongoinit(DC_NAME + "-" + DBpoint) + Mongoinit(DCName + "-" + DBPoint ) + // Mongoinit("beego-demo") } diff --git a/services/mongo.go b/services/mongo.go index 3ecf258..5e25b3f 100644 --- a/services/mongo.go +++ b/services/mongo.go @@ -98,6 +98,7 @@ func Mongoinit(DBname string) { panic(err) } + logs.Info("Connecting mongo client to db %v", DBname) mngoDB = mngoClient.Database(DBname) MngoCollData = mngoDB.Collection(MngoNamesCollection.DATA)