Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENDOC-628 generate MS and MFE Tutorial edit commands #652

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vuepress/docs/next/tutorials/create/ms/add-api-claim.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ent bundle run simple-node-ms
* Access <http://localhost:8081/api/hello> to see a `Hello World!` response with a timestamp.
* Access <http://localhost:8081/api/health> to see a standard `{"status:"UP"}` response.

In local development, the run command can be used to modify the port to run multiple microservices, but in production, microservices must run on port 8081.
In local development, custom commands can be used to modify ports to run each microservice, but in production, microservices must run on port 8081.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is less clarified... prefer nathan's tweak to your original wording: In local development, the run command can be used to modify the port for a microservice, but in production microservices must run on port 8081.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to include cases where there are multiple microservices because that's when this applies, not when there is just one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In local development, the run command can be used to modify the port number so that multiple microservices can run in parallel on separate ports, but in production microservices must run on port 8081


6. Finally, create `microservices/simple-node-ms/Dockerfile` so ent knows how to assemble the Docker image for the service:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,113 @@ You have now generated a Spring Boot microservice with database integration and
* ```/src/main/docker``` contains Docker files to help with local development environments.

## Configure the Components
1. From the root directory of the project, edit the `entando.json` and update `microservices/conference-ms` to set the `healthCheckPath` and `dbms`:
1. From the root directory of the project, edit the `entando.json` file and update `microservices/conference-ms` to set the `healthCheckPath` and `dbms`:
```json
"healthCheckPath":"/management/health",
"dbms":"postgresql"
```

2. Move the generated `conference-table` MFE into the microfrontends directory in the bundle project. If you chose a different entity name, you'll need to adjust these commands accordingly.
2. Move the generated `conference-table` MFE into the `microfrontends` directory in the bundle project. If you chose a different entity name, you'll need to adjust these commands accordingly.
```shell
ent bundle mfe add conference-table
mv microservices/conference-ms/ui/widgets/conference/tableWidget microfrontends/ && mv microfrontends/tableWidget microfrontends/conference-table
mv microservices/conference-ms/ui/widgets/conference/tableWidget/{.,}* microfrontends/conference-table
```
>Note: In some shells (e.g. zsh), you may receive an "invalid argument" warning that can be ignored as long as the folders are relocated correctly.

3. Now add an API claim to connect the `conference-table` MFE to the `conference-ms` microservice. The connection information is stored in `entando.json`.
```shell
ent bundle api add conference-table conference-api --serviceName=conference-ms --serviceUrl=http://localhost:8081
```

4. Repeat the previous steps for the `conference-details` and `conference-form` MFEs:
```shell
ent bundle mfe add conference-details
ent bundle mfe add conference-form
mv microservices/conference-ms/ui/widgets/conference/detailsWidget microfrontends/ && mv microfrontends/detailsWidget microfrontends/conference-details
mv microservices/conference-ms/ui/widgets/conference/formWidget microfrontends/ && mv microfrontends/formWidget microfrontends/conference-form

a. Add the MFEs:
```shell
ent bundle mfe add conference-details
ent bundle mfe add conference-form
```
b. Relocate the folders:
```shell
mv microservices/conference-ms/ui/widgets/conference/detailsWidget/{.,}* microfrontends/conference-details
mv microservices/conference-ms/ui/widgets/conference/formWidget/{.,}* microfrontends/conference-form
```
c. Add the API claims:
```shell
ent bundle api add conference-details conference-api --serviceName=conference-ms --serviceUrl=http://localhost:8081
ent bundle api add conference-form conference-api --serviceName=conference-ms --serviceUrl=http://localhost:8081
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a/b/c here don't end with : but the other instructions do

```
5. For local development and testing, a custom command is needed in the `entando.json` to use a different port for each MFE as shown below:
```
"microfrontends": [
{
"name": "conference-table",
"customElement": "conference-table",
"stack": "react",
"type": "widget",
"group": "free",
"publicFolder": "public",
"titles": {
"en": "conference-table",
"it": "conference-table"
},
"commands": {
"run": "npm install && PORT=3000 npm start"
},
"apiClaims": [
{
"name": "conference-api",
"type": "internal",
"serviceName": "conference-ms"
}
]
},
{
"name": "conference-details",
"customElement": "conference-details",
"stack": "react",
"type": "widget",
"group": "free",
"publicFolder": "public",
"titles": {
"en": "conference-details",
"it": "conference-details"
},
"commands": {
"run": "npm install && PORT=3001 npm start"
},
"apiClaims": [
{
"name": "conference-api",
"type": "internal",
"serviceName": "conference-ms"
}
]
},
{
"name": "conference-form",
"customElement": "conference-form",
"stack": "react",
"type": "widget",
"group": "free",
"publicFolder": "public",
"titles": {
"en": "conference-form",
"it": "conference-form"
},
"commands": {
"run": "npm install && PORT=3002 npm start"
},
"apiClaims": [
{
"name": "conference-api",
"type": "internal",
"serviceName": "conference-ms"
}
]
}
],
```

5. Finally, move the Blueprint-provided auxiliary service definitions into the `svc` directory in the bundle project and enable the `keycloak` service for local tests:
6. Finally, move the Blueprint-provided auxiliary service definitions into the `svc` directory in the bundle project and enable the `keycloak` service for local testing:
```shell
mv microservices/conference-ms/src/main/docker/* svc/
ent bundle svc enable keycloak
Expand Down
2 changes: 1 addition & 1 deletion vuepress/docs/next/tutorials/create/ms/run-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ent bundle svc start keycloak
``` sh
ent bundle run conference-ms
```
To check that the MS is working, go to `http://localhost:8081/`. In local development, the run command can be used to modify the port to run multiple microservices, but in production, microservices must run on port 8081.
To check that the MS is working, go to `http://localhost:8081/`. In local development, custom commands can be used to modify ports to run each microservice, but in production, microservices must run on port 8081.

>1. If you want to reset the conference-ms data, and you selected "H2 with disk-based persistence" during microservice generation, you can delete the target folder, restart the microservice, and the data will be regenerated.
>2. The `serviceUrl` variable is the microservice API URL.
Expand Down