Skip to content

Commit c13afb3

Browse files
committed
feat: add architecture documentation
1 parent 0008821 commit c13afb3

4 files changed

+169
-0
lines changed

Architecture.md

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Introduction
2+
3+
At [osscameroon](https://osscameroon.com) we often build software solutions that need to be deployed on different environments.
4+
This applications are packaged in several forms such as **docker images**, **static files** or **modules**.
5+
6+
A packaged deployable application is called an **artifact**. Those artifacts are generated on CI jobs and developers will manually deploy them on our infrastructure.
7+
We currently have no nice and easy way to deploy applications automatically on both our **staging** and **production** environments.
8+
9+
That's where **Sami** comes in. **Sami** is a system that will help us better manage the creation and deployment of our artifacts.
10+
11+
12+
# Architecture
13+
14+
**Sami** is composed of several subsystems that handle the creation, storage and deployment of artifacts.
15+
16+
- A **Repository** where the code lives with **CI integrations** triggered on pull request merged.
17+
- The **Artifact Management System** that will create, store and request a deployment of your artifacts.
18+
- The **Infrastructure** your application runs on.
19+
20+
21+
22+
![image](./res/imgs/structurizr-1-AMS-Context.png)
23+
*Artifact Managment System*
24+
25+
## Repository
26+
27+
Where your application code lives. At [osscameroon](https://osscameroon.com) we store our source code on **GitHub**.
28+
This repository contains `CI` workflows that interacts with the **Artifact Managment System**.
29+
30+
## Artifact Managment System
31+
32+
The **Artifact Managment System** is responsible for the creation, storage of your artifacts,
33+
this is also where we can request the deployment of an artifact to any environment.
34+
35+
In the case of an application packaged as a **docker image**,
36+
the application repository will contain several **CI workflows** that will be triggered
37+
when a pull request gets merged into the `master/main` branch.
38+
39+
- **CI Artifact creation** workflow creates a docker image and pushes it to a **docker container registry**.
40+
- **CI Artifact deployment** request a deployment of the newly created docker image in our infrastructure.
41+
42+
43+
44+
![image](./res/imgs/structurizr-1-AMS-Containers.png)
45+
*Artifact Managment System Containers*
46+
47+
### CI Artifact creation
48+
The Artifact creation CI is a reusable [GitHub Action](https://github.com/features/actions) that creates your artifacts, tags it and pushes it to an Artifact Registry.
49+
For a docker image that action will create the image and push it either on the [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry) or to [DockerHub](https://hub.docker.com/)
50+
51+
*Note: we have built an Artifact Creation workflow [here](https://github.com/osscameroon/camerdevs/blob/682256603a8bd3cb58752a66e81ce36b37a1e6d6/.github/workflows/backend-build-api-image.yaml#L41)*
52+
53+
### Artifact Registry
54+
An artifact registry designate the place your artifacts are being stored. For docker images it can be a container registry and for static files can be an s3 bucket.
55+
56+
57+
### CI Artifact deployment request
58+
This CI integration is a reusable [GitHub Action](https://github.com/features/actions) to request for your application artifact to be deployed on a specific environment.
59+
60+
*Note: we have built an Artifact Deployment workflow [here](https://github.com/osscameroon/camerdevs/blob/682256603a8bd3cb58752a66e81ce36b37a1e6d6/.github/workflows/backend-build-api-image.yaml#L49)*
61+
62+
## Infrastructure
63+
64+
The application you build and package need to run on an infrastructure. The infrasture is a set of several components that allow us deploy, run, monitor and observe our applications/services.
65+
66+
The infrastructure consists of these components:
67+
68+
- A Git repository containing your applications deployment manifests.
69+
- An instance of [Webhook](https://github.com/adnanh/webhook).
70+
- A [Swarm](https://docs.docker.com/engine/swarm/) cluster which is where application will be run and scheduled.
71+
72+
![image](/Users/elhmn/Downloads/structurizr-1-Infrastructure\ \(1\).png)
73+
*Infrastructure*
74+
75+
### GitHub Repository
76+
Your applications deployment manifests should live in a GitHub repository.
77+
This repository also contains few **CI workflows** that will update your artifact sha in the manifest
78+
and/or trigger an api call to the **Webhook** that will trigger the actual deployment on your swarm clusters.
79+
80+
**Examples:**
81+
- CI Updating the artifact sha in your manifest can found [here](https://github.com/osscameroon/deployments/blob/main/.github/workflows/deploy-service.yaml)
82+
- CI making the api call to the webhook can be found [here](https://github.com/osscameroon/deployments/blob/main/.github/workflows/apply-config.yaml)
83+
84+
#### Deployment folder structure
85+
The deployment folder should follow a very strict structure and contain a `sami.yaml` file
86+
that describe your service's deployment.
87+
88+
##### Folder
89+
90+
At the root of the [deployments folder](https://github.com/osscameroon/deployments)
91+
92+
93+
###### L0 - root
94+
95+
You can find these folder:
96+
97+
- `conf` folder container configuration for applications running on the VPS such as `nginx`.
98+
- `services` which contains a list of services.
99+
Each service folder name should match the name of your service otherwise the `sami-cli` won't be able to pick them up correctly.
100+
- `README.md` that should contain a description of the deployments folder.
101+
102+
103+
###### L1 - service_name
104+
Inside the `services/<service_name>/` folder are contained folders named after the type of deployment you want to perform
105+
The supported type of deployment can be `swarm`, `compose`, `k8s`, `cron`, `static_file` etc...
106+
107+
###### L2 - deployment_type
108+
The `services/<service_name>/<deployment_type>/` folder contain a folder named
109+
after the environment you want your application to be deployed to.
110+
The supported environment are `stage`, `production`, `pull_request`.
111+
112+
###### L3 - environment
113+
In the `service/<service_name>/<deployment_type>/<environment>` can be found
114+
a `sami.(yaml|yml)` file that describes the service we would like to deploy.
115+
116+
###### Tree
117+
```
118+
├── README.md
119+
├── conf
120+
│   └── nginx
121+
│   └── sites-enabled
122+
│   ├── camerdevs.com
123+
│   ├── grafana.osscameroon.com
124+
│   ├── portainer.osscameroon.com
125+
│   └── webhooks.osscameroon.com
126+
└── services
127+
├── camerdevs
128+
│   └── compose
129+
│   ├── prod
130+
│   └── stage
131+
│   └── camerdevs-stack.yml
132+
├── caparledev-bot
133+
│   └── compose
134+
│   └── stage
135+
│   └── caparledev-bot-stack.yml
136+
├── portainer
137+
│   └── compose
138+
│   └── prod
139+
│   └── portainer-agent-stack.yml
140+
└── prometheus
141+
└── compose
142+
└── prod
143+
├── grafana
144+
├── prometheus
145+
└── prometheus-stack.yml
146+
```
147+
148+
##### Sami's file
149+
150+
the `sami.(yaml|yml)` file describes the service we want to deploy.
151+
The file is picked up and used by the `sami-cli` in order the deploy the application on our infrastructure.
152+
153+
*Manifest*
154+
```yaml
155+
#service/<service_name>/<deployment_type>/<environment>/sami.(yml|yaml)
156+
version: v1beta
157+
158+
service_name: "camerdevs"
159+
type: "swarm"
160+
161+
#This description is not exhaustive and will be enriched as we design
162+
#the system
163+
```
164+
165+
166+
### Webhook
167+
168+
169+
### Swarm
298 KB
Loading
143 KB
Loading
323 KB
Loading

0 commit comments

Comments
 (0)