Skip to content

Commit

Permalink
monorepo vs multirepo
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Jan 13, 2024
1 parent e7f02db commit 90c1ff4
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 1 deletion.
153 changes: 152 additions & 1 deletion pages/guides/ci-cd/jenkins-docker-ci-cd.en-UZ.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,155 @@ post {
}
}
```
Jarayon tugallangandan so'ng (muvaffaqiyatsiz bo'lsa ham), **discordSend** qadami bajariladi. U **DISCORD_WEBHOOK** da saqlangan webhook URL manzilidan foydalanib, Discord channelga notification(xabar) yuboradi. Xabarda natija, Git omboriga havola va job nomi kabi ma'lumotlar mavjud.
Jarayon tugallangandan so'ng (muvaffaqiyatsiz bo'lsa ham), **discordSend** qadami bajariladi. U **DISCORD_WEBHOOK** da saqlangan webhook URL manzilidan foydalanib, Discord channelga notification(xabar) yuboradi. Xabarda natija, Git omboriga havola va job nomi kabi ma'lumotlar mavjud.

Qisqa qilib aytganda ushbu boshlang'ich sodda pipeline ishga tushganida biinchi **Clean Workspace** bosqichida **cleanWs()** bilan worskspaceni tozalaydi keyingi **Clone Repository** bosqichida berilgan **GIT_URL**, **GIT_TOKEN** va **BRANCH_NAME** bilan Git repositoriyani klon qilib oladi. Oxirgi bosqichda pipeline muvaffaqiyatli(**SUCCSES**) yoki muvaffaqiyatsiz(**FAILED**) bo'lgani haqida Discord channelga notification(xabar) yuboradi.

Keling pipelineni ishga tushiramiz. **-> Build Now**

> ![netflix](/images/article/netflix/jenkins5.png)
SIzda quyidagi natijha bilan muvaffaqiyatli ishga tushishi va discordga notification yuborilishi kerak.

> ![netflix](/images/tutorials/ci-cd/jenkins-docker/job4.png)
> ![netflix](/images/tutorials/ci-cd/jenkins-docker/discord10.png)
## Git repositoriyalar bilan ishlash (mono repo va multi repo)

Bizda har xil vaziyat bo'lishi mumkin loyihamiz mono repo yoki multi repo bo'lishi mumkin.

**Monorepo (Monolithic Repository)->** `monolithic repository` so'zining qisqartmasi **monorepo** - bu bir nechta loyihalar, applicationlar yoki servicelar bitta repositoriyada saqlanadigan version control system (VCS) strategiyasidir. Monorepoda barcha kodlar, kutubxonalar(library) va turli loyihalar uchun dependensilar(bog'liqliklar) bitta markaziy repositoriyada birgalikda boshqariladi. Ushbu yondashuv har bir loyiha yoki servicening o'z repositoriyasiga ega bo'lgan ko'p repositoriyali(multi-repo) sturukturasidan farq qiladi. Qisqa qilib aytganda butun bir tashkilot loyilari bitta repositoriyada bo'ladi.

**Multirepo (Multi-Repository)->** multi-repo yondashuvida har bir loyiha, application yoki service o'zining alohida repositoriyasiga ega. Har bir repositoriya ma'lum bir kod bazasi yoki servicega bag'ishlangan va loyihalar o'rtasidagi dependensilar versiya va paketlarni boshqarish orqali boshqariladi. Qisqa qilib ayganda har bir loyiha, application, service va boshqalar alohida alohida repositoriyalarda bo'ladi va bir-biriga bo'g'liklari bo'ladi.

**Monorepo** va **multirepo** yondashuvlarining kuchli va zaif tomonlari bor va ular orasidagi tanlov ko'pincha loyiha yoki tashkilotning o'ziga xos ehtiyojlari, ko'lami va rivojlanish ish oqimlariga bog'liq.


Agar biz CI/CD yozayotgan loyiha monorepo bo'lsa, bitta monoreponi o'zini clon qilib uni build qilib ishga tushira olamiz, Bu soddaroq bo'ladi chunki loyihalar, applicationlar, servicelar va boshqalar o'rtasidagi bo'gliklik(reference) bitta shu monorepo ichida bo'ladi.

Monorepo uchun Jenkins pipeline, faqat kerakli monorepo clon qilinadi holos.

```groovy {16-20}
pipeline {
agent any
environment {
DISCORD_WEBHOOK = credentials('discord-webhook')
GIT_URL = 'https://github.com/ismoilovdevml/devops-journey.git'
GIT_TOKEN = credentials('git-token')
BRANCH_NAME = 'main'
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Clone Repository') {
steps {
git branch: BRANCH_NAME, url: GIT_URL, credentialsId: 'git-token'
}
}
}
post {
always {
discordSend(
description: "Jenkins Pipeline Build ${currentBuild.currentResult}",
link: env.GIT_URL,
result: currentBuild.currentResult,
title: JOB_NAME,
webhookURL: env.DISCORD_WEBHOOK
)
}
}
}
```

Tashkilot loyihlari multirepo bo'lsa va biz loyihalarga CI/CD yozayotgan bo'lsak, har bir loyihada bir nechta boshqa repositoriyalarga bo'glikligi(reference) bo'ladi, shuning uchun CI/CD yozayotgan loyihamiz ishlashiga kerak bo'lgan loyiha, application,service va boshqalar repositoriyalarni ham klon qilib olishimiz va yig'ishimiz kerak bo'ladi.

Multirepo uchun Jenkins pipeline.

```groovy {6-9, 20-40}
pipeline {
agent any
environment {
DISCORD_WEBHOOK = credentials('discord-webhook')
API_GIT_URL ='https://github.com/ismoilovdevml/devops-journey-api.git'
UI_GIT_URL = 'https://github.com/ismoilovdevml/devops-journey-ui.git'
SERVICE_GIT_URL = 'https://github.com/ismoilovdevml/devops-journey-service.git'
CONFIGURATIONS_GIT_URL = 'https://github.com/ismoilovdevml/devops-journey-configurations.git'
GIT_URL = 'https://github.com/ismoilovdevml/devops-journey.git'
GIT_TOKEN = credentials('git-token')
BRANCH_NAME = 'main'
}
stages {
stage('Clean Workspace') {
steps {
cleanWs()
}
}
stage('Setup Environment') {
steps{
dir('configurations'){
git branch: BRANCH_NAME, url: CONFIGURATIONS_GIT_URL, credentialsId: 'git-token'
}
dir('devops-journey/ui'){
git branch: BRANCH_NAME, url: UI_GIT_URL, credentialsId: 'git-token'
}
dir('devops-journey/api'){
git branch: BRANCH_NAME, url: API_GIT_URL, credentialsId: 'git-token'
}
dir('devops-journey/service'){
git branch: BRANCH_NAME, url: SERVICE_GIT_URL, credentialsId: 'git-token'
}
sh "cp configurations/devops-journey/${BUILD_BRANCH}/MAIN.Dockerfile ./MAIN.Dockerfile"
sh "cp configurations/devops-journey/${BUILD_BRANCH}/API.Dockerfile ./API.Dockerfile"
sh "cp configurations/devops-journey/${BUILD_BRANCH}/UI.Dockerfile ./UI.Dockerfile"
sh "cp configurations/devops-journey/${BUILD_BRANCH}/SERVICE.Dockerfile ./SERVICE.Dockerfile"
}
}
}
post {
always {
discordSend(
description: "Jenkins Pipeline Build ${currentBuild.currentResult}",
link: env.GIT_URL,
result: currentBuild.currentResult,
title: JOB_NAME,
webhookURL: env.DISCORD_WEBHOOK
)
}
}
}
````
Multirepo uchun yozgan pipelinemizda o'zgarishlar quyidagicha **devops-journey** loyihamizda bir nechta boshqa repositoriyalarga bo'gliklari mavjuda maslaan UI, API, Service va Configurations repositoriyalarga. Ushbu loyihani Jenkins CI/CD ishga tushirihsimiz uchun ushbu repositoriyalar clon qilinb yig'ishimiz va birga ishga tushirishimiz kerak. **Setup Environment** qadami ushbu vazifani bajaradi yani Environmentni sozlaydi kerak repositoriyalarni bir joyga yig'adi.
Ushbu namunada konfiguratsiyalar ham alohida repositoriyada saqlanagnmi ko'rsatilgan yani **configurations** repositoriyada barcha loyihalar servicelar applicationlar konfiglari(masalan Dockerfayllar) branchlar nomi bilan joylashtirgan bo'ladi. **configurations** repositoriyasi tuzulishga namuna.
```bash
├── main
│ ├── API.Dockerfile
│ ├── MAIN.Dockerfile
│ ├── SERVICE.Dockerfile
│ └── UI.Dockerfile
├── dev
│ ├── API.Dockerfile
│ ├── MAIN.Dockerfile
│ ├── SERVICE.Dockerfile
│ └── UI.Dockerfile
├── stage
│ ├── API.Dockerfile
│ ├── MAIN.Dockerfile
│ ├── SERVICE.Dockerfile
│ └── UI.Dockerfile
├── prod
│ ├── API.Dockerfile
│ ├── MAIN.Dockerfile
│ ├── SERVICE.Dockerfile
│ └── UI.Dockerfile
```

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 90c1ff4

Please sign in to comment.