Skip to content

Commit 720bc6f

Browse files
committed
add changes 🔑
1 parent 4e521de commit 720bc6f

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

chapter10/chapter10.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ To install Git for your OS, download a package from [the official website](http:
937937

938938
**Figure 10-4.** Configuring and testing the Git installation
939939

940-
<span id="generating-ssh-keys" class="anchor"><span id="sshkey" class="anchor"></span></span>Generating SSH Keys
940+
Generating SSH Keys
941941
----------------------------------------------------------------------------------------------------------------
942942

943943
SSH keys provide a secure connection without the need to enter username and password every time. For GitHub repositories, the latter approach is used with HTTPS URLs (e.g., `https://github.com/azat-co/rpjs.git`) and the former with SSH URLs (e.g., `[email protected]:azat-co/rpjs.git`).

chapter15/chapter15.md

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,20 @@ There's a fancy term in computer science which will make you look smart (if you
1616

1717
As with many tech concepts, microservices technology goes through the cycle of over hype. There are advantages and disadvantages. Uber for example has over 2500 microservices and its engineers hate it cause of complexity and other issue of managing so many separate apps. Hate it or love it, the best thing is to know how to use it and use microservices when you see a fit. Again, Node is brilliant at that cause it's light weight, fast and because most developers are lazy to learn or code in a normal server-side language like Go or Java.
1818

19-
Before doing the exercise in this chapter, make sure you have the following:
19+
The project of creating microservice in container and deploying it to cloud is divided into three parts:
20+
21+
1. Creating a local Node project which is a microservice RESTful API that connects to MongoDB
22+
1. Dockerizing Node project, i.e., turning a local project into a Docker image
23+
1. Use Docker networks for multi-container setup
24+
1. Deploying Docker microservice image to cloud namely Amazon Web Services Elastic Container Service
25+
26+
# Installing Installations
27+
28+
But before doing the exercise in this chapter, make sure you have the following:
2029

2130
1. Docker engine
22-
1. AWS account
23-
1. AWS CLI
31+
1. Amazon Web Services (AWS) account
32+
1. AWS CLI (`aws-cli`)
2433

2534

2635
## Installing Docker Engine
@@ -125,14 +134,12 @@ sudo -H pip install awscli --upgrade --ignore-installed six
125134
Python at least 2.6.5 or 3.x (recommended), see here: <http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html>. At <https://www.python.org/downloads/> you can download Python for your OS.
126135

127136

128-
### Other AWS CLI Installations
137+
There are a few other AWS CLI Installation options:
129138

130139
* [Install the AWS CLI with Homebrew](http://docs.aws.amazon.com/cli/latest/userguide/cli-install-macos.html#awscli-install-osx-homebrew) - for macOS
131140
* [Install the AWS CLI Using the Bundled Installer (Linux, macOS, or Unix)](http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-bundle.html) - just download, unzip and execute
132141

133-
### Verify AWS CLI
134-
135-
Run the following command to verify AWS CLI installation and its version (1+ is ok):
142+
You might be wondering how to verify AWS CLI installation. Run the following command to verify AWS CLI installation and its version (1+ is ok):
136143

137144
```bash
138145
aws --version
@@ -142,13 +149,8 @@ aws --version
142149

143150
Before deploying anything in the cloud let's build Node app Docker images locally. Then run container in development and production modes locally as well. When you finish this project, you will get 🍍.
144151

145-
The project is divided into three parts:
146152

147-
1. Create Node project
148-
1. Dockerize Node project
149-
1. Use Docker networks for multi-container setup
150-
151-
## 1. Create/Copy Node project
153+
## 1. Creating/Copying the Node Project
152154

153155
Firstly, you need to have the application code itself before you can containerize anything. Of course, you can copy the existing code from code/banking-api but it's better for learning to create the project from scratch.
154156

@@ -308,9 +310,7 @@ CMD ["npm", "start"]
308310

309311
Next we will learn what these statements mandate Docker to do.
310312

311-
## Create app directory
312-
313-
The next "commands" in your Dockerfile will tell Docker to create a folder and the to set up a default folder for subsequent commands:
313+
Firstly, create app directory in the docker container. So the next "commands" in your Dockerfile will tell Docker to create a folder and the to set up a default folder for subsequent commands:
314314

315315
```
316316
# Create api directory
@@ -344,7 +344,7 @@ CMD [ "npm", "start" ]
344344

345345
By now the Dockerfile, which is a blueprint for your Node microservice, is ready. The code for the microservice is ready too. It's REST API with Express.
346346

347-
## Build and Verify Container
347+
Next, building, running and verifying the container.
348348

349349
Build the image from the banking-api folder where you should have Dockerfile and the `api` folder:
350350

@@ -401,6 +401,7 @@ Put the IP in the environment variable in the run command for the Docker build o
401401
docker run --rm -t --name banking-api -e NODE_ENV=development -e DB_URI="mongodb://{host-ip}:27017/db-prod" -v $(pwd)/api:/usr/src/api -p 80:3000 {app-image-id}
402402
```
403403

404+
This command has IP and my image ID in the command instead of `{}` values. Don't copy my command as-is but put your IP and image ID though.
404405

405406
```
406407
docker run --rm -t --name banking-api -e NODE_ENV=development -e DB_URI="mongodb://10.0.1.7:27017/db-prod" -v $(pwd)/api:/usr/src/api -p 80:3000 330df9053088
@@ -420,14 +421,14 @@ app.get('/accounts', (req, res, next)=>{
420421
})
421422
```
422423

423-
Hit save in your editor on your host and boom. You'll see the changes in the response from the app container:
424+
Hit save in your editor on your host and boom! You'll see the change in the response from the app container. The change is the `a:1` response instead of the empty response `[]` as before. This means that the code *in the container* is changing because of the volume and the changes *in the host*. See what I have here as the CURL request and microservice's response:
424425

425426
```
426427
curl localhost/accounts
427428
[{"a":1}]%
428429
```
429430

430-
To stop the container, run
431+
To stop the container, simply run the `stop` command with the container name which you specified when you run the `docker run` command. Here's the stop command for the `banking-api` name:
431432

432433
```
433434
docker stop banking-api
@@ -544,8 +545,7 @@ Using the similar approach, you can launch other apps and services into the same
544545

545546
Note: The older `--link` flag/option is deprecated. Don't use it. See <https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks>
546547

547-
548-
## Troubleshooting
548+
Let me share some of the common issues and their solutions for easy and effortless troubleshooting. Here's the top list:
549549

550550
* No response: Check that the port is mapped in the `docker run` command with `-p`. It's not enough to just have `EXPOSE` in Dockerfile. Developers need to have both.
551551
* The server hasn't updated after my code change: Make sure you mount a volume with `-v`. You don't want to do it for production though.
@@ -554,9 +554,9 @@ Note: The older `--link` flag/option is deprecated. Don't use it. See <https://d
554554

555555
# Node Containers in AWS with EC2 ECS
556556

557-
For the next topics, we will learn how to deploy Node microservices into cloud. ☁️
557+
For the next topics, we will learn how to deploy Node microservices into cloud. ☁️ When you are done, write me a post card and send it with a pigeon.
558558

559-
Deploy two containers (API and DB) which connect using ECR and EC2 ECS is achieved with the following steps:
559+
The goal is to deploy two containers (API and DB) which connect using ECR and EC2 ECS is achieved with the following steps:
560560

561561
1. Create registry (ECR)
562562
1. Upload the app image to ECR
@@ -690,7 +690,7 @@ Go to the Task Definitions in EC2 ECS and as you might guess, press on the butto
690690

691691
![](media/aws-ecs-6.png)
692692

693-
## Main Task settings for the example
693+
### Main Task settings for the example
694694

695695
Use the following settings for the task to make sure your project is running (because some other values might make the project nonfunctional):
696696

@@ -701,7 +701,7 @@ Use the following settings for the task to make sure your project is running (be
701701

702702
Let's define the first container — app.
703703

704-
## First container—App
704+
### First container—App
705705

706706
Enter the name: banking-api-container.
707707

@@ -734,7 +734,7 @@ See the screengrab below:
734734
![](media/aws-ecs-8.png)
735735

736736

737-
## Second container—Database
737+
### Second container—Database
738738

739739
Analogous to the previous container, define name and URL with these values:
740740

@@ -781,7 +781,7 @@ ECS creates a lot of EC2 resources for you such as Internet Gateway, VPC, securi
781781
![](media/aws-ecs-14.png)
782782

783783

784-
## 4. Create Service and Verify
784+
## 4. Creating Cloud Container Service and Verifying
785785

786786
The last step is to create a service which will take the task and the cluster and make the containers in the task run in the specified cluster. It's oversimplified explanation because service will do more such as monitor health and restart containers.
787787

@@ -790,26 +790,30 @@ Go to Create Services which is under Task Definition -> banking-api-task -> Acti
790790
![](media/aws-ecs-15.png)
791791

792792

793-
## Everything is ready
793+
### Everything is ready
794794

795795
Phew. Everything should be ready by now. To verify, we need to grab a public IP or public DNS. To do so, click Clusters -> banking-api-cluster (cluster name) -> ESC Instances (tab) and Container instance:
796796

797797
![](media/aws-ecs-16.png)
798798

799799
Copy public IP or DNS 📝. We will need it for testing.
800800

801-
## Dynamic Test
801+
### Dynamic Test
802802

803803
To test the dynamic content (content generated by the app with the help of a database), open in browser with `{PUBLIC_DNS}/accounts`. Most likely the response will be `[]` because the database is empty but that's a good response. The server is working and can connect to the database from a different container.
804804

805805

806-
## Static Test
806+
### Static Test
807807

808808
To test the static content such as an image which was downloaded from the Internet by Docker (ADD in Dockerfile) and baked into the image, navigate to http://{PUBLIC_DNS}/node-university-logo.png to see the images with Docker downloaded via `ADD`. Using ADD, you can fetch any data such as HTTPS certificates (from a private S3 for example).
809809

810-
## Terminate Service and Cluster/Instances
810+
## 5. Terminate Service and Cluster/Instances
811811

812-
Don't forget to terminate your service and instances. You can do it from the web console.
812+
Don't forget to terminate your service and instances. Otherwise you will be stil paying dinero for running those could resources. (I am sure you can find a better way to spend the money. For example, buy some DOGECOIN.) You can terminate resources from the AWS web console. Do so for ECS first. Make sure you remove tasks.
813813

814814
Summary
815815
=======
816+
817+
Microservices is an old concepts when you think about it as decoupling and loose coupling. The less functionality you pack into an application, the more flexible and easier it will be to scale different parts of the app(s) or to maintain them (make changes). There are certain downsides of microservices as well. Uber engineers are crying because they have 2,500+ microservices with all the overhead involved in managing their environments, provisioning, patches and deployments. Luckily, containers and cloud services such as Docker and AWS ECS are here to help in reducing this complexity and management of microservices.
818+
819+
In this chapter you've built your own microservices which connect to another service (MongoDB) both locally and in the cloud. You used Docker by the way of making an image. What's great about this dockerization is that your project is extremely portable. It's mostly independent of OS or any other discrepancies which often can bite a developer in a tail.

0 commit comments

Comments
 (0)