Skip to content

Commit 00912a8

Browse files
authored
Add "new microservice" docs (#3033)
* Add new microservice docs * Add new microservice docs
1 parent e94eb63 commit 00912a8

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

docs/adding-new-microservice.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Adding a new microservice
2+
3+
This document outlines the steps required to add a new microservice to the Online Boutique application.
4+
5+
## 1. Create a new directory
6+
7+
Create a new directory for your microservice within the `src/` directory. The directory name should be the name of your microservice.
8+
9+
## 2. Add source code
10+
11+
Place your microservice's source code inside the newly created directory. The structure of this directory should follow the conventions of the existing microservices. For example, a Python-based service would include at minimum the following files:
12+
13+
- `README.md`: The service's description and documentation.
14+
- `main.py`: The application's entry point.
15+
- `requirements.in`: A list of Python dependencies.
16+
- `Dockerfile`: To containerize the application.
17+
18+
Take a look at existing microservices for inspiration.
19+
20+
## 3. Create a Dockerfile
21+
22+
Create a `Dockerfile` in your microservice's directory. This file will define the steps to build a container image for your service.
23+
24+
Refer to this example and tweak based on your new service's needs: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/src/frontend/Dockerfile
25+
26+
## 4. Create Kubernetes manifests
27+
28+
Create a new directory under `kustomize/components/` in the root of the repository for your microservice. Inside this directory, add the necessary Kubernetes YAML files for your new microservice. This typically includes:
29+
30+
- A **Deployment** to manage your service's pods.
31+
- A **Service** to expose your microservice to other services within the cluster.
32+
33+
Ensure you follow the existing naming conventions and that the container image specified in the Deployment matches the one built by your `cloudbuild.yaml` and `skaffold.yaml` files.
34+
35+
Refer to this example and tweak based on your new service's needs: https://github.com/GoogleCloudPlatform/microservices-demo/tree/main/kustomize/components/shopping-assistant
36+
37+
## 5. Update the root `kustomization.yaml` file
38+
39+
Add your newly created component to the root kustomization file so it gets picked up by the deployment cycle.
40+
41+
The file is available here: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/kustomize/kustomization.yaml
42+
43+
## 6. Update the root `skaffold.yaml`
44+
45+
Add your newly created service to the root skaffold file so the images build correctly.
46+
47+
The file is available here: https://github.com/GoogleCloudPlatform/microservices-demo/blob/main/skaffold.yaml
48+
49+
## 7. Update the Helm chart
50+
51+
Add your newly created service to the Helm chart templates and default values.
52+
53+
The chart is available here: https://github.com/GoogleCloudPlatform/microservices-demo/tree/main/helm-chart
54+
55+
## 8. Update the documentation
56+
57+
Finally, update the project's documentation to reflect the addition of your new microservice. This may include:
58+
59+
- Adding a section to the main `README.md` if the service introduces significant new functionality.
60+
- Updating the architecture diagrams in the `docs/img` directory.
61+
- Adding a new document in the `docs` directory if the service requires detailed explanation.

docs/development-guide.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ This doc explains how to build and run the Online Boutique source code locally u
5454
gcloud auth configure-docker -q
5555
```
5656
57-
3. In the root of this repository, run `skaffold run --default-repo=us-docker.pkg.dev/[PROJECT_ID]/microservices-demo`,
58-
where [PROJECT_ID] is your GCP project ID.
57+
3. In the root of this repository, run:
58+
59+
```
60+
skaffold run --default-repo=us-docker.pkg.dev/PROJECT_ID/microservices-demo
61+
```
62+
63+
Where `PROJECT_ID` is replaced by your Google Cloud project ID.
5964
6065
This command:
6166
62-
- builds the container images
63-
- pushes them to AR
64-
- applies the `./kubernetes-manifests` deploying the application to
67+
- Builds the container images.
68+
- Pushes them to AR.
69+
- Applies the `./kubernetes-manifests` deploying the application to
6570
Kubernetes.
6671
6772
**Troubleshooting:** If you get "No space left on device" error on Google
@@ -114,6 +119,11 @@ This doc explains how to build and run the Online Boutique source code locally u
114119

115120
6. Navigate to `localhost:8080` to access the web frontend.
116121

122+
## Adding a new microservice
123+
124+
In general, the set of core microservices for Online Boutique is fairly complete and unlikely to change in the future, but it can be useful to add an additional optional microservice that can be deployed to complement the core services.
125+
126+
See the [Adding a new microservice](adding-new-microservice.md) guide for instructions on how to add a new microservice.
117127

118128
## Cleanup
119129

0 commit comments

Comments
 (0)