From aafe6e9d798a9e29d7d2769a66bddb3cb72f471c Mon Sep 17 00:00:00 2001 From: pb Date: Mon, 19 Feb 2024 17:24:14 +0100 Subject: [PATCH] Fixed router not working --- Dockerfile | 4 ++++ README.md | 45 +++++++++++++++++++++++++++++--------- docker-compose.backend.yml | 3 ++- routers/router.go | 1 + 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32f436d..6f4010b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,12 +6,16 @@ COPY . . RUN go get github.com/beego/bee/v2 && go install github.com/beego/bee/v2@master +# Generating routers/commentsRouter.go +RUN bee generate routers + # Generating the swagger RUN timeout 20 bee run -gendoc=true -downdoc=true -runmode=dev || : 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 ls -l routers RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" . diff --git a/README.md b/README.md index 781d0cf..8337e47 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,30 @@ To install the Beego bee command : go install github.com/beego/bee/v2@master -To build and run : +## Running the app locally +In order to run the application we need to correct some errors that beego generates. - go mod tidy - bee run -downdoc=true -gendoc=true +**Router generation** -## Full deploy +Beego generates the routers from the comment of the controllers methods. However, there seems to be some errors when we let beego generate th routers from `bee run`. + +We need to use `bee generate routers` to have a working router file. + +**Swagger generation** + +Using `bee run -downdoc=true -gendoc=true` beego download a swagger template and generate the JSON file (swagger.json) in `swagger/`. However the swagger template in `swagger/index.html` does not change the exemple's url for our current JSON file. When running locally we have to edit the call to construct the object holding the swagger information, with the parameter url set with the relative path to our JSON swagger file : + +``` +const ui = SwaggerUIBundle({ + url: "swagger.json", + ... + ... + }); +``` + +This issue is fixed in the Dockerfile build with two `sed` to change the value of the swagger file URL. + +## Deployment with Docker compose Deploy with docker: `docker-compose -f docker-compose.yml -f docker-compose.backend.yml up --build` @@ -23,15 +41,22 @@ and populate DB (or other scripts) with: or out of docker `./scripts/populate_models.sh ./scripts/demo.json` -## Dev +### Dev -Start DB with `docker-compose up -d` and run the API with `bee run -downdoc=true -gendoc=true` +- Start DB with `docker-compose up -d` +- Run the API with `bee run -downdoc=true -gendoc=true` -## Multinode +### Multinode + +Deploy : -Deploy `docker-compose -f docker-compose.yml -f docker-compose.backend.yml -f docker-compose.multi.yml up --build` -Populate -`./scripts/multinode.sh ./scripts/demo.json` \ No newline at end of file +## Populating the MongoDB database + +From the root of the projet run : + +`./scripts/multinode.sh ./scripts/demo.json` + +This script should be updated to be ran from anywhere. \ No newline at end of file diff --git a/docker-compose.backend.yml b/docker-compose.backend.yml index d5871ea..5a7ab49 100644 --- a/docker-compose.backend.yml +++ b/docker-compose.backend.yml @@ -2,7 +2,8 @@ version: '3.4' services: oc-catalog: - image: oc-catalog + image: oc-catalog:latest + container_name: oc-catalog restart: always environment: - DOCKER_DCNAME=DC_myDC diff --git a/routers/router.go b/routers/router.go index 5fb9cbc..7fe7a4b 100644 --- a/routers/router.go +++ b/routers/router.go @@ -125,3 +125,4 @@ func Init() { initAuthMiddleware() initUglyFixes() } +