تخطَّ إلى المحتوى
AggregaAggregaAggregaAggrega
اختر لغة: العربية
تُرجمت هذه الصفحة آليًا. اقرأ الأصل الإنجليزي.

استيراد قالب Azure Resource Manager

يستورد هذا الشرح العملي قالب Azure Resource Manager صغيرًا — مساحة أسماء Event Hubs المُنشَرة عبر وحدة Azure Verified Modules، وموقع App Service يشغّل حاوية، وتطبيق ويب ساكنًا، والشبكة الافتراضية التي يُراد للموقع الانضمام إليها — ويبني النتيجة بوصفها قالب Azure Resource Manager واحدًا. يصوغ الاستيراد Aggregate و Release و Manifest: يصبح كلٌّ من مساحة الأسماء والموقع مرجعًا إلى أحد Components المكتبة القياسية، ويُصاغ تطبيق الويب الساكن، الذي لا يمثله أي Component، من القالب، وتُحمَل القيم التي يذكرها القالب بصيغة يمكن أن يأخذها Release. وتُترك لك بضع قيم لا يذكرها القالب بهذه الصيغة، وتبيّن الصفحة أيّها وأين. كل ملف وكل كتلة إخراج أدناه من تشغيل فعلي؛ والقالب ومراحل الشرح العملي كلها في المثال import-arm، حيث يعيد نص فحص برمجي تشغيل الاستيراد، ويقارن ما يكتبه وما يطبعه والكتل التي تقتبسها هذه الصفحة بالملفات المحفوظة هناك، ويؤكد أن المسودة تتوقف حيث تقول هذه الصفحة، ويبني Release المراجَع.

صُغ مسودة المثال

يمكنك تشغيل هذا الاستيراد بالأوامر الواردة في هذه الصفحة، أو اجعل مساعد الذكاء الاصطناعي يشغّله نيابةً عنك.

اكتب المثال في مجلد جديد يحمل اسمه:

Terminal window
aggrega draft --example import-arm

ثم يطبع الأوامر التي تُشغَّل بعد ذلك. يدخل الأول إلى المجلد الجديد؛ ويدخل الذي يليه، أدناه، إلى مجلد source الخاص به، الذي يحوي ما تستورده هذه الصفحة وهو المكان الذي يجري فيه الاستيراد:

Terminal window
cd import-arm

القالب

main.json هو الصيغة المُحوَّلة برمجيًا للقالب: ملف JSON الذي يكتبه بناء Bicep ويقوم Azure Resource Manager بنشره. مُعامِله هو المنطقة، ويبدأ بشبكة افتراضية تحمل الشبكة الفرعية التي ينضم إليها الموقع:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "westeurope"
}
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2023-11-01",
"name": "vnet-notes",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.20.0.0/16"
]
},
"subnets": [
{
"name": "snet-app",
"properties": {
"addressPrefix": "10.20.1.0/24",
"delegations": [
{
"name": "web",
"properties": {
"serviceName": "Microsoft.Web/serverFarms"
}
}
]
}
}
]
}
},
[… omitted: the rest of the template]

تُنشَر مساحة الأسماء عبر وحدة Azure Verified Modules المسماة avm/res/event-hub/namespace بالإصدار 0.15.3: مورد Microsoft.Resources/deployments يحمل عضو template فيه القالب المُحوَّل برمجيًا للوحدة نفسها، وهو أكثر من 3,700 سطر، وتمثل parameters فيه ما يضبطه القالب للوحدة:

{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "ehModule",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"name": {
"value": "evh-notes"
},
"location": {
"value": "[parameters('location')]"
},
"skuName": {
"value": "Standard"
},
"skuCapacity": {
"value": 2
},
"publicNetworkAccess": {
"value": "Enabled"
},
"enableTelemetry": {
"value": true
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
[… omitted: the module's compiled template, and the rest of the resource]

القالب المُحوَّل برمجيًا للوحدة هو القالب الذي يقدمه Microsoft Container Registry لذلك الإصدار، وهو مرخَّص بترخيص MIT، ويحمل README المثال الإشعار. يقرأ الاستيراد القالب ليتعرّف على الوحدة: فبادئة القياس عن بُعد في القالب وإصداره تسميان وحدة Azure Verified Modules ونوع المورد الذي تنشره.

الموقع مورد عادي. يعمل على خطة App Service موجودة أصلًا، وينضم إلى الشبكة الفرعية للقالب، ويشغّل الحاوية المسماة في linuxFxVersion، ويقرأ إخراج name الخاص بالوحدة، ويضبط متغيّرًا آخر:

{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-12-01",
"name": "notes-api",
"location": "[parameters('location')]",
"kind": "app,linux,container",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'ehModule')]",
"[resourceId('Microsoft.Network/virtualNetworks', 'vnet-notes')]"
],
"properties": {
"serverFarmId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes",
"virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app')]",
"siteConfig": {
"linuxFxVersion": "DOCKER|ghcr.io/example/notes-api:2.3.0",
"appSettings": [
{
"name": "EVENTHUB_NAMESPACE",
"value": "[reference('ehModule').outputs.name.value]"
},
{
"name": "EVENTHUB_NAME",
"value": "notes"
}
]
}
}
},

تطبيق الويب الثابت مورد عادي أيضًا. وبجوار القالب يقدّم ملف المُعامِلات المُعامِل الوحيد:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": { "value": "northeurope" }
}
}

يقع الملفان في المجلد notes، ويجعل .aggrega-config.yaml الموجود بجانب ذلك المجلد الدليل مساحة عمل، فيكتب الاستيراد مسوداته هناك:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside the notes folder.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

يقرأ الاستيراد القالب وملف مُعامِلاته بوصفهما JSON مع تعليقات، فيتعرف على القالب من $schema و resources فيه، وعلى ملف المُعامِلات من $schema و parameters فيه. ويوازن كل مورد مع Components كتالوج مساحة العمل، الذي يقرأه كما يصف كيف يعمل الاستيراد، ولا يقرأ أي حساب سحابي: فالقيمة التي يحتسبها القالب أثناء نشره تُحمَل بوصفها التعبير الذي يحتسبها، ولا يُستعلم عنها أبدًا.

انتقل إلى source:

Terminal window
cd source

شغّل الاستيراد

سمِّ المجلد الذي يحتوي القالب. يتعرف المستورِد على القالب وملف مُعامِلاته من محتوياتهما:

Terminal window
aggrega import notes

لم يُسمَّ --target. يعلن المستورِد arm هدفه الافتراضي، لأن Recipes المكتبة القياسية التي تخص منصة Azure Resource Manager ترتبط به، ويصوغ الاستيراد Manifest له؛ أما الاستيراد الذي يسمي هدفًا بواسطة --target فيصوغ لذلك الهدف بدلًا منه. ويحتفظ السجل الذي يكتبه الاستيراد بجانب مسوداته بالهدف، ويعيد --sync استخدامه.

يسرد على الإخراج القياسي ما كتبه:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote catalog/component/imported/compute/microsoft-web-staticsites/0.1.0/component.yaml
wrote catalog/recipe/arm/microsoft-web-staticsites/0.1.0/recipe.yaml
wrote .aggrega-import.json

على الخطأ القياسي، حيث يمثّل <workspace> المجلد الذي شغّلته فيه:

[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]
read as the arm format, with drafted paths relative to <workspace>
info: the drafts are for the target "arm", the importer's declared default; an import naming a target drafts for that one
info: ehmodule deploys the Azure Verified Modules resource module avm/res/event-hub/namespace, of telemetry prefix 46d3xbcp.res.962075c, version 0.15.3, named "Event Hub Namespaces" in its metadata: it is one node of the resource type Microsoft.EventHub/namespaces, the parameters it sets read as the module's, and the module's telemetry is not carried, as whether a Recipe sends telemetry is the Recipe's to set
warn: notes-api sets the variable EVENTHUB_NAMESPACE at properties.siteConfig.appSettings.0.value from ehmodule's outputs.name.value, and the drafted Aggregate does not wire it: ehmodule publishes no provides key for it; the instance notes-api is connected to ehmodule for the dependency alone, a comment above the connection saying why; write the value where the instance is configured
info: the resource notes-site of the type Microsoft.Web/staticSites@2023-01-01 is drafted from the source as the Component imported/compute/microsoft-web-staticsites and the Recipe microsoft-web-staticsites on arm, carrying the properties the source writes; the decision's swap hint names the import drafting it from the vendor's schema
warn: the source creates substrate the draft leaves to the operator and drafts nothing for: vnet-notes (Microsoft.Network/virtualNetworks), of which the format says the network a component runs in is the operator's: a component of the catalog takes it by its resource ID under infra.overrides, reading the parameter location at location; provide each where the Release deploys, and fill the pointers the Release leaves for them
warn: notes-api sets the variable EVENTHUB_NAME in the environment of the instance notes-api, and the draft delivers an instance's environment from its connections alone, so the variable is not carried: the instance's Release entry names it, for the author to set where the instance is configured
mapped ehmodule (Microsoft.EventHub/namespaces) to core/messaging/azure-event-hubs as a reference, HIGH at 0.8656
mapped notes-site (Microsoft.Web/staticSites) to imported/compute/microsoft-web-staticsites as a draft, NONE at 0.05
made no choice for vnet-notes (Microsoft.Network/virtualNetworks)
mapped notes-api (Microsoft.Web/sites) to core/compute/server as a reference, HIGH at 0.9
made no choice for resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app') ()
[… omitted: what the pull could not render yet, a stop of the App Service Recipe's assertion that the Release names the subnet, which the sections below explain]
external inputs: dependency pins were written and are complete; 0 external input(s) pinned, and any this Release also needs are still unpinned
external inputs: a build of this Release halts naming the unpinned URL; fixing what stopped the render and resolving again pins it
Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)
External inputs were not fully discovered: dependency pins are complete, external-input pins may not be (see the diagnostics above)
  • السطور info تذكر ما قرره المستورِد دون سؤال. يقول الأول إن المسودات مخصصة للهدف arm. ويتعرف الثاني على الوحدة: المورد ehmodule هو وحدة Azure Verified Modules الخاصة بمساحة أسماء Event Hubs، وتُقرأ المُعامِلات التي يضبطها القالب لها بوصفها مُعامِلات الوحدة نفسها، فتتعامل معها المسودة بوصفها مساحة أسماء واحدة لا قالبًا متداخلًا ليُقرأ. ويقول الثالث إن تطبيق الويب الساكن يُصاغ من القالب.
  • السطور warn تسمي ما لا تحمله المسودة. الأول هو المتغيّر الذي يقرؤه الموقع من إخراج name الخاص بالوحدة: فالمسودة لا توصّل اتصالًا إلا لما يطرحه Component، ولا تطرح مساحة الأسماء أي مفتاح لاسمها، فيوجد الاتصال للتبعية وحدها. ويسمي الثاني الشبكة الافتراضية التي ينشئها القالب، وتتركها المسودة لك، كما يوضح ما تتركه المسودة لك. ويسمي الثالث المتغيّر الذي يضبطه الموقع ولا يسلّمه أي اتصال في المسودة.
  • السطور mapped تقول إلى ماذا تحول كل مورد. ehmodule مثيل من core/messaging/azure-event-hubs في المكتبة القياسية، أما notes-api فمثيل للخادم العام، core/compute/server، وكلٌّ منهما مطابق في المستوى العالي ومُشار إليه بوصفه مرجعًا. notes-site لا يطابق أي Component، فهو مسودة بلا مطابقة. وتسمي السطور made no choice ما لا تقرر له المسودة شيئًا: الشبكة الافتراضية، ومؤشر الشبكة الفرعية الذي يتركه Release فارغًا.
  • خطوة pull هي جلب الاستيراد لما يعتمد عليه Release المُصاغ، كما يفعل aggrega pull، إلى release.lock. فما يسميه Manifest من Recipes لمساحة الأسماء والموقع يكتب مواردهما بنفسه ولا تجلب أي مصدر، ولذلك تكون قيمة source_artifacts هي 0 ولا تصل خطوة pull إلى خارج الكتالوج لجلب أي شيء. ثم يحاول الاستيراد تصيير Release لإيجاد المُدخَلات التي سيجلبها البناء، فيوقفه Recipe App Service: فالمسودة لا تسمي أي شبكة فرعية بعد. وينتهي الاستيراد مع ذلك، وقد كُتب ملف القفل، ويقول إن المُدخَلات الخارجية لم تُكتشف بالكامل؛ والتوقف هو نفسه الذي يبلغ عنه التحقق تاليًا.

ما يكتبه

يحمل Aggregate و Release و Manifest الاسم imported/notes، نسبة إلى المجلد الذي قرأه الاستيراد — ويحمل القالب المستورَد بوصفه ملفًا اسم الملف، main — ضمن مساحة الأسماء التي يحددها إعداد target_namespace في المستورِد، وهي imported ما لم تضبط غيرها (الإعدادات).

aggregate.yaml — إدخال واحد لكل مورد، والاتصال الذي يرسمه الموقع:

# Sources read: main.json, main.parameters.json.
# Substrate the source creates, left to the operator: vnet-notes (Microsoft.Network/virtualNetworks).
apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/notes
version: 0.1.0
description: Draft Aggregate imported from a source in the arm format.
spec:
components:
ehmodule:
type: core/messaging/azure-event-hubs
notes-site:
type: imported/compute/microsoft-web-staticsites
values:
name: "notes-site"
notes-api:
type: core/compute/server
uses:
# Not wired: notes-api sets the variable EVENTHUB_NAMESPACE at properties.siteConfig.appSettings.0.value from ehmodule's outputs.name.value; ehmodule publishes no provides key for it.
ehmodule:
ehmodule:
target: ehmodule

تطبيق الويب الثابت مكوِّن من نوع صاغه الاستيراد مسودةً، imported/compute/microsoft-web-staticsites. ولا يحمل اتصال الموقع بمساحة الأسماء كتلة inject، لأن المسودة لا تسلّم متغيّرًا من اتصال إلا عندما يطرح Component القيمة، ويذكر التعليق فوقه أي متغيّر لا توصّله ولماذا.

release.yaml — البيئة، وإعدادات كل مورد:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/notes
# environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to.
environment: development
version: 0.1.0
description: Draft Release imported from a source in the arm format.
spec:
aggregate: imported/notes
manifest: imported/notes
components:
# Module parameters the source sets and the draft does not translate: location, name, publicNetworkAccess, skuCapacity, skuName.
ehmodule: {}
notes-site:
infra:
# From the template parameter location, the value the parameters file supplies.
location: "northeurope"
overrides:
appLocation: "/"
outputLocation: "dist"
name: "Free"
tier: "Free"
# Properties the source writes and the draft does not place: kind, properties.siteConfig.linuxFxVersion.
# Environment variables the source sets and no connection delivers: EVENTHUB_NAME = notes.
notes-api:
infra:
overrides:
service_plan_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes"
# From the template parameter location, the value the parameters file supplies.
location: "northeurope"
# Left for the Release, since the source cannot supply it: infra.overrides.virtual_network_subnet_id, the pointer to the resource "resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app')", which the draft leaves to the operator and the source names as "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app')]"; the catalog Recipe takes the resource's literal identifier: write it
virtual_network_subnet_id: ""

البيئة، development، قيمة افتراضية يكتبها الاستيراد لأن القالب لا يسمي أيًّا منها. ويصل مُعامِل location في القالب إلى إدخالَي تطبيق الويب الثابت والموقع بوصفه القيمة التي يقدمها ملف المُعامِلات، northeurope. ويُحمَل service_plan_id الخاص بالموقع بوصفه المعرّف الحرفي الذي يكتبه القالب. وإدخال مساحة الأسماء فارغ، ويسرد التعليق فوقه مُعامِلات الوحدة التي لا تترجمها المسودة.

مفتاح واحد فارغ، ويذكر تعليقه السبب: virtual_network_subnet_id مؤشر إلى مورد، وتأخذه Recipes المكتبة القياسية الخاصة بمنصة Azure Resource Manager بوصفه المعرّف الحرفي /subscriptions/… للمورد. يكتب القالب الشبكة الفرعية للموقع بوصفها تعبير resourceId يسمي موردًا في القالب نفسه، والتعبير ليس معرّفًا يستطيع Recipe أخذه، فتترك المسودة المفتاح فارغًا وتسمي التعبير في تعليق. وفي المقابل يحتفظ المورد المصوغ بكل تعبير في القالب كاملًا.

صورة الحاوية ليست في الإدخال. يكتبها القالب داخل linuxFxVersion، وهي خاصية لا تضعها المسودة في أي موضع، ويسرد التعليق فوق الإدخال kind و linuxFxVersion بين الخصائص التي لا تضعها.

manifest.yaml — Recipe الذي يُحقَّق به كل مكوِّن على arm:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/notes
version: 0.1.0
spec:
mappings:
components:
type: {}
name:
ehmodule: arm/azure-event-hubs
notes-site: arm/microsoft-web-staticsites
notes-api: arm/server-app-service

لا يوجد في المكتبة القياسية Component لتطبيق الويب الساكن، فيصوغ الاستيراد واحدًا مع Recipe تحت مجلد catalog في مساحة العمل: يعلن Component imported/compute/microsoft-web-staticsites القيمة name التي يعطيها القالب للموقع، و location، وكائن overrides لكل خاصية يكتبها القالب بأسماء المورِّد نفسه، ويكتب Recipe microsoft-web-staticsites موردًا واحدًا من النوع Microsoft.Web/staticSites وبإصدار API ذلك النوع. المسودات ملفات عادية لتقرأها وتعدلها:

apiVersion: aggrega.ai/v1beta1
kind: Component
metadata:
name: imported/compute/microsoft-web-staticsites
version: 0.1.0
description: "Draft Component of the resource type Microsoft.Web/staticSites@2023-01-01, imported from a source in the arm format."
labels:
component.aggrega.ai/type: resource
component.aggrega.ai/category: compute
component.aggrega.ai/hosting: managed
spec:
schema:
values:
type: object
properties:
# identity: the resource's own name or identifier
# The source writing the resource gives no description of name.
name:
type: string
required: true
additionalProperties: false
infra:
type: object
properties:
# placement: where the resource is deployed
# The source writing the resource gives no description of location.
location:
type: string
required: true
# override: every writable property no other rule places, each under the vendor's own name
overrides:
type: object
description: "Writable settings of Microsoft.Web/staticSites@2023-01-01, each under the vendor's own name, which the Recipe passes to the resource as written; its header lists the names it reads."
additionalProperties: true
additionalProperties: false
[… omitted: the values the Component publishes, id and name]

يسجل release.lock كيانات الكتالوج التي انتهى حل Release إليها، بحسب الملخّص؛ أما .aggrega-import.json فهو سجل ما كتبه الاستيراد، الذي يقرؤه aggrega import --sync لاحقًا.

التحقق

Terminal window
aggrega validate --release release.yaml

يتوقف التحقق. فالمسودة لا تسمي شبكة فرعية للموقع، ولا يضم Recipe App Service موقعًا إلى شبكة فرعية من شبكتك أنت إلا بمعرّفها:

[CATALOG_ERROR E0033]
Recipe/FeatureRecipe assertions
[… omitted: the line beginning "caused by: Recipe "server-app-service" instance "notes-api" assertion "placement_supplied"", which ends with the Recipe's message: … infra.overrides.virtual_network_subnet_id is "", and this Recipe takes the subnet the app joins by virtual network integration as the subnet's resource ID: set it to /subscriptions/<subscription>/resourceGroups/<group>/providers/Microsoft.Network/virtualNetworks/<network>/subnets/<subnet>, a subnet delegated to Microsoft.Web/serverFarms, or remove it]
release dependency validation failed: 1 diagnostic(s)

يسمي الرفض ما يجب تغييره وأين، في المستند الذي تغيّره. وهو هنا إدخال notes-api في release.yaml، وبعد الشبكة الفرعية يسمي البناء قيمة ثانية: صورة الحاوية. يكتبها القالب في linuxFxVersion التي لا تضعها المسودة، ولا يحمل Recipe الخادم العام الخاص بمنصة App Service أي صورة خاصة به، فيتوقف البناء برسالة تقول إن Release لا يضبط infra.image. والصورة عليك أن تقدمها في Release.

يسرد تعليق مساحة الأسماء skuName و skuCapacity و location، وهي قيم تأخذها الوحدة من القالب ولا تضعها المسودة أيضًا. وبدونها تسري القيم الافتراضية التي يحملها Recipe نفسه؛ وتحمل infra.overrides.sku_name و infra.overrides.sku_capacity و infra.overrides.location قيم القالب. ويحتوي مجلد reviewed في المثال على ملف release.yaml وفيه جميعها مكتوبة:

# Module parameters the source sets and the draft does not translate: location, name, publicNetworkAccess, skuCapacity, skuName.
ehmodule:
infra:
overrides:
# Where the template sets skuName and skuCapacity, which the draft places nowhere: the namespace's tier and its throughput units.
sku_name: "Standard"
sku_capacity: 2
# Where the template sets location, which the draft places nowhere on a module: the namespace's region.
location: "northeurope"

وإدخال الموقع، مع الصورة والشبكة الفرعية:

# Properties the source writes and the draft does not place: kind, properties.siteConfig.linuxFxVersion.
# Environment variables the source sets and no connection delivers: EVENTHUB_NAME = notes.
notes-api:
infra:
# The template writes the container image in properties.siteConfig.linuxFxVersion, which the draft places nowhere: the image the site runs.
image: "ghcr.io/example/notes-api:2.3.0"
overrides:
service_plan_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes"
# From the template parameter location, the value the parameters file supplies.
location: "northeurope"
# The subnet the template's virtual network holds, as the literal ID the Recipe takes, in the resource group the network is deployed to.
virtual_network_subnet_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-network/providers/Microsoft.Network/virtualNetworks/vnet-notes/subnets/snet-app"

يبني النص البرمجي لفحص المثال هذا Release، ويؤكد أن المسودة تتوقف بالرسالة الواردة أعلاه.

البناء

انتقل إلى مجلد يحتوي Release المراجَع، أو عدّل release.yaml في source بالطريقة نفسها، ثم ابنِ:

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml --auto-pull

لم يعد Release يطابق release.lock الذي كتبه الاستيراد، لذلك يحتاج البناء إلى --auto-pull الذي يحلّه من جديد؛ ودونه يتوقف البناء ويسمي aggrega pull. ويطبع التحقق:

release dependency validation passed: release.yaml (schema-pillar + dependency pillars)

ويطبع البناء، حيث يمثّل <workspace> المجلد الذي شغّلته فيه:

[… omitted: the pull's line reporting the lockfile it wrote]
[… omitted: a total build time, which differs per run]
Build completed: 1 file written to <workspace>/dist

قراءة arm-template.json

يكتب البناء ملفًا واحدًا هو dist/arm/arm-template.json: القالب المُجمَّع، بإصدار اللغة 2.0، مع إدخال واحد تحت resources لكل مورد يكتبه مكوِّن، يُسمّى بمعرّف مثيل المكوِّن مطويًا إلى كلمات:

Ehmodule the Event Hubs namespace, in a nested template
NotesApi the App Service site
NotesApiFtpPublishing the site's FTP publishing policy, which the Recipe turns off
NotesApiScmPublishing the site's SCM publishing policy, which the Recipe turns off
NotesSite the static web app, the resource the draft Recipe writes

يحتوي إدخال مساحة الأسماء على مساحة الأسماء التي يكتبها Recipe، مع الإعدادات التي يحملها Release — الفئة ووحدات الإنتاجية والمنطقة — وإعدادات Recipe نفسه لما تبقى:

"Ehmodule": {
"apiVersion": "2025-04-01",
"metadata": {
"aggrega.ai/provenance": {
"aggrega.ai/aggregate-name": "imported/notes",
"aggrega.ai/boundary-path": "default",
[… omitted: a compiler-version entry, which moves with the build]
"aggrega.ai/component-id": "ehmodule",
"aggrega.ai/environment": "development",
"aggrega.ai/provider": "arm",
[… omitted: a provider-version entry, which moves with the build]
"aggrega.ai/recipe-uri": "azure-event-hubs:1.0.0"
}
},
"name": "[format('Ehmodule-{0}', uniqueString(deployment().name))]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {
"serviceBusEndpoint": {
"type": "string",
"value": "[reference(resourceId('Microsoft.EventHub/namespaces', 'ehmodule'), '2026-01-01').serviceBusEndpoint]"
}
},
"resources": [
{
"apiVersion": "2026-01-01",
"location": "northeurope",
"name": "ehmodule",
"properties": {
"disableLocalAuth": true,
"isAutoInflateEnabled": false,
"minimumTlsVersion": "1.2",
"publicNetworkAccess": "Enabled"
},
"sku": {
"capacity": 2,
"name": "Standard",
"tier": "Standard"
},
"type": "Microsoft.EventHub/namespaces"
}
]
}
},
"type": "Microsoft.Resources/deployments"
},

يحمل إدخال الموقع الخطة والشبكة الفرعية والصورة بوصفها الحاوية التي يشغّلها الموقع، والمنفذ الذي يعلنه الخادم العام:

"NotesApi": {
"apiVersion": "2025-03-01",
"kind": "app,linux,container",
"location": "northeurope",
"metadata": {
"aggrega.ai/provenance": {
"aggrega.ai/aggregate-name": "imported/notes",
"aggrega.ai/boundary-path": "default",
[… omitted: a compiler-version entry, which moves with the build]
"aggrega.ai/component-id": "notes-api",
"aggrega.ai/environment": "development",
"aggrega.ai/provider": "arm",
[… omitted: a provider-version entry, which moves with the build]
"aggrega.ai/recipe-uri": "server-app-service:1.0.0"
}
},
"name": "notes-api",
"properties": {
"clientAffinityEnabled": false,
"httpsOnly": true,
"publicNetworkAccess": "Disabled",
"serverFarmId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes",
"siteConfig": {
"alwaysOn": true,
"appSettings": [
{
"name": "WEBSITES_PORT",
"value": "8080"
}
],
"ftpsState": "Disabled",
"linuxFxVersion": "DOCKER|ghcr.io/example/notes-api:2.3.0",
"minTlsVersion": "1.2",
"vnetRouteAllEnabled": true
},
"virtualNetworkSubnetId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-network/providers/Microsoft.Network/virtualNetworks/vnet-notes/subnets/snet-app"
},
"type": "Microsoft.Web/sites"
},

يتلقى الموقع WEBSITES_PORT ولا شيء مما ضبطه القالب: أما EVENTHUB_NAMESPACE و EVENTHUB_NAME فمتغيّران لم تسلّمهما المسودة، وتسميهما سطور warn والتعليقات. واسم مساحة الأسماء هو ehmodule، وهو اسم المكوِّن، بينما سمّاها القالب evh-notes: تحديد name الخاص بالوحدة يعود إلى Recipe، ويدرجه التعليق فوق الإدخال بين المُعامِلات التي لا تترجمها المسودة.

نشر القالب

القالب هو قالب مجموعة موارد. لا يكتب البناء ملف مُعامِلات ولا يشغّل أي شيء على Azure: الأوامر لك. اعرض مسبقًا ما سيغيّره القالب، ثم انشره:

Terminal window
az deployment group what-if --resource-group <group> --template-file dist/arm/arm-template.json
az deployment group create --resource-group <group> --name <name> --template-file dist/arm/arm-template.json

تعرض صفحة ARM Provider هذه الأوامر، والمكدس الذي لا يحذف أبدًا ما توقف عن إدارته، وما تقرره كل علامة. قبل أن يُنشر القالب، يجب أن تكون الموارد التي يسمّيها Release ولا ينشرها القالب موجودة: خطة App Service والشبكة الفرعية التي ينضم إليها الموقع، وهي مفوَّضة إلى Microsoft.Web/serverFarms.

مع مساعد الذكاء الاصطناعي

يستطيع مساعد الذكاء الاصطناعي المُعَدّ بأدوات Aggrega أن يفعل الشيء نفسه: الصق هذا الموجِّه فيه.

استخدم أدوات Aggrega فقط، ولا تنشئ أي مجلد بنفسك. إذا لم يكن مجلد مساحة العمل يحتوي بعد على مجلد `import-arm`، فاستدعِ الأداة `draft` مرة واحدة مع تعيين `example` إلى `import-arm` ودون `dir`: فهي تكتب المثال في مجلد `import-arm` جديد. ثم استدعِ الأداة `import` مع تعيين `workspace_root` إلى `import-arm/source` و `source` إلى `notes`: فهي تكتب مسوَّداتها في `import-arm/source` وتشغّل pull لما تحتاج إليه. ثم استدعِ الأداة `build` مع تعيين `workspace_root` إلى `import-arm/reviewed` و `release` إلى `release.yaml` و `auto_pull` إلى true و `write` إلى true. أخبرني بالملفات التي كتبها البناء؛ فهي تحت `import-arm/reviewed/dist/`.

يحتوي المجلد reviewed على المسوَّدة مع كتابة القيم، كما يسردها التحقق؛ ولمراجعة مسودتك أنت، اطلب من المساعد أن يتحقق أولًا من import-arm/source ويخبرك بالموضع الذي يتوقف عنده.

افتحه في VS Code

بعد تثبيت امتداد Aggrega لمحرر Visual Studio Code، افتح المجلد import-arm/source في VS Code، حيث كتب الاستيراد مسوَّداته. يحتوي المجلد على Release واحد هو release.yaml المسوَّد، فيختاره المحرر نيابةً عنك، ويفحص المسوَّدات مقابل ذلك Release أثناء تحريرك لها، ويبرز ما يجده في الملف وفي لوحة Problems. يرسم Aggrega: Show topology graph، في لوحة الأوامر، مكوِّنات Release والاتصالات بينها. وتعمل Aggrega: Build و Aggrega: Preview build و Aggrega: Pull على Release نفسه، وكل منها أيضًا زر في لوحة Commands من عرض Aggrega في شريط النشاط؛ ويكتب Build ملفاته في dist/ الخاص بالمجلد. يغطي استخدام Aggrega في Visual Studio Code ما تبقى.

عند تغيّر القالب

أبقِ .aggrega-import.json بجوار المسوَّدات، وبعد تغيّر القالب شغِّل:

Terminal window
aggrega import notes --sync

يقرأ الهدف الذي يحتفظ به السجل، وهو arm، ولا يغيّر إلا ما كتبه الاستيراد. بعد أن يتغيّر outputLocation الخاص بتطبيق الويب الثابت من dist إلى build في main.json، يقول الاستيراد:

changed spec.components.notes-site.infra.overrides.outputLocation in release.yaml

ويكتب release.yaml مع تغيير ذلك السطر الواحد؛ وتبقى القيم التي كتبتها بجواره كما هي. والجزء الذي تركه المصدر دون تغيير يبقى كما هو على القرص، عدّلته أم لا؛ وحيث غيّر المصدر جزءًا عدّلته أنت، يتوقف ويسمّي الجزء ولا يكتب شيئًا، لتسوّي الفرق بينهما يدويًا. يصف aggrega import القواعد وكل علامة بالتفصيل الكامل.

يمكن لقالب أن ينشر قالبًا آخر عبر مورد Microsoft.Resources/deployments يسمّي فيه templateLink.relativePath ملفًا بجواره. يقرأ الاستيراد القوالب المُشار إليها داخل الدليل المستورد: يبدأ من قالب واحد، هو الجذر، ويقرأ كل قالب يشير إليه الجذر، ويُعِدّ مسوَّدة لموارد جميعها بوصفها Aggregate واحدًا.

يُحدَّد جذر الدليل الذي يحتوي على عدة قوالب بحسب ما يشير إلى ماذا: الجذر هو القالب الوحيد الذي لا يشير إليه قالب آخر. والدليل الذي يحتوي على قالبين لا إشارة بينهما ليس له جذر واحد، فيتوقف الاستيراد ويسمّي كليهما:

halt: the sources network.json, site.json are each linked by no other source, and the root setting names none of them: set root to the path of the one to start from

يسمّي إعداد root القالب الذي يُبدأ منه، في إدخال المستورِد ضمن تكوين مساحة العمل. ويسمّي uri المستورِد بهويته وبإصدار المحوِّل البرمجي الذي تشغّله، كما يكتبه aggrega plugin add importer (أي مستورِد يحوّل مصدرًا إلى مسوَّدات):

plugins:
importer:
- uri: importer/arm:<version>
with:
settings:
root: site.json

مع تعيين root، يقرأ الاستيراد site.json والقوالب التي يشير إليها، ويترك network.json خارجًا.

الرابط الذي يغادر الدليل المستورد — ../shared/dns.json — لا يُقرأ: فالاستيراد لا يفتح أبدًا ملفًا خارج الدليل الذي أُعطيه. ويحذّر، مسمّيًا المورد والمسار، ويُعِدّ مسوَّدة للمورد بوصفه موردًا قائمًا بذاته، حاملًا كل إخراج من ذلك القالب يقرؤه القالب على هيئة التعبير الذي يقيّمه عند نشر القالب:

warn: dns is a Microsoft.Resources/deployments resource of main.json whose template is linked by a relative path leaving the imported directory, which the import does not read: no resource of that template is drafted, and each of its outputs the template reads is carried as text evaluated when the template deploys; to draft its resources, place the linked template inside the imported directory and link it by templateLink.relativePath

ضع القالب المُشار إليه داخل الدليل المستورد فيقرأه الاستيراد التالي.

عندما يكون الاسم مستخدمًا

المورد الذي تجعله المسوَّدة Component يأخذ الاسم الذي يختاره الاستيراد له من نوعه: imported/compute/microsoft-web-staticsites لتطبيق الويب الثابت. وحيث يوجد Component بهذا الاسم أصلًا في مجلد كتالوج في مساحة العمل أو في hub، ولم يُعِدّه هذا الاستيراد مسوَّدة، لا يكتب الاستيراد فوقه ولا يخمّن. فيُبقي المورد جانبًا، فلا يُعِدّه مسوَّدة ولا يشير إليه، ويحذّر. وعند استيراد المثال مرة ثانية إلى مجلد آخر من مساحة العمل نفسها، مع --output-dir second، بعد أن كتب الاستيراد الأول Component في مجلد catalog الخاص بمساحة العمل، يقول:

warn: notes-site (Microsoft.Web/staticSites) is held back: the catalog holds the Component imported/compute/microsoft-web-staticsites a draft of it takes, which this import did not draft, so the resource is neither drafted nor referenced; to reference it, write in the importer's settings the entry {"mapping_overrides":{"arm":{"Microsoft.Web/staticSites":{"component":"imported/compute/microsoft-web-staticsites","category":"compute","traits":{"component.aggrega.ai/hosting":"managed","component.aggrega.ai/type":"resource"},"vendor":"staticsites"}}}}, then fill the instance's infra in the Release

يعيّن إعداد mapping_overrides في إدخال المستورِد، المفهرس بالصيغة arm ثم بنوع المورد، النوع إلى Component الموجود، والإدخال الذي يطبعه التحذير هو الذي يُكتب (الإعدادات). ومعه يشير الاستيراد التالي إلى Component: يُعيَّن notes-site بوصفه مرجعًا، ولا يحتوي إدخاله في Release على مفاتيح بل على تعليق فقط يسمّي الخصائص التي يكتبها القالب:

notes-site: {}

يعلن Component كلًّا من name و location على أنه مطلوب ولا تكتب المسوَّدة أيًّا منهما، فينتهي الاستيراد بالإبلاغ عن كل منهما بوصفه مفقودًا، مع كتابة المسوَّدات. اكتبهما، والخصائص التي يسردها التعليق، في Release، كما يعلنها Component.

ما تتركه المسوَّدة لك

يُعِدّ الاستيراد مسوَّدة لما يذكره القالب ولما يحدده الكتالوج لديك، ويقول أين توقف. ويترك للقالب ما يلي:

  • الطبقة التحتية التي ينشئها القالب لخدمة غيرها. توجد الشبكة الافتراضية vnet-notes وشبكتها الفرعية في القالب من أجل الموقع. لا تنشئ المسوَّدة أي شبكة: يأخذ Component من الكتالوج الشبكة التي يعمل فيها بمعرّف موردها، تحت infra.overrides، والشبكة من مسؤوليتك. يسمّي سطر warn كل مورد من هذا النوع، والمؤشرات التي كانت تشير إليه هي المفاتيح الفارغة في Release. وفي الموضع الذي ينشر فيه Release، تكون الشبكة والشبكة الفرعية موجودتين أصلًا، أو تنشرهما أنت مع القالب الذي استوردته.
  • القيم التي لا تضعها المسوَّدة. يسرد تعليق كل إدخال في Release مُعامِلات الوحدة وخصائص المورد التي لا تضعها المسوَّدة، ومنها هنا فئة مساحة الأسماء ووحدات الإنتاجية والمنطقة والاسم، و kind و linuxFxVersion الخاصان بالموقع، ليُذكر إعداد القالب ولا يُسقَط بصمت. وحيث يكون في Component مكان لأحدها، تكتبه أنت، كما يفعل قسم التحقق.
  • متغيّرات البيئة التي لا يسلّمها أي اتصال. يُذكر EVENTHUB_NAMESPACE و EVENTHUB_NAME الخاصان بالموقع في تعليقات Aggregate و Release وفي سطر warn لكل منهما. وحيث يُكوَّن الموقع في Release، تضبطهما أنت.
  • صورة الحاوية. لا تحمل المسوَّدة صورة إلا حيث يذكرها القالب في خاصية تضعها المسوَّدة. يكتب هذا القالب الصورة في linuxFxVersion، ولذلك لا تحمل المسوَّدة أيًّا منها، ويتوقف البناء مسمّيًا infra.image: فالصورة عليك أن تقدمها في Release.

الوحدة التي لا تعيّن لها المكتبة القياسية شيئًا تُحفظ كاملة. وحيث ينشر قالب وحدة من Azure Verified Modules لنوع مورد لا يعيّنه أي صف من صفوف المستورِد، يُعِدّ الاستيراد مسوَّدة Component و Recipe يحدّدان الوحدة مصدرًا بالعنوان oci://mcr.microsoft.com/bicep/<path> مع تعطيل القياس عن بُعد، ويُترك مُعامِل الوحدة الذي يغذّيه سرّ خارجًا ويُحذَّر منه. ويُعَدّ مسودةً من القالب المورد الذي لا يعيّن أي صف نوعه كما يحدث مع تطبيق الويب الثابت؛ ويسمّي تلميح التبديل في المسوَّدات aggrega import --format arm-schema، الذي يُعِدّ مسوَّدة Component نفسه من مخطط المورِّد بدلًا من ذلك، كما يصف نشر خدمة لا يملكها الكتالوج.

سلسلة نصية مكتوبة على أسطر متعددة

لا يقبل JSON فاصل سطر خامًا داخل سلسلة نصية، ويقرأ المستورِد القالب بوصفه JSON. والقالب الذي يحتوي على واحد — نص برمجي مكتوب عبر أسطر في قيمة scriptContent — لا يُتعرَّف عليه، لأن قراءته تفشل:

[E0350]
no importer recognises the source (source "main.json"). Pass --format to name it explicitly (for example --format agent-framework, --format arm-schema, --format arm, --format cloudformation-schema, --format compose, --format crewai, --format dify, --format flowise, --format google-adk, --format langflow, --format langgraph, --format mcp, --format n8n or --format terraform-schema)

ومع --format arm، يتوقف الاستيراد مسمّيًا الموضع:

halt: could not parse source "main.json" as arm: json parse: invalid character '\n' in string literal at line 14, column 35

اكتب كل سلسلة نصية على سطر واحد، مع \n حيث ينكسر النص، ويقرؤها الاستيراد.