Quest: [Build a Website on Google Cloud](https://www.cloudskillsboost.google/quests/115)<br>
## Challenge lab scenario
You have just started a new role at FancyStore, Inc.
Your task is to take the company's existing monolithic e-commerce website and break it into a series of logically separated microservices. The existing monolith code is sitting in a GitHub repo, and you will be expected to containerize this app and then refactor it.
You are expected to have the skills and knowledge for these tasks, so don't expect step-by-step guides.
You have been asked to take the lead on this, after the last team suffered from monolith-related burnout and left for greener pastures (literally, they are running a lavender farm now). You will be tasked with pulling down the source code, building a container from it (one of the farmers left you a Dockerfile), and then pushing it out to GKE.
You should first build, deploy, and test the Monolith, just to make sure that the source code is sound. After that, you should break out the constituent services into their own microservice deployments.
Some FancyStore, Inc. standards you should follow:
- Create your cluster in `us-central1`.
- Naming is normally *team-resource*, e.g. an instance could be named **fancystore-orderservice1**.
- Allocate cost effective resource sizes. Projects are monitored and excessive resource use will result in the containing project's termination.
- Use the `n1-standard-1` machine type unless directed otherwise.
## Your challenge
As soon as you sit down at your desk and open your new laptop, you receive the following request to complete these tasks. Good luck!
## Setup
Export the following variables in the Cloud Shell:
```bash
export MONOLITH_IDENTIFIER=
export CLUSTER_NAME=
export ORDERS_IDENTIFIER=
export PRODUCTS_IDENTIFIER=
export FRONTEND_IDENTIFIER=
```
from the labs variables, you can copy the value of each variable and paste it in the cloud shell
There's a `setup.sh` script in the root directory of the project that you'll need to run to get your monolith container built up.
``` bash
cd ~/monolith-to-microservices
./setup.sh
```
After running the setup.sh script, ensure your Cloud Shell is running its latest version of nodeJS.
```bash
nvm install --lts
```
There's a Dockerfile located in the `~/monotlith-to-microservices/monolith` folder which you can use to build the application container. Before building the Docker container, you can preview the monolith application on **port 8080**.
> Note: You can skip previewing the application if you want to, but it's a good idea to make sure it's working before you containerize it.
```bash
cd ~/monolith-to-microservices/monolith
npm start
```
`CTRL+C` to stop the application.
You will have to run Cloud Build (in that monolith folder) to build it, then push it up to GCR. Name your artifact as follows:
Below is the set of services which need to be containerized. Navigate to the source roots mentioned below, and upload the artifacts which are created to the Google Container Registry with the metadata indicated. Name your artifact as follows:
**Orders Microservice**
- Service root folder: `~/monolith-to-microservices/microservices/src/orders`
- GCR Repo: gcr.io/${GOOGLE_CLOUD_PROJECT}
- Image name: `ORDERS_IDENTIFIER`
- Image version: 1.0.0
```bash
cd ~/monolith-to-microservices/microservices/src/orders
Deploy these new containers following the same process that you followed for the `MONOLITH_IDENTIFIER` monolith. Note that these services will be listening on different ports, so make note of the port mappings in the table below. Create and expose your deployments as follows:
Replace the `REACT_APP_ORDERS_URL` and `REACT_APP_PRODUCTS_URL` to the new format while replacing with your Orders and Product microservice IP addresses so it matches below.
Press **CTRL+O**, press **ENTER**, then **CTRL+X** to save the file in the `nano` editor. Now rebuild the frontend app before containerizing it.
```bash
npm run build
```
### Task 6: Create a containerized version of the Frontend microservice
The final step is to containerize and deploy the Frontend. Use Cloud Build to package up the contents of the Frontend service and push it up to the Google Container Registry.
- Service root folder: `~/monolith-to-microservices/microservices/src/frontend`
- GCR Repo: gcr.io/${GOOGLE_CLOUD_PROJECT}
- Image name: `FRONTEND_IDENTIFIER`
- Image version: 1.0.0
```bash
cd ~/monolith-to-microservices/microservices/src/frontend
Deploy this container following the same process that you followed for the **Orders** and **Products** microservices. Create and expose your deployment as follows: