This commit is contained in:
masoodafar-web
2026-01-03 18:27:49 +03:30
parent 0369292d7f
commit 5965b98728
156 changed files with 16082 additions and 0 deletions
@@ -0,0 +1,359 @@
# مدیریت Package های Proto در FourSat با GitLab Registry
> **تاریخ**: December 6, 2025
> **NuGet Server**: GitLab Package Registry (Afrino)
> **URL**: `https://git.afrino.co/api/packages/FourSat/nuget/index.json`
---
## 📊 معماری فعلی
```
┌────────────────────────────────────────────────────┐
│ LAYER 1: CMS Proto (Base) │
│ CMSMicroservice.Protobuf │
│ Version: 0.0.142 → Auto-push به GitLab │
└─────────────────┬──────────────────────────────────┘
│ PackageReference
┌────────────────────────────────────────────────────┐
│ LAYER 2: BFF Protos │
│ BackOffice.BFF.*.Protobuf (14 packages) │
│ FrontOffice.BFF.*.Protobuf (8 packages) │
│ → Depend on: CMS Proto v0.0.x │
└─────────────────┬──────────────────────────────────┘
│ PackageReference
┌────────────────────────────────────────────────────┐
│ LAYER 3: UI Applications │
│ BackOffice UI → BackOffice.BFF Protos │
│ FrontOffice UI → FrontOffice.BFF Protos │
└────────────────────────────────────────────────────┘
```
---
## 🔧 تنظیمات فعلی در csproj
شما از قبل این Target را دارید:
```xml
<Target Name="PushToFoursatNuget" AfterTargets="Pack">
<PropertyGroup>
<NugetPackagePath>$(PackageOutputPath)$(PackageId).$(Version).nupkg</NugetPackagePath>
<PushCommand>dotnet nuget push **/*.nupkg --source https://git.afrino.co/api/packages/FourSat/nuget/index.json --api-key 061a5cb15517c6da39c16cfce8556c55ae104d0d --skip-duplicate &amp;&amp; del "$(NugetPackagePath)"</PushCommand>
</PropertyGroup>
<Exec Command="$(PushCommand)" />
</Target>
```
**مزیت**: خودکار push می‌شه
⚠️ **نیاز**: فقط Version افزایش پیدا کنه
---
## 🚀 Workflow پیشنهادی
### حالت 1️⃣: Development (Local)
```xml
<!-- Debug Mode: استفاده از ProjectReference -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\..\CMS\src\CMSMicroservice.Protobuf\CMSMicroservice.Protobuf.csproj" />
</ItemGroup>
```
**مزایا**:
- تغییرات بلافاصله اعمال می‌شود
- نیازی به build/pack/push نیست
- سرعت توسعه بالا
### حالت 2️⃣: Production (Release)
```xml
<!-- Release Mode: استفاده از PackageReference -->
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.142" />
</ItemGroup>
<!-- Auto-Push Target -->
<Target Name="PushToFoursatNuget" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
<!-- ... همان کدی که دارید -->
</Target>
```
**مزایا**:
- استقلال پروژه‌ها
- Version control دقیق
- امکان Rollback
---
## 📝 مثال کامل csproj
### CMSMicroservice.Protobuf.csproj
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- Package Info -->
<PackageId>Foursat.CMSMicroservice.Protobuf</PackageId>
<Version>0.0.142</Version> <!-- 👈 این خط را با script تغییر می‌دهیم -->
<Authors>FourSat Team</Authors>
<Company>Afrino</Company>
<Description>gRPC Protobuf contracts for CMS Microservice</Description>
<RepositoryUrl>https://git.afrino.co/FourSat/cms</RepositoryUrl>
</PropertyGroup>
<!-- Dependencies -->
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.23.3" />
<PackageReference Include="Grpc.Core.Api" Version="2.54.0" />
<PackageReference Include="Grpc.Tools" Version="2.55.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- Proto Files -->
<ItemGroup>
<Protobuf Include="Protos\*.proto" ProtoRoot="Protos\" GrpcServices="Both" />
</ItemGroup>
<!-- Auto-Push به GitLab (فقط در Release mode) -->
<Target Name="PushToFoursatNuget" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
<PropertyGroup>
<NugetPackagePath>$(PackageOutputPath)$(PackageId).$(Version).nupkg</NugetPackagePath>
<PushCommand>dotnet nuget push "$(NugetPackagePath)" --source https://git.afrino.co/api/packages/FourSat/nuget/index.json --api-key 061a5cb15517c6da39c16cfce8556c55ae104d0d --skip-duplicate</PushCommand>
</PropertyGroup>
<Exec Command="$(PushCommand)" />
<!-- پاک کردن فایل بعد از push موفق -->
<Delete Files="$(NugetPackagePath)" />
</Target>
</Project>
```
### BackOffice.BFF.Products.Protobuf.csproj
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<PackageId>Foursat.BackOffice.BFF.Products.Protobuf</PackageId>
<Version>1.0.0</Version> <!-- 👈 این را با script تغییر می‌دهیم -->
</PropertyGroup>
<!-- gRPC Dependencies -->
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.28.3" />
<PackageReference Include="Grpc.Core.Api" Version="2.70.0" />
<PackageReference Include="Grpc.Tools" Version="2.68.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<!-- 🔧 Development: ProjectReference -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\..\CMS\src\CMSMicroservice.Protobuf\CMSMicroservice.Protobuf.csproj" />
</ItemGroup>
<!-- 🚀 Production: PackageReference -->
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.142" />
</ItemGroup>
<!-- Proto Files -->
<ItemGroup>
<Protobuf Include="Protos\products.proto" ProtoRoot="Protos\" GrpcServices="Both" />
</ItemGroup>
<!-- Auto-Push به GitLab -->
<Target Name="PushToFoursatNuget" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
<PropertyGroup>
<NugetPackagePath>$(PackageOutputPath)$(PackageId).$(Version).nupkg</NugetPackagePath>
<PushCommand>dotnet nuget push "$(NugetPackagePath)" --source https://git.afrino.co/api/packages/FourSat/nuget/index.json --api-key 061a5cb15517c6da39c16cfce8556c55ae104d0d --skip-duplicate</PushCommand>
</PropertyGroup>
<Exec Command="$(PushCommand)" />
<Delete Files="$(NugetPackagePath)" />
</Target>
</Project>
```
---
## 🔄 فرآیند Release جدید
### مرحله 1: افزایش Version
```bash
# افزایش Patch version (0.0.142 → 0.0.143)
./bump-version.sh patch
# افزایش Minor version (0.0.142 → 0.1.0)
./bump-version.sh minor
# افزایش Major version (0.0.142 → 1.0.0)
./bump-version.sh major
# افزایش version یک پروژه خاص
./bump-version.sh patch /path/to/Project.csproj
```
### مرحله 2: Build & Pack (Auto-Push)
```bash
# Build & Pack CMS Proto (Layer 1)
cd /home/masoud/Apps/project/FourSat/CMS/src/CMSMicroservice.Protobuf
dotnet pack -c Release
# ✅ بعد از Pack، خودکار push می‌شه به GitLab!
```
### مرحله 3: Update BFF Dependencies
```bash
# بعد از push CMS Proto، version جدید را در BFF ها update کنید:
# BackOffice.BFF.Products.Protobuf.csproj:
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.143" /> <!-- ⬅️ Update -->
</ItemGroup>
```
### مرحله 4: Build & Pack BFF Protos (Layer 2)
```bash
# Build & Pack همه BackOffice.BFF Protos
cd /home/masoud/Apps/project/FourSat/BackOffice.BFF/src/Protobufs
for dir in BackOffice.BFF.*.Protobuf; do
cd "$dir"
dotnet pack -c Release # ✅ Auto-push می‌شه
cd ..
done
```
### مرحله 5: Update UI Dependencies
```bash
# BackOffice.csproj:
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.BackOffice.BFF.Products.Protobuf" Version="1.0.1" /> <!-- ⬅️ Update -->
<!-- ... other protos -->
</ItemGroup>
```
---
## 🛠️ Scripts خودکار
### 1. `bump-version.sh` - افزایش Version
```bash
# همه Proto projects
./bump-version.sh patch
# یک پروژه خاص
./bump-version.sh minor CMS/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj
```
### 2. `release-proto.sh` - Release کامل
```bash
#!/bin/bash
# 1. Bump version
./bump-version.sh patch
# 2. Build & Pack (Auto-push)
cd CMS/src/CMSMicroservice.Protobuf
dotnet pack -c Release
# 3. Commit changes
git add .
git commit -m "chore: bump proto version"
git push
```
---
## 📊 Version Strategy
```
0.0.142 → Current CMS Proto version
│ │ │
│ │ └── PATCH: Bug fixes, compatible changes
│ └───── MINOR: New features, compatible
└────── MAJOR: Breaking changes
```
**مثال**:
- اضافه کردن فیلد جدید → **PATCH** (0.0.143)
- اضافه کردن RPC جدید → **MINOR** (0.1.0)
- تغییر signature RPC → **MAJOR** (1.0.0)
---
## 🔍 بررسی Packages روی GitLab
```bash
# اضافه کردن GitLab source
dotnet nuget add source https://git.afrino.co/api/packages/FourSat/nuget/index.json \
--name foursat-gitlab \
--username YOUR_USERNAME \
--password 061a5cb15517c6da39c16cfce8556c55ae104d0d \
--store-password-in-clear-text
# جستجو
dotnet nuget search Foursat --source foursat-gitlab
# نصب
dotnet add package Foursat.CMSMicroservice.Protobuf --version 0.0.142 --source foursat-gitlab
```
---
## ⚙️ nuget.config (Optional)
```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="foursat-gitlab" value="https://git.afrino.co/api/packages/FourSat/nuget/index.json" />
</packageSources>
<packageSourceCredentials>
<foursat-gitlab>
<add key="Username" value="foursat" />
<add key="ClearTextPassword" value="061a5cb15517c6da39c16cfce8556c55ae104d0d" />
</foursat-gitlab>
</packageSourceCredentials>
</configuration>
```
---
## 🎯 خلاصه
**Development** → Debug build → `ProjectReference` → سرعت بالا
**Production** → Release build → `PackageReference` → استقلال
**Auto-Push** → بعد از Pack خودکار به GitLab می‌ره
**Version Bump** → با `bump-version.sh` خودکار
**Rollback** → برگشت به version قبلی ساده
---
**تاریخ**: December 6, 2025
**NuGet Registry**: GitLab (Afrino)
**Current CMS Version**: 0.0.142
@@ -0,0 +1,420 @@
# راهنمای Package کردن Proto Projects برای Production
> تاریخ: December 6, 2025
> وضعیت: Production Deployment Guide
---
## 🎯 مسئله
**Development (Local)**:
- استفاده از `<ProjectReference>` برای توسعه سریع
- تغییرات proto بلافاصله در همه پروژه‌ها اعمال می‌شود
**Production (Server)**:
- استفاده از `<PackageReference>` و NuGet packages
- هر لایه پکیج خودش را منتشر می‌کند
- پروژه‌های بالاتر از NuGet server پکیج‌ها را می‌گیرند
---
## 📦 معماری Packaging
```
┌─────────────────────────────────────────────────────────────┐
│ LAYER 1: CMS Proto │
│ CMSMicroservice.Protobuf → Foursat.CMSMicroservice.Protobuf │
└────────────────────┬────────────────────────────────────────┘
│ (NuGet Package v1.0.x)
┌─────────────────────────────────────────────────────────────┐
│ LAYER 2: BFF Proto (depends on CMS) │
│ BackOffice.BFF.*.Protobuf → Foursat.BackOffice.BFF.*.Protobuf │
│ FrontOffice.BFF.*.Protobuf → Foursat.FrontOffice.BFF.*.Protobuf │
└────────────────────┬────────────────────────────────────────┘
│ (NuGet Package v1.0.x)
┌─────────────────────────────────────────────────────────────┐
│ LAYER 3: UI Apps (depends on BFF) │
│ BackOffice UI → uses Foursat.BackOffice.BFF.*.Protobuf │
│ FrontOffice UI → uses Foursat.FrontOffice.BFF.*.Protobuf │
└─────────────────────────────────────────────────────────────┘
```
---
## 🔧 Setup 1: Private NuGet Server
### گزینه A: BaGet (پیشنهادی - رایگان و ساده)
```bash
# نصب با Docker
docker run -d \
--name foursat-nuget \
--restart unless-stopped \
-p 5555:80 \
-e ApiKey=FOURSAT-SECRET-API-KEY-2025 \
-e Storage__Type=FileSystem \
-e Storage__Path=/var/baget/packages \
-e Database__Type=Sqlite \
-e Database__ConnectionString="Data Source=/var/baget/baget.db" \
-e Search__Type=Database \
-v /opt/foursat-nuget/packages:/var/baget/packages \
-v /opt/foursat-nuget/database:/var/baget \
loicsharma/baget:latest
# سرور روی http://YOUR_SERVER:5555 در دسترس خواهد بود
```
### گزینه B: Azure Artifacts
```bash
# اضافه کردن feed
az artifacts universal publish \
--organization https://dev.azure.com/yourorg \
--feed foursat-packages \
--name CMSMicroservice.Protobuf \
--version 1.0.0 \
--path ./nupkg
```
### گزینه C: GitHub Packages
```bash
# تنظیم authentication
dotnet nuget add source https://nuget.pkg.github.com/YOURORG/index.json \
--name github \
--username YOURNAME \
--password ghp_YOUR_TOKEN \
--store-password-in-clear-text
```
---
## 📝 Setup 2: تنظیمات Proto Projects
### 1. CMS Protobuf (لایه اول - پایه)
**CMSMicroservice.Protobuf.csproj** از قبل آماده است:
```xml
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.0.0</Version>
<PackageId>Foursat.CMSMicroservice.Protobuf</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<!-- اطلاعات پکیج -->
<Authors>FourSat Development Team</Authors>
<Company>FourSat</Company>
<Description>gRPC Protobuf contracts for CMS Microservice</Description>
<PackageTags>grpc;protobuf;foursat;cms</PackageTags>
<RepositoryUrl>https://github.com/foursat/cms</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
```
### 2. BackOffice.BFF Proto Projects (لایه دوم)
مثال برای **BackOffice.BFF.Products.Protobuf**:
```xml
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Version>1.0.0</Version>
<PackageId>Foursat.BackOffice.BFF.Products.Protobuf</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>FourSat Development Team</Authors>
<Company>FourSat</Company>
<Description>gRPC Protobuf contracts for BackOffice BFF - Products Module</Description>
<PackageTags>grpc;protobuf;foursat;backoffice</PackageTags>
</PropertyGroup>
<!-- Development: ProjectReference -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\..\CMS\src\CMSMicroservice.Protobuf\CMSMicroservice.Protobuf.csproj" />
</ItemGroup>
<!-- Production: PackageReference -->
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="1.0.0" />
</ItemGroup>
```
### 3. FrontOffice.BFF Proto Projects (لایه دوم)
مشابه BackOffice.BFF:
```xml
<PropertyGroup>
<PackageId>Foursat.FrontOffice.BFF.Products.Protobuf</PackageId>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\..\CMS\src\CMSMicroservice.Protobuf\CMSMicroservice.Protobuf.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="1.0.0" />
</ItemGroup>
```
---
## 🚀 فرآیند Deployment
### مرحله 1: Package CMS Protobuf
```bash
cd /home/masoud/Apps/project/FourSat/CMS/src/CMSMicroservice.Protobuf
# Build در حالت Release
dotnet build -c Release
# ایجاد NuGet package
dotnet pack -c Release -o ./nupkg
# Push به NuGet server
dotnet nuget push ./nupkg/Foursat.CMSMicroservice.Protobuf.1.0.0.nupkg \
--source http://YOUR_SERVER:5555/v3/index.json \
--api-key FOURSAT-SECRET-API-KEY-2025
```
### مرحله 2: Package BackOffice.BFF Protos
```bash
# تمام Proto projects را pack کن
cd /home/masoud/Apps/project/FourSat/BackOffice.BFF/src/Protobufs
for dir in */; do
if [ -f "$dir/*.csproj" ]; then
cd "$dir"
dotnet pack -c Release -o ../../nupkg
cd ..
fi
done
# Push همه packages
cd ../../nupkg
dotnet nuget push "Foursat.BackOffice.BFF.*.nupkg" \
--source http://YOUR_SERVER:5555/v3/index.json \
--api-key FOURSAT-SECRET-API-KEY-2025
```
### مرحله 3: Package FrontOffice.BFF Protos
```bash
cd /home/masoud/Apps/project/FourSat/FrontOffice.BFF/src/Protobufs
for dir in */; do
cd "$dir"
dotnet pack -c Release -o ../../nupkg
cd ..
done
cd ../../nupkg
dotnet nuget push "Foursat.FrontOffice.BFF.*.nupkg" \
--source http://YOUR_SERVER:5555/v3/index.json \
--api-key FOURSAT-SECRET-API-KEY-2025
```
### مرحله 4: تنظیم UI Projects برای Production
**BackOffice.csproj**:
```xml
<!-- Development -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\BackOffice.BFF\src\Protobufs\BackOffice.BFF.Products.Protobuf\BackOffice.BFF.Products.Protobuf.csproj" />
<ProjectReference Include="..\..\BackOffice.BFF\src\Protobufs\BackOffice.BFF.User.Protobuf\BackOffice.BFF.User.Protobuf.csproj" />
<!-- ... سایر proto references -->
</ItemGroup>
<!-- Production -->
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.BackOffice.BFF.Products.Protobuf" Version="1.0.0" />
<PackageReference Include="Foursat.BackOffice.BFF.User.Protobuf" Version="1.0.0" />
<!-- ... سایر package references -->
</ItemGroup>
```
**FrontOffice.csproj**: مشابه
---
## 🔄 Versioning Strategy
### Semantic Versioning
```
MAJOR.MINOR.PATCH
1.0.0 → Initial release
1.0.1 → Bug fix (backward compatible)
1.1.0 → New feature (backward compatible)
2.0.0 → Breaking change
```
### مثال:
```xml
<!-- CMS Proto v1.0.0 -->
<Version>1.0.0</Version>
<!-- بعد از اضافه کردن فیلد جدید (backward compatible) -->
<Version>1.1.0</Version>
<!-- بعد از تغییر RPC signature (breaking) -->
<Version>2.0.0</Version>
```
---
## 🛠️ Scripts خودکار
### pack-all-protos.sh
```bash
#!/bin/bash
# رنگ‌ها برای output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
NUGET_SERVER="http://YOUR_SERVER:5555/v3/index.json"
API_KEY="FOURSAT-SECRET-API-KEY-2025"
echo -e "${BLUE}🚀 Starting Proto Packaging Process...${NC}\n"
# 1. CMS Protobuf
echo -e "${GREEN}📦 Step 1: Packaging CMS Protobuf${NC}"
cd /home/masoud/Apps/project/FourSat/CMS/src/CMSMicroservice.Protobuf
dotnet pack -c Release -o ./nupkg
dotnet nuget push ./nupkg/*.nupkg --source $NUGET_SERVER --api-key $API_KEY --skip-duplicate
# 2. BackOffice.BFF Protos
echo -e "${GREEN}📦 Step 2: Packaging BackOffice.BFF Protos${NC}"
cd /home/masoud/Apps/project/FourSat/BackOffice.BFF/src/Protobufs
for dir in BackOffice.BFF.*.Protobuf/; do
if [ -d "$dir" ]; then
echo " → Packaging $dir"
cd "$dir"
dotnet pack -c Release -o ../../../nupkg
cd ..
fi
done
cd ../../nupkg
dotnet nuget push Foursat.BackOffice.BFF.*.nupkg --source $NUGET_SERVER --api-key $API_KEY --skip-duplicate
# 3. FrontOffice.BFF Protos
echo -e "${GREEN}📦 Step 3: Packaging FrontOffice.BFF Protos${NC}"
cd /home/masoud/Apps/project/FourSat/FrontOffice.BFF/src/Protobufs
for dir in FrontOffice.BFF.*.Protobuf/; do
if [ -d "$dir" ]; then
echo " → Packaging $dir"
cd "$dir"
dotnet pack -c Release -o ../../../nupkg
cd ..
fi
done
cd ../../nupkg
dotnet nuget push Foursat.FrontOffice.BFF.*.nupkg --source $NUGET_SERVER --api-key $API_KEY --skip-duplicate
echo -e "\n${GREEN}✅ All packages published successfully!${NC}"
```
اجرا:
```bash
chmod +x pack-all-protos.sh
./pack-all-protos.sh
```
---
## 📋 NuGet.Config برای Development
**nuget.config** در root:
```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Official NuGet -->
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<!-- FourSat Private NuGet Server -->
<add key="foursat" value="http://YOUR_SERVER:5555/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<foursat>
<add key="Username" value="foursat" />
<add key="ClearTextPassword" value="FOURSAT-SECRET-API-KEY-2025" />
</foursat>
</packageSourceCredentials>
</configuration>
```
---
## 🔍 بررسی Packages
```bash
# لیست packages روی server
curl http://YOUR_SERVER:5555/v3/search?q=foursat
# دانلود package
dotnet add package Foursat.CMSMicroservice.Protobuf --version 1.0.0
# بررسی dependency tree
dotnet list package --include-transitive
```
---
## 📊 خلاصه Packages
| Package | Layer | Depends On | Version |
|---------|-------|------------|---------|
| Foursat.CMSMicroservice.Protobuf | 1 | - | 1.0.x |
| Foursat.BackOffice.BFF.Products.Protobuf | 2 | CMS Proto | 1.0.x |
| Foursat.BackOffice.BFF.User.Protobuf | 2 | CMS Proto | 1.0.x |
| Foursat.BackOffice.BFF.*.Protobuf (14 pkg) | 2 | CMS Proto | 1.0.x |
| Foursat.FrontOffice.BFF.Products.Protobuf | 2 | CMS Proto | 1.0.x |
| Foursat.FrontOffice.BFF.*.Protobuf (8 pkg) | 2 | CMS Proto | 1.0.x |
**جمع**: ~23 NuGet packages
---
## 🎯 مزایا
**Development**: سریع (ProjectReference)
**Production**: مستقل (PackageReference)
**Versioning**: کنترل دقیق تغییرات
**CI/CD**: خودکارسازی آسان
**Rollback**: برگشت به نسخه قبلی ساده
**Team Work**: همکاری بهتر روی Proto ها
---
## 🚨 نکات مهم
1. **همیشه از Semantic Versioning استفاده کنید**
2. **Breaking changes** = Major version bump (2.0.0)
3. **Proto changes باید documented باشند**
4. **هر push به production نیاز به package جدید دارد**
5. **Development با Debug build** = ProjectReference
6. **Production با Release build** = PackageReference
---
## 📞 Support
سوال یا مشکل؟
- داکیومنت: `/home/masoud/Apps/project/FourSat/PROTO-PACKAGING-GUIDE.md`
- BaGet UI: http://YOUR_SERVER:5555
- Team: FourSat Development Team
@@ -0,0 +1,249 @@
# Proto Package Management - Quick Start
این فایل یک راهنمای سریع برای مدیریت Proto Packages در پروژه FourSat است.
---
## 📦 فایل‌های مهم
| فایل | توضیحات |
|------|---------|
| `PROTO-PACKAGING-GUIDE.md` | راهنمای کامل و جامع (همه جزئیات) |
| `pack-protos.sh` | Script خودکار برای Package کردن همه Proto ها |
| `docker-compose.baget.yml` | راه‌اندازی Private NuGet Server |
| `EXAMPLE-PROTO-CSPROJ.xml` | مثال csproj با تنظیمات Debug/Release |
---
## 🚀 شروع سریع
### 1. راه‌اندازی NuGet Server (اختیاری برای Local Development)
```bash
# شروع BaGet با Docker
docker-compose -f docker-compose.baget.yml up -d
# بررسی وضعیت
docker ps | grep baget
# دسترسی به UI
# مرورگر: http://localhost:5555
```
### 2. Package کردن همه Proto ها
```bash
# فقط ساخت packages (بدون push)
./pack-protos.sh
# ساخت و push به NuGet server
./pack-protos.sh --push
# استفاده از custom server
NUGET_SERVER=https://nuget.foursat.com ./pack-protos.sh --push
```
### 3. اضافه کردن NuGet Source
```bash
# اضافه کردن local BaGet
dotnet nuget add source http://localhost:5555/v3/index.json \
--name foursat-local \
--username foursat \
--password FOURSAT-SECRET-API-KEY-2025 \
--store-password-in-clear-text
# بررسی sources
dotnet nuget list source
```
---
## 🔄 Workflow توسعه
### Development (Local):
```bash
# Build با Debug config → استفاده از ProjectReference
cd BackOffice/src
dotnet build -c Debug
# همه تغییرات Proto بلافاصله اعمال می‌شود
```
### Production (Deploy):
```bash
# 1. Package کردن CMS Proto
cd CMS/src/CMSMicroservice.Protobuf
dotnet pack -c Release -o ./nupkg
# 2. Push به NuGet Server
dotnet nuget push ./nupkg/*.nupkg \
--source http://localhost:5555/v3/index.json \
--api-key FOURSAT-SECRET-API-KEY-2025
# 3. Package کردن BFF Protos (وابسته به CMS)
cd BackOffice.BFF/src/Protobufs
# ... (مشابه)
# 4. Build UI با Release config → استفاده از PackageReference
cd BackOffice/src
dotnet build -c Release
```
---
## 📊 ساختار Packages
```
Foursat.CMSMicroservice.Protobuf (v1.0.0)
└─ Base Proto Layer
└─ استفاده شده در:
├─ Foursat.BackOffice.BFF.Products.Protobuf
├─ Foursat.BackOffice.BFF.User.Protobuf
├─ Foursat.BackOffice.BFF.*.Protobuf (12 package دیگر)
├─ Foursat.FrontOffice.BFF.Products.Protobuf
└─ Foursat.FrontOffice.BFF.*.Protobuf (7 package دیگر)
```
**تعداد کل Packages**: ~23 package
---
## 🔍 دستورات مفید
```bash
# جستجو در local NuGet server
dotnet nuget search Foursat --source foursat-local
# نصب یک package
dotnet add package Foursat.CMSMicroservice.Protobuf \
--version 1.0.0 \
--source foursat-local
# بررسی dependencies
dotnet list package --include-transitive
# حذف package cache
dotnet nuget locals all --clear
# بررسی محتویات package
unzip -l package.nupkg
```
---
## ⚙️ تنظیمات csproj
### Development (Debug):
```xml
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\CMS\src\CMSMicroservice.Protobuf\CMSMicroservice.Protobuf.csproj" />
</ItemGroup>
```
### Production (Release):
```xml
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="1.0.0" />
</ItemGroup>
```
**مثال کامل**: `EXAMPLE-PROTO-CSPROJ.xml`
---
## 📝 Versioning
### Semantic Versioning (SemVer):
```
MAJOR.MINOR.PATCH
1.0.0 → Initial release
1.0.1 → Bug fix
1.1.0 → New feature (backward compatible)
2.0.0 → Breaking change
```
### مثال تغییر نسخه:
```xml
<!-- قبل: -->
<Version>1.0.0</Version>
<!-- بعد از اضافه کردن فیلد جدید (compatible): -->
<Version>1.1.0</Version>
<!-- بعد از تغییر RPC signature (breaking): -->
<Version>2.0.0</Version>
```
---
## 🎯 نکات مهم
1.**Local Development**: همیشه با `Debug` build کار کنید
2.**Production Build**: همیشه با `Release` build
3.**Version Bump**: هر تغییر در Proto → نسخه جدید
4.**Push Order**: اول CMS، بعد BFF ها، آخر UI ها
5.**Testing**: قبل از push حتماً test کنید
---
## 🆘 عیب‌یابی
### مشکل: Package پیدا نمی‌شود
```bash
# بررسی source ها
dotnet nuget list source
# اضافه کردن source
dotnet nuget add source http://localhost:5555/v3/index.json --name foursat-local
# پاک کردن cache
dotnet nuget locals all --clear
```
### مشکل: Version conflict
```bash
# حذف obj و bin
find . -name "obj" -o -name "bin" | xargs rm -rf
# Restore دوباره
dotnet restore
# Build
dotnet build -c Release
```
### مشکل: BaGet server در دسترس نیست
```bash
# بررسی container
docker ps | grep baget
# restart container
docker-compose -f docker-compose.baget.yml restart
# لاگ‌ها
docker logs foursat-nuget-server
```
---
## 📚 منابع بیشتر
- **راهنمای کامل**: `PROTO-PACKAGING-GUIDE.md`
- **BaGet Documentation**: https://loic-sharma.github.io/BaGet/
- **NuGet CLI Reference**: https://docs.microsoft.com/en-us/nuget/reference/nuget-exe-cli-reference
- **Semantic Versioning**: https://semver.org/
---
**تاریخ**: December 6, 2025
**نسخه**: 1.0.0
**پروژه**: FourSat
@@ -0,0 +1,70 @@
# ⚠️ یادآوری مهم - Proto Package Management
## قانون طلایی (برای ALL سرویس‌ها)
**هر تغییر در Proto = این 3 مرحله اجباری:**
```bash
# 1️⃣ افزایش Version
<Version>X.Y.Z</Version> → <Version>X.Y.Z+1</Version>
# 2️⃣ Pack کردن
dotnet pack -c Release
# ✅ خودکار push می‌شه به GitLab
# 3️⃣ Update در لایه بالاتر
<PackageReference Include="PackageName" Version="NEW_VERSION" />
```
---
## مثال عملی
### تغییر در CMS Proto:
```bash
cd CMS/src/CMSMicroservice.Protobuf
# ویرایش products.proto
# افزایش <Version>0.0.142</Version> → 0.0.143
dotnet pack -c Release
```
### Update در BackOffice.BFF:
```xml
<!-- BackOffice.BFF.Products.Protobuf.csproj -->
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.143" />
```
### Pack کردن BFF:
```bash
cd BackOffice.BFF/src/Protobufs/BackOffice.BFF.Products.Protobuf
# افزایش <Version>1.0.0</Version> → 1.0.1
dotnet pack -c Release
```
### Update در BackOffice UI:
```xml
<!-- BackOffice.csproj -->
<PackageReference Include="Foursat.BackOffice.BFF.Products.Protobuf" Version="1.0.1" />
```
---
## این قانون برای همه است:
- ✅ CMS → BackOffice.BFF
- ✅ CMS → FrontOffice.BFF
- ✅ BackOffice.BFF → BackOffice UI
- ✅ FrontOffice.BFF → FrontOffice UI
---
## ⚠️ فراموش کردن = Bug
- Runtime errors بی‌دلیل
- "Method not found"
- "Type mismatch"
- ساعت‌ها Debug بیهوده
---
**GitLab Registry**: `https://git.afrino.co/api/packages/FourSat/nuget/index.json`
File diff suppressed because it is too large Load Diff