Fixed router not working

This commit is contained in:
pb 2024-02-19 17:24:14 +01:00
parent 2e36c7f655
commit aafe6e9d79
4 changed files with 42 additions and 11 deletions

View File

@ -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" .

View File

@ -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
## 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.

View File

@ -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

View File

@ -125,3 +125,4 @@ func Init() {
initAuthMiddleware()
initUglyFixes()
}