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-575 Update the jhipster tutorial for Docker-based format in Ent… #581

Merged
merged 6 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -1,81 +1,67 @@
---
sidebarDepth: 2
---

# Generate Microservices and Micro Frontends

## Overview

This tutorial describes how to use the Entando Component Generator (ECG) to create microservices and micro frontends for deployment to the [Entando Component Repository](../../../docs/compose/local-hub-overview.md) and Entando Applications. The ECG is powered by [JHipster](https://www.jhipster.tech/) and leverages the Entando Blueprint.

![Entando Component Generator](./img/component-gen-flow.png)
This tutorial describes how to use the Entando Component Generator (ECG) to create microservices and micro frontends for deployment to the [Local Hub](../../../docs/compose/local-hub-overview.md) of an Entando Application or a shared [Entando Hub](../../../docs/getting-started/landing-page.md#entando-hub). The ECG is powered by [JHipster](https://www.jhipster.tech/) and leverages the Entando Blueprint.

The general flow of component generation is:

1. Run the Entando Blueprint to create your components (Spring Boot microservice and optionally React micro frontends)
2. Customize and enhance your generated code
3. Build an Entando Bundle from your components
4. Deploy a [custom resource](../../../docs/consume/custom-resources.md) for your bundle into Kubernetes
5. Install your Entando Bundle into your Entando Application(s)
The output of this tutorial is [a new bundle project](../../../docs/curate/bundle-details.md#bundle-development-process) with several components:
Copy link
Contributor

Choose a reason for hiding this comment

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

the first word of each bulleted line item below should be capitalized (or use 3 for the second bullet)

- A Spring Boot microservice with CRUD operations for a single database entity
- Three React micro frontends for displaying and managing the entity

## Prerequisites
Use the [Entando CLI](../../../docs/getting-started/entando-cli.md#check-the-environment) to verify environmental dependencies (e.g. Java, npm, git, JHipster, Entando Blueprint).
``` sh
ent check-env develop
```

## Generate the Project
Create a project with microservices.

1. Setup a new project directory
``` sh
mkdir testProject && cd testProject
- [A working instance of Entando](../../../docs/getting-started/)
- Verify dependencies with the [Entando CLI](../../../docs/getting-started/entando-cli.md#check-the-environment): `ent check-env develop`

## Set Up a New Bundle Project
1. Create a new bundle project directory. This will add a simple `entando.json` descriptor as a starting point.
```shell
ent bundle init YOUR-PROJECT-NAME
````

## Generate the Components
1. From the project directory, use the Entando CLI to add a basic microservice configuration to the project:
```shell
cd YOUR-PROJECT-NAME
ent bundle ms add conference-ms --stack=spring-boot
```

2. Use `ent jhipster` to generate the project skeleton via the Entando Blueprint
``` sh
ent jhipster --blueprints entando
2. From the `conference-ms` directory, use the Entando Blueprint (powered by JHipster) to generate the `conference-ms` microservice:
```shell
cd microservices/conference-ms
ent jhipster --blueprints=entando
```

3. This triggers a project initialization prompt. Enter "Yes" in response.

`The project dir doesn't seem to be initialized, should I do it now?` (**Yes**)

4. Enter "Yes" when prompted with the following overwrite to resolve the conflict:

`Overwrite .gitignore?`

5. You'll be presented with a series of additional prompts pertaining to project configuration. These are echoed below, with the base values for this tutorial in parentheses. Input your preferences, except where a required entry is identified in **bold**. Note that the `Enter` key will select the default option.

3. You'll be presented with a series of prompts pertaining to service generation. These are echoed below, with the base values for this tutorial in parentheses. Input your preferences, except where a required entry is identified in **bold**. Note that the `Enter` key will select the default option.
Copy link
Contributor

Choose a reason for hiding this comment

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

my questions/selections didn't match this exactly; i can show you what printed to the terminal

Copy link
Member Author

Choose a reason for hiding this comment

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

@Lyd1aCla1r3 the questions can differ based on answers to some questions. I went through this with the latest blueprint and thought it was consistent but let's look at what you're seeing.


- `Please provide the project name:` (Up to you)

- `What is the base name of your application?` (Up to you)
- `As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts.` (8081)
- `What is your default Java package name?` (Up to you)
- `Which *type* of database would you like to use?` (SQL)
- If no database is selected you'll be building a stateless microservice, which is a valid choice, but the rest of this tutorial won't work.
- `Which *production* database would you like to use?` (PostgreSQL or MySQL)
- `Which *production* database would you like to use?` (PostgreSQL)
- `Which *development* database would you like to use?` (H2 with disk-based persistence)
- `Which cache do you want to use? (Spring cache abstraction)` (Caffeine (local cache, for a single node))
- `Do you want to use Hibernate 2nd level cache?` (Yes)
- `Which other technologies would you like to use?` (**Don't select any other technologies**)
- `Which BE dependencies do you want to use?` (Dependencies maintained by Entando (entando/entando-bundle-bom))
- `What name would you give to the bundle to share on an Entando Component Repository?` (Up to you)
- `Which is the organization name to use when publishing the docker image?` (**Enter the name of the organization where you are going to push your Docker image. If you're using your personal Docker hub account enter your username.**) <-- this can be changed later as needed
Copy link
Collaborator

Choose a reason for hiding this comment

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

why were these two items removed? I still get them

- `Would you like to generate micro frontends when creating entities?` (Always)
- `Would you like to enable internationalization support` (Up to you)
- `Please choose the native language of the application` (Up to you)
- `Besides JUnit and Jest, which testing frameworks would you like to use?` (Up to you)
- `Would you like to install other generators from the JHipster Marketplace?` (No)

6. Next, add an Entity to your microservice and create the corresponding micro frontends. In this tutorial, `Conference` is the name of the entity that will be added to the application.
4. Enter "Yes" when prompted with the following overwrite to resolve the conflict:
Copy link
Contributor

Choose a reason for hiding this comment

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

is this step still needed? (I think it was the case because the cli created a .gitignore file but now we run the bp in a separated folder, it should be different)

Copy link
Member Author

Choose a reason for hiding this comment

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

@avdev4j The prompt was still showing up for me in my last test. We're planning to test one more time when the blueprint is finalized and can update the text to match then.


`Overwrite .gitignore?`

``` sh
5. Add an Entity to your microservice and create the corresponding micro frontends. In this tutorial, `Conference` is the name of the entity that will be added to the application.

```shell
ent jhipster entity Conference
```

7. You'll be presented with a series of prompts to add fields to your entity. These are echoed below, with the base values for this tutorial in parentheses. Input your preferences, and note that the `Enter` key will select the default option.
6. You'll be presented with a series of prompts to add fields to your entity. These are echoed below, with the base values for this tutorial in parentheses. Input your preferences, and note that the `Enter` key will select the default option.

- `Do you want to add a field to your entity?` (Yes)

Expand All @@ -98,29 +84,56 @@ ent jhipster entity Conference
- `Do you want pagination and sorting on your entity?` (Yes, with infinite scroll)
- (If you chose to be prompted to generate micro frontends) `Do you want to generate micro frontends?` (Up to you)


8. Affirm each overwrite prompt (echoed below) to resolve conflicts as the Blueprint generates controllers, repositories, services and micro frontends for your entity. **Note: Enter "a" in response to the initial prompt to authorize all overwrites to existing files with the necessary configuration changes.**
- `Overwrite src/main/resources/config/liquibase/master.xml?`
7. Affirm each overwrite prompt to resolve conflicts as the Blueprint generates controllers, repositories, services and micro frontends for your entity. **Note: Enter "a" to the initial prompt to authorize changes to all the updated files.**

- `Overwrite package.json?`
- `Overwrite bundle/descriptor.yaml?`
- `Overwrite bundle/plugins/jhipster-plugin.yaml?`
- `Overwrite src/main/resources/config/liquibase/master.xml?`
- `Overwrite src/main/java/com/mycompany/myapp/config/CacheConfiguration.java?`

You have now generated an Entando project, including a Spring Boot microservice with database integration and React-based micro frontends.
You have now generated a Spring Boot microservice with database integration and React-based micro frontends.

### Project Structure
* ```/src/main/docker``` contains Docker files to help with local development environments.
### Output
* ```/src/main/java``` and ```src/main/resources``` contain the microservice codebase and configuration.
* ```/ui``` holds the React-based micro frontends. By default, JHipster generates 3 MFEs per entity to contain the details, form, and table.
* ```/bundle``` is used to assemble the project code into an Entando Bundle.
* ```/src/main/docker``` contains Docker files to help with local development environments.

## Next Steps
Follow one of the links below to learn how to assemble and run a bundle locally or deploy it.
## 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`:
```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.
```shell
ent bundle mfe add conference-table
find microservices/conference-ms/ui/widgets/conference/tableWidget/. -mindepth 1 -maxdepth 1 -exec mv -t microfrontends/conference-table/ -- {} +
```

- [Build and publish a project bundle](../pb/publish-project-bundle.md) to deploy your microservice and micro frontends to the Entando Component Repository
- Learn how to [run Blueprint-generated components locally in dev mode](./run-local.md)
- Discover the benefits and features of [the Entando Blueprint](../../../docs/create/blueprint-features.md)
3. Now add an API claim to connect the `conference-table` MFE to the `conference-ms` microservice. The connection information is stored in the `entando-json`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

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
find microservices/conference-ms/ui/widgets/conference/detailsWidget/. -mindepth 1 -maxdepth 1 -exec mv -t microfrontends/conference-details/ -- {} +
find microservices/conference-ms/ui/widgets/conference/formWidget/. -mindepth 1 -maxdepth 1 -exec mv -t microfrontends/conference-form/ -- {} +
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
```

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:
```shell
mv microservices/conference-ms/src/main/docker/* svc/
ent bundle svc enable keycloak
```

## Next Steps
Follow one of the links below to run the bundle components locally, or build and publish the bundle into an Entando Application:

- [Run Blueprint-generated components locally in dev mode](./run-local.md)
- [Build and publish a project bundle](../pb/publish-project-bundle.md) to deploy your microservice and micro frontends to Entando
- Explore the benefits and features of [the Entando Blueprint](../../../docs/create/blueprint-features.md)
- [Iterate on your data model](./update-data-model.md) using the JHipster Domain Language (JDL)

Binary file not shown.