You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A system context diagram (SCD) in engineering is a high level view of a system that defines the boundary between the system, or part of a system, and its environment, showing the entities that interact with it.
*One codebase tracked in revision control, many deploys*. <br />
143
137
@@ -148,7 +142,7 @@ In this repository two branches have been created:
148
142
2.**dev** branch for the development.
149
143
The source code has been tracked using the Github platform, and every team member contributes using pull requests
150
144
mechanism.
151
-
145
+
---
152
146
# 2 - Dependencies
153
147
*Explicitly declare and isolate dependencies*. <br />
154
148
@@ -169,6 +163,7 @@ Visual Studio can restore packages automatically when it builds a project, and y
169
163
nuget restore
170
164
```
171
165
Package Restore first installs the direct dependencies of a project as needed, then installs any dependencies of those packages throughout the entire dependency graph.
166
+
---
172
167
# 3 - Configuration
173
168
*Store config in the environment*. <br />
174
169
@@ -177,27 +172,42 @@ According to our application, the database connection string is considered a con
177
172
178
173
### Environmental Variables for the Error Message API
179
174
180
-
In the Docker Compose file, under the environment, two variables are defined (MongoDB__URL, Mongo_DB), the values of the two varaibles are stored in the OS environmental Variables.
175
+
In the Docker Compose file, under the environment, four variables are defined (Host, MONGO_ROOT_USER, MONGO_ROOT_PASSWORD, DB_Name), the values of the four varaibles are stored in the user environmental Variables.
181
176
177
+
#### ErrorMessage API
182
178
```
183
179
environment:
184
-
MongoDB__URL: ${ConnectionString}
185
-
Mongo_DB: ${DB_Name}
180
+
Host: ${Host}
181
+
username: ${MONGO_ROOT_USER}
182
+
password: ${MONGO_ROOT_PASSWORD}
183
+
database: ${DB_Name}
186
184
```
187
-
Besides, the Mongo database credentials are stored in the docker compose file such as the following:
185
+
The four env. variables are read in code to consturct the URL of the mongo database in the Class Name [MongoDbConfig.cs](https://github.com/eng-aomar/ErrorMessagesAPI/blob/master/Config/MongoDbConfig.cs)
186
+
Besides, the Mongo database and the mongo express credentials are stored in the docker compose file such as the following:
In K8s, the configeration is satisied by using secert file to store the base64 encrypted passwords [Mongo-Sercert](https://github.com/eng-aomar/ErrorMessagesAPI/blob/master/k8s/mongo-secret.yml)
201
+
202
+
---
193
203
# 4 - Backing services
194
204
*Treat backing services as attached resources*. <br />
195
205
196
206
Anything external to a service is treated as an attached resource, including other services. In general, backing services are those that our application consumes over the network as part of its normal process.
197
207
In our case, MongoDB is considered a backing service, that can be accessed using the credentials stored in the config file (see factor #3).
198
208
Applying this factor ensures that every service is completely portable and loosely coupled to the other resources in the system. Strict separation increases flexibility during development, developers only need to run the services they are modifying, not others. A database (Mongo DB) should be referenced by a simple endpoint (URL) and credentials, if necessary.
199
209
200
-
210
+
---
201
211
# 5 - Build / Release / Run
202
212
*Strictly separate build and run stages*. <br />
203
213
@@ -207,6 +217,8 @@ In order to transform our codebase to a deploy, we should pass 3 stages: </br>
207
217
2- *Release stage*, where we combines the build produced in the previous stage, with the deploy config. Therefore, ready to be executed. Note that each release must have a unique ID, and using the release management tools we can rollback to previous releases. </br>
208
218
3- *Run stage*, where we run the application in the execution environment.</br>
209
219
220
+
The Whole pipline is automated using GitHub Actios By Buliding a [continous integration](https://github.com/eng-aomar/ErrorMessagesAPI/blob/master/.github/workflows/CI.yml), and a [continous delivery](https://github.com/eng-aomar/ErrorMessagesAPI/blob/master/.github/workflows/CD.yml) for our API.
221
+
210
222
A release is deployed on the execution environment and must be immutable.
In the Dockor-Compose we connect three images ( MessagAPI, Mongo, Mongo-express). Docker compose creat the defualt network between the images. Regarding the mongo image, we define the mongo-data volume locally inside the conatiner to presist the data. The Mongo-express is used to provide a simple interface to the mongo database. Mongo-express can be accessed using the following url (http://localhost:8081/). By defualt mongo database has alreday three pre-defined databases as the picture shows. We add messagedb database and Message collection to it.
*Execute the app as one or more stateless processes*. <br />
532
516
Every meaningful business application creates, modifies, or uses data. In IT, a synonym for data is state. An application service that creates or modifies persistent data is called **stateful component**. In general, database services are stateful component. On the other hand, application components that do not create or modify persistent data are called **stateless components**.
533
517
Stateless components are *easier* and *simpler* to handle and can be easily scaled-up and down compared with stateful components. Moreover, they can easily restarted on a completely different node because they have no persistent data associated with them.
518
+
519
+
#### Error Messsage API is a statless application as we don't store data inside our API, we use backing services [mongo database] to store our data.
534
520
521
+
---
535
522
# 7- Port Binding
536
523
*Export services via port binding*. <br />
537
524
This factor talks about exposing the application services to the outside world using port binding.
538
525
In general, docker containers can connect to the outside world without further configuration, but the outside world cannot connect to Docker containers by default. To allow communication between different containers in the same network we need to publish our container on one or more ports, and this is done by the **expose command**.
539
526
In our DockerFile, we put the **Expose 80** command (we can put any port number), this tells Docker that our container’s service can be connected to on port 80.
540
527
**Note**: The ports are configured with the "HOST_PORT:CONTAINER_PORT" syntax.
541
528
529
+
#### In our API, Port binding is satisfied using both Docker-Compose file and K8S YAML (deployment, service) files, as the service of each application forwards the traffic to the specified port
530
+
using Target port, that points to the container port.
531
+
532
+
---
542
533
# 8- Concurrency
543
534
*Scale out via the process model*. <br />
544
535
@@ -557,12 +548,15 @@ For more details, you can click [here]: {https://pspdfkit.com/blog/2018/how-to-u
557
548
558
549
Moreover, Kubernetes also allows us to scale the stateless application at runtime by defining the **ReplicaSet**, where it automatically scale the number of pods with that number.
559
550
551
+
---
560
552
# 9- Disposability
561
553
*Maximize robustness with fast startup and graceful shutdown*. <br />
562
554
The different instances of our application are disposable, which means that they can started or stopped at any moment. This actually facilitate the scalability and deployment for the application.
563
-
This is achieved in out application when we use **volumes**, storing long-term persistent data outside the container (in an external-to-Docker database, in Docker volumes) means that we can desdtriy any container without affecting the user experienceز
555
+
This is achieved in out application when we use **volumes**, storing long-term persistent data outside the container (in an external-to-Docker database, in Docker volumes) means that we can desdtriy any container without affecting the user experience.
564
556
557
+
Pods in K8S are considered stateless ephemeral objects, they can be stopped, started, and deleted gracefully, without the knowledge of the end-users.
565
558
559
+
---
566
560
# 10- Dev/prod parity
567
561
*Keep development, staging, and production as similar as possible.*
568
562
@@ -576,12 +570,32 @@ What does that mean for our Application?
576
570
WE use continuous deployment to minimize the gap between deveoplment and production, by pushing the docker image continously into docker hub on push and pull reguest of the
577
571
master branch.
578
572
573
+
---
579
574
# 11- Logs
580
575
*Treat logs as event streams*. </br>
581
576
Logs are the stream of aggregated, time-ordered events collected from the output streams of all **running processes and backing services.**
582
577
583
578
The ```docker logs [OPTIONS] CONTAINER_NAME``` command shows information logged by a running container.
584
579
For more details you can read [this article] {https://docs.docker.com/engine/reference/commandline/logs/}
585
580
581
+
---
586
582
# 12- Admin processes
587
583
*Run admin/management tasks as one-off processes.*
584
+
In our case we stored the TAML files for both kubernetes and docker-compose ready to deploy our apps in any envionment in the same repostory.
585
+
You can find all needed YAML files in the following folder [k8s](https://github.com/eng-aomar/ErrorMessagesAPI/tree/master/k8s)
586
+
587
+
---
588
+
# 13- Open API Spesification:
589
+
590
+
In our API we used the [Swagger OpenAPI](https://swagger.io/) for documentation.
591
+
**Swagger** is used together with a set of open-source software tools to design, build, document, and use RESTful web services.
592
+
593
+
We integrate our dotnet cor api with swagger using the following code in [startup.cs](https://github.com/eng-aomar/ErrorMessagesAPI/blob/master/Startup.cs)
594
+
595
+
In order to view the documentation of our API, you are supposed to run the project and go to this link:
596
+
*https://localhost:5001/swagger*
597
+
598
+
<sub>Note: The port number may be different in your run.</sub>
0 commit comments