Skip to content

Commit 68fbcab

Browse files
committed
added ecs example
1 parent 80e3b4a commit 68fbcab

34 files changed

+9883
-0
lines changed

examples/AWS-ECS/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

examples/AWS-ECS/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM --platform=linux/amd64 node:13-alpine
2+
3+
ENV MONGO_DB_USERNAME=admin \
4+
MONGO_DB_PWD=password
5+
6+
RUN mkdir -p /home/app
7+
8+
COPY ./app /home/app
9+
10+
WORKDIR /home/app
11+
12+
RUN npm install
13+
14+
CMD ["node", "server.js"]
15+

examples/AWS-ECS/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## ECS Test CASE
2+
3+
ECS clustter is deployed with following process:
4+
- build Docker Image
5+
- upload to Docker hub or ECR
6+
- update docker-compose file
7+
- create and use docker context
8+
- deploy application
9+
10+
### If want to install Chronos as dependency (optional)
11+
12+
1: add a `.env` file to the *server* folder that contains the following key/value pairs:
13+
- `CHRONOS_DB`: `MongoDB` or `PostgreSQL`
14+
- `CHRONOS_URI`: The URI to the desired MongoDB or PostgreSQL database to save health metrics via **Chronos**
15+
16+
2: Then look at the `package.json` file in the server folder and note how `@chronosmicro/tracker` is included as a dependency:
17+
- If the @chronosmicro/tracker dependency is listed as a remote npm package (i.e. `"@chronosmicro/tracker": "^8.0.1"`), no further work is needed.
18+
19+
- If the @chronosmicro/tracker dependency is listed as a local npm package (i.e. `"@chronosmicro/tracker": "file:./chronos_npm_package"`), the Docker build will require that the the Chronos code is in this folder. Copy the _chronos_npm_package_ folder in manually.
20+
21+
### Deploy application in ECS
22+
23+
Step 1: build Docker Image
24+
```
25+
docker build -t ecs-test:1.0 .
26+
```
27+
* If you want to change name and/or tag of docker image, please make sure to update docker-compose.yaml file accordingly. And do Not miss the . at the end as it denotes location of the Dockerfile
28+
29+
Step 2: docker-compose to test out image (image is stored locally right now)
30+
```
31+
docker-compose -f docker-compose.yaml up
32+
```
33+
Step 3: Upload image to docker hub or ECR, update docker-compose.yaml with new URI of image
34+
- you only need to update the image for ecs-test, mongo and mongo-express are pulled from docker public library
35+
36+
Step 4: Set up AWS account, grant access to floowing AWS IAM permissions listed [here](https://docs.docker.com/cloud/ecs-integration/#requirements). Some other permissions you would need includes:
37+
* iam:DeleteRolePolicy
38+
* iam:PutRolePolicy
39+
* ecr:GetAuthorizationToken
40+
* logs:TagResource
41+
* elasticfilesystem:CreateFileSystem
42+
43+
If you push docker image in ECR you might need additional permission as well.
44+
45+
Step 5: Generate access key in IAM -> Users -> yourusername -> secureity credentials -> Access Keys. _Make sure you save your secret access key as it is only accessible once when generated._
46+
47+
Step 6: Create and use AWS context, follow instruction [here](https://docs.docker.com/cloud/ecs-integration/#requirements).
48+
49+
Step 7: Deploy test application in ECS
50+
```
51+
docker compose up
52+
```
53+
### some notes about the ecs-test
54+
55+
The way deployment set up is using Fargate, you will not be able to see graph in cluster->metrics. Instead, check inside services or cloudwatch. The ultimate visulization is in Chronos!!!
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const path = require('path');
2+
require('dotenv').config({path: path.resolve(__dirname, './.env')});
3+
4+
module.exports = {
5+
// General configuration
6+
microservice: 'ecs-test',
7+
interval: 5000,
8+
9+
// Mode Specific
10+
mode: 'microservices',
11+
dockerized: true,
12+
13+
database: {
14+
connection: 'REST',
15+
type: process.env.CHRONOS_DB,
16+
URI: process.env.CHRONOS_URI,
17+
},
18+
19+
notifications: [],
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

0 commit comments

Comments
 (0)