माँग पर चलाया जाने वाला टास्क: एक Aggregate, चार लक्ष्य
core/manual-trigger वहन करने वाला एक टास्क, जो Kubernetes, Docker Compose, Terraform और CloudFormation पर बिना शुरू हुए डिप्लॉय होता है, कुछ भी वहन न करने वाले एक टास्क के बगल में, और हर लक्ष्य पर रन शुरू करने वाले कमांड के साथ।
कुछ काम पूरा होने तक तभी चलता है जब कोई उसके लिए कहता है: एक बार का डेटा सुधार, अनुरोध पर लिया जाने वाला बैकअप। core/manual-trigger इसी के लिए Feature है। बिना शेड्यूल वाले किसी core/compute/task पर अटैच होने पर, यह टास्क को बिना शुरू किए डिप्लॉय करता है, और हर रन ऐसा होता है जिसे कोई व्यक्ति लक्ष्य के अपने कमांड से हाथ से शुरू करता है।
यह वर्कस्पेस एक Aggregate को चार लक्ष्यों के लिए बिल्ड करता है — Helm के ज़रिए Kubernetes, Docker Compose, Terraform और CloudFormation — और हर एक पर दिखाता है कि अटैचमेंट रेंडर किए गए आउटपुट में क्या बदलता है और रन शुरू करने वाला कमांड क्या है। दूसरा टास्क कोई अटैचमेंट वहन नहीं करता, इसलिए अंतर उसी बिल्ड में दिखाई देता है। दो और Releases के रुकने की अपेक्षा है, और पेज उद्धृत करता है कि हर एक क्या प्रिंट करता है।
यह क्या बिल्ड करता है
| इंस्टेंस | कैटलॉग Component | अटैचमेंट | रन किससे शुरू होता है |
|---|---|---|---|
data-fix | core/compute/task | core/manual-trigger | कोई व्यक्ति, हाथ से, हर लक्ष्य पर |
report | core/compute/task | कोई नहीं | उसका शेड्यूल, या, Docker Compose पर, स्टैक का शुरू होना |
अटैचमेंट Aggregate में, उस टास्क के बगल में होता है जिसे वह बदलता है: माँग पर चलना इस बात का हिस्सा है कि data-fix क्या है, इसलिए डेवलपर (Developer) इसे लिखता है, और Feature न कोई मान लेता है और न कोई infra। Release इसके लिए कुछ नहीं लिखता।
report का शेड्यूल एक पैरामीटर है, report_schedule, जिसे Aggregate खाली डिफ़ॉल्ट के साथ घोषित करता है और टास्क के schedule मान में पढ़ता है:
spec: parameters: report_schedule: type: string default: "" [… omitted: the parameter's description]
components: [… omitted: data-fix with its attachment, and the comment above each task] report: type: core/compute/task values: schedule: "{{ .parameters.report_schedule }}"यह एक पैरामीटर है क्योंकि बिना अटैचमेंट वाले टास्क के बारे में चारों लक्ष्य असहमत हैं। Kubernetes उसे शेड्यूल होने पर CronJob के रूप में उस शेड्यूल पर चलाता है, या शेड्यूल न होने पर डिप्लॉय के समय एक बार। Docker Compose के पास कोई शेड्यूलर नहीं है, इसलिए वह स्टैक के हर बार शुरू होने पर टास्क को एक बार चलाता है और शेड्यूल को अस्वीकार करता है। AWS पर, Terraform या CloudFormation के अप्लाई होने पर कुछ भी Amazon ECS टास्क नहीं चलाता, इसलिए वहाँ टास्क को एक शेड्यूल या अटैचमेंट चाहिए, और दोनों के बिना वह अस्वीकार होता है। इसलिए Kubernetes, Terraform और CloudFormation Releases report_schedule को पूरा करते हैं, और Docker Compose Release उसे खाली छोड़ता है।
data-fix चारों पर एक ही तरह से बिल्ड होता है, बिना शेड्यूल और बिना पैरामीटर के।
छह Releases
| Release | Manifest | report_schedule | बिल्ड |
|---|---|---|---|
release-helm.yaml | manifest-helm.yaml | 30 2 * * 1-5 | पूरा होता है |
release-compose.yaml | manifest-compose.yaml | खाली | पूरा होता है |
release-terraform.yaml | manifest-terraform.yaml | 30 2 * * 1-5 | पूरा होता है |
release-cloudformation.yaml | manifest-cloudformation.yaml | 30 2 * * 1-5 | पूरा होता है |
release-compose-scheduled.yaml | manifest-compose.yaml | 30 2 * * 1-5 | रुक जाता है |
release-terraform-unscheduled.yaml | manifest-terraform.yaml | खाली | रुक जाता है |
हर Manifest core/compute/task को अपने लक्ष्य के Recipe से मैप करता है और core/manual-trigger को अपने लक्ष्य के FeatureRecipe से बाइंड करता है: helm/task और helm/manual-trigger, compose/task और compose/manual-trigger, terraform/task-ecs और terraform/manual-trigger, और cloudformation/task-ecs और cloudformation/manual-trigger। जो Manifest अटैचमेंट के लिए कोई FeatureRecipe बाइंड नहीं करता, उससे बिल्ड अटैचमेंट का नाम लेते हुए रुक जाता है।
हर Release infra.image के अंतर्गत वह इमेज नामित करता है जिसे हर टास्क चलाता है, क्योंकि core/compute/task कोई सॉफ़्टवेयर पैकेज नहीं करता। AWS Releases infra.overrides के अंतर्गत वह क्लस्टर, सबनेट, सिक्योरिटी ग्रुप और एक्ज़िक्यूशन रोल भी नामित करते हैं जिनके साथ हर टास्क चलता है, और, जहाँ report का शेड्यूल है, वहाँ वह रोल जिसके अंतर्गत शेड्यूल हर रन शुरू करता है। वहाँ हर खाता-विशिष्ट मान एक प्लेसहोल्डर है।
उदाहरण ड्राफ़्ट करें
आप यह उदाहरण नीचे दिए कमांड से बिल्ड कर सकते हैं, या अपने AI असिस्टेंट से इसे अपने लिए बिल्ड करवा सकते हैं।
उदाहरण को उसी के नाम वाले एक नए फ़ोल्डर में लिखें:
aggrega draft --example task-run-on-demandफिर यह आगे चलाने के लिए कमांड प्रिंट करता है। पहला कमांड नए फ़ोल्डर में ले जाता है:
cd task-run-on-demandबिल्ड करें
वर्कस्पेस स्टैंडर्ड-लाइब्रेरी कैटलॉग को उस हब रजिस्ट्री से पढ़ता है जिसका नाम .aggrega-config.yaml लेता है। यहाँ का हर Recipe केवल कैटलॉग से रेंडर होता है, इसलिए लॉकफ़ाइल रिज़ॉल्व हो जाने के बाद हर बिल्ड ऑफ़लाइन चलता है।
aggrega build --release release-helm.yaml --auto-pull # one Releaseदस्तावेज़ीकरण रिपॉज़िटरी के चेकआउट में, जिसमें वह साझा बिल्ड हेल्पर है जो aggrega draft --example द्वारा लिखी गई प्रति में नहीं होता, ./check.sh सभी छह Releases बिल्ड करता है और हर परिणाम की जाँच करता है। यह हर Release के लिए एक पंक्ति प्रिंट करता है और 0 के साथ तभी बाहर निकलता है जब हर एक वैसे ही समाप्त हुआ हो जैसा यह पेज बताता है:
RELEASE EXIT EXPECTED VERDICT----------------------------------------------------------------------------------------------------release-helm.yaml 0 complete OK: completed, the files the README showsrelease-compose.yaml 0 complete OK: completed, the files the README showsrelease-terraform.yaml 0 complete OK: completed, the files the README showsrelease-cloudformation.yaml 0 complete OK: completed, the files the README showsrelease-compose-scheduled.yaml 1 halt OK: halted with the expected refusalrelease-terraform-unscheduled.yaml 1 halt OK: halted with the expected refusal
check: every build ended as expected.AI असिस्टेंट के साथ
Aggrega के टूल के साथ सेट अप किया गया AI असिस्टेंट भी यही कर सकता है: यह प्रॉम्प्ट उसमें पेस्ट करें।
केवल Aggrega टूल का उपयोग करें, और स्वयं कोई फ़ोल्डर न बनाएं। यदि Workspace फ़ोल्डर में अभी कोई `task-run-on-demand` फ़ोल्डर नहीं है, तो `draft` टूल को एक बार कॉल करें, `example` को `task-run-on-demand` पर सेट करके और बिना `dir` के: यह उदाहरण को एक नए `task-run-on-demand` फ़ोल्डर में लिखता है। फिर `build` टूल को कॉल करें, `workspace_root` को `task-run-on-demand` पर, `release` को `release-helm.yaml` पर, `auto_pull` को true पर और `write` को true पर सेट करके। मुझे बताएं कि बिल्ड ने कौन-सी फ़ाइलें लिखीं; वे `task-run-on-demand/dist/` के अंतर्गत हैं।Kubernetes
release-helm.yaml दो फ़ाइलें लिखता है, प्रति टास्क एक CronJob, और कुछ नहीं। data-fix निलंबित रखा गया एक CronJob है, ऐसे शेड्यूल पर जिसे डेवलपर ने कभी नहीं लिखा:
apiVersion: batch/v1kind: CronJobmetadata: name: data-fix [… omitted: the labels and annotations the build writes on every resource]spec: schedule: 0 0 30 2 * suspend: true jobTemplate: spec: template: [… omitted: the pod template's metadata, the same labels again] spec: containers: - name: main image: registry.example.com/orders-data-fix:2.0.1 [… omitted: the container's CPU and memory requests and limits] restartPolicy: NeverCronJob को एक शेड्यूल चाहिए, और 0 0 30 2 * 30 फ़रवरी का नाम लेता है, एक ऐसी तारीख जो किसी भी वर्ष में नहीं आती: निलंबित रहने पर CronJob कोई रन शुरू नहीं करता, और फिर से चालू किए जाने पर भी उसके पास रन शुरू करने का कोई समय नहीं होता। अटैचमेंट के बिना, बिना शेड्यूल वाला टास्क एक Job होता, जो डिप्लॉय होते ही चल पड़ता है।
report उस शेड्यूल पर एक CronJob है जिसे Release ने पूरा किया, और वह निलंबित नहीं है:
[… omitted: apiVersion, kind and metadata, as in data-fix-cronjob.yaml under report's name]spec: schedule: 30 2 * * 1-5 jobTemplate: [… omitted: the job template, as in data-fix-cronjob.yaml with report's image]data-fix का एक रन उसके CronJob से बनाया गया एक Job है, आपके द्वारा चुने गए नाम के अंतर्गत:
kubectl create job data-fix-run-1 --from=cronjob/data-fixयही कमांड, --from=cronjob/report दिए जाने पर, report के शेड्यूल किए गए रन के बीच उसका एक अतिरिक्त रन शुरू करता है।
Docker Compose
release-compose.yaml एक Compose फ़ाइल लिखता है। हर टास्क एक ऐसी सेवा है जिसे Compose उसके बाहर निकलने पर फिर से शुरू नहीं करता; data-fix प्रोफ़ाइल manual भी वहन करता है, और report कोई प्रोफ़ाइल वहन नहीं करता:
services: data-fix: image: registry.example.com/orders-data-fix:2.0.1 [… omitted: the labels the build writes on every service, and the service's network] restart: "no" [… omitted: the CPU and memory limits and reservations] profiles: - manual report: image: registry.example.com/orders-report:1.4.2 [… omitted: the labels and the network, as on data-fix] restart: "no" [… omitted: the CPU and memory limits and reservations, as on data-fix][… omitted: the network the services join]Compose प्रोफ़ाइल वहन करने वाली किसी सेवा को तभी शुरू करता है जब वह प्रोफ़ाइल सक्षम हो या कमांड लाइन पर सेवा का नाम लिया गया हो, इसलिए docker compose up report को एक बार चलाता है और data-fix को रुका हुआ छोड़ देता है। data-fix का रन उसकी सेवा का नाम लेकर शुरू किया जाता है, और रन समाप्त होते ही --rm उसका कंटेनर हटा देता है:
docker compose -f dist/compose/docker-compose.yaml run --rm data-fixTerraform
release-terraform.yaml प्रति टास्क एक मॉड्यूल ब्लॉक वाला एक रूट कॉन्फ़िगरेशन लिखता है, और उसके बगल में हर टास्क का मॉड्यूल। दोनों ब्लॉक शेड्यूल में भिन्न हैं:
# Root configuration for this boundary. Each component rendered here is one# module block below, and the directory that block points at holds that# component's own files. One configuration means one dependency graph, which is# what lets a reference or a depends_on reach from one component to another.
module "data-fix" { source = "./modules/data-fix"
assign_public_ip = false cluster = "arn:aws:ecs:eu-west-1:123456789012:cluster/example-cluster" cpu = "256" environment = {} execution_role_arn = "arn:aws:iam::123456789012:role/example-ecs-task-execution" image = "registry.example.com/orders-data-fix:2.0.1" memory = "512" name = "data-fix" security_groups = ["sg-0fedcba9876543210"] subnet_ids = ["subnet-0123456789abcdef0"]}
module "report" { source = "./modules/report"
assign_public_ip = false cluster = "arn:aws:ecs:eu-west-1:123456789012:cluster/example-cluster" cpu = "256" environment = {} execution_role_arn = "arn:aws:iam::123456789012:role/example-ecs-task-execution" image = "registry.example.com/orders-report:1.4.2" memory = "512" name = "report" schedule_expression = "cron(30 2 ? * 2,3,4,5,6 *)" schedule_expression_timezone = "UTC" scheduler_role_arn = "arn:aws:iam::123456789012:role/example-scheduler" security_groups = ["sg-0fedcba9876543210"] subnet_ids = ["subnet-0123456789abcdef0"]}मॉड्यूल EventBridge Scheduler शेड्यूल तभी घोषित करता है जब उसे कोई एक्सप्रेशन दिया गया हो, इसलिए data-fix की टास्क डेफ़िनिशन अकेली रहती है:
[… omitted: the provider requirement, the Region lookup, the task definition and the comments on each]resource "aws_scheduler_schedule" "this" { count = var.schedule_expression == null ? 0 : 1[… omitted: the rest of the schedule]Recipe report का शेड्यूल EventBridge Scheduler के अपने रूप में लिखता है: 30 2 * * 1-5 बन जाता है cron(30 2 ? * 2,3,4,5,6 *), जिसमें सप्ताह के दिन रविवार को 1 मानकर गिने जाते हैं, और यह UTC में है क्योंकि Release कोई टाइम ज़ोन नामित नहीं करता।
CloudFormation
release-cloudformation.yaml एक स्टैक टेम्पलेट लिखता है। इसमें हर टास्क के लिए एक टास्क डेफ़िनिशन है और केवल report के लिए एक शेड्यूल:
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "DataFixTaskDefinition": { [… omitted: the provenance metadata the build writes on every resource] "Properties": { "ContainerDefinitions": [ { "Essential": true, "Image": "registry.example.com/orders-data-fix:2.0.1", "Name": "main" } ], "Cpu": "256", "ExecutionRoleArn": "arn:aws:iam::123456789012:role/example-ecs-task-execution", "Family": "data-fix", "Memory": "512", "NetworkMode": "awsvpc", "RequiresCompatibilities": [ "FARGATE" ] }, "Type": "AWS::ECS::TaskDefinition" }, "ReportSchedule": { [… omitted: the provenance metadata] "Properties": { "FlexibleTimeWindow": { "Mode": "OFF" }, "ScheduleExpression": "cron(30 2 ? * 2,3,4,5,6 *)", "ScheduleExpressionTimezone": "UTC", "Target": { "Arn": "arn:aws:ecs:eu-west-1:123456789012:cluster/example-cluster", "EcsParameters": { [… omitted: the launch type, the network configuration and the task count each run starts with] "TaskDefinitionArn": { "Ref": "ReportTaskDefinition" } }, "RoleArn": "arn:aws:iam::123456789012:role/example-scheduler" } }, "Type": "AWS::Scheduler::Schedule" }, "ReportTaskDefinition": { [… omitted: the same shape as DataFixTaskDefinition, with report's image and family] } }}स्टैक में कुछ भी DataFixTaskDefinition का संदर्भ नहीं देता, इसलिए उसे कुछ भी शुरू नहीं करता।
Amazon ECS पर रन शुरू करना
दोनों AWS लक्ष्यों पर data-fix का रन Amazon ECS RunTask ऑपरेशन से शुरू किया जाता है, जिसे टास्क डेफ़िनिशन की फ़ैमिली, जैसी वह रेंडर हुई, और वह क्लस्टर और नेटवर्क कॉन्फ़िगरेशन दिया जाता है जिसे Release infra.overrides के अंतर्गत नामित करता है:
aws ecs run-task \ --cluster arn:aws:ecs:eu-west-1:123456789012:cluster/example-cluster \ --task-definition data-fix \ --launch-type FARGATE \ --network-configuration 'awsvpcConfiguration={subnets=[subnet-0123456789abcdef0],securityGroups=[sg-0fedcba9876543210],assignPublicIp=DISABLED}'केवल अपनी फ़ैमिली से नामित किए जाने पर, टास्क डेफ़िनिशन अपने नवीनतम सक्रिय रिविज़न पर रिज़ॉल्व होती है।
बिल्ड क्या नहीं करता
बिल्ड फ़ाइलें लिखता है और रुक जाता है। वह किसी भी लक्ष्य पर कोई रन शुरू नहीं करता: वह किसी क्लस्टर तक नहीं पहुँचता, कोई Compose स्टैक शुरू नहीं करता और कोई AWS API कॉल नहीं करता, और अटैचमेंट केवल वह बदलता है जो फ़ाइलें कहती हैं। वह कोई स्क्रिप्ट भी नहीं लिखता: इस पेज का हर कमांड लक्ष्य का अपना है, जिसे वही चलाता है जो उसे संचालित करता है, और कोई भी कमांड dist/ में नहीं है। अटैचमेंट के रियलाइज़ेशन किसी भी लक्ष्य पर अपनी कोई फ़ाइल नहीं जोड़ते; हर एक जो बदलाव करता है, वह टास्क के अपने आउटपुट में है, जो ऊपर दिखाया गया है।
रुकने वाले दो Releases
release-compose-scheduled.yaml Docker Compose पर report_schedule को पूरा करता है, और report पर core/manual-trigger भी अटैच करता है। Kubernetes और AWS पर शेड्यूल वाला टास्क उस शेड्यूल पर चलता है, चाहे अटैचमेंट हो या न हो; Docker Compose पर, कोई शेड्यूलर न होने के कारण, शेड्यूल वाले टास्क का कोई रियलाइज़ेशन नहीं होता, अटैचमेंट हो या न हो। aggrega build --release release-compose-scheduled.yaml --auto-pull रुक जाता है:
[… omitted: what resolving the lockfile prints, the same halt among it][CATALOG_ERROR E0033] Recipe/FeatureRecipe assertions caused by: Recipe "task" instance "report" assertion "schedule_refused": [… omitted: the template position and the assertion's own source]: error calling fail: assertion failed: the component "report" is scheduled "30 2 * * 1-5", and Docker Compose has no scheduler: nothing in a compose file starts a service at a time, so the run would happen at none of the times written. Map core/compute/task to helm/task in the Manifest, which runs it on its schedule as a Kubernetes CronJob; or remove the schedule from the component in the Aggregate to run it once at each docker compose up, or attach core/manual-trigger to it there to start each run with docker compose run --rmrelease-terraform-unscheduled.yaml Terraform पर report_schedule को खाली छोड़ता है, इसलिए report के पास न कोई शेड्यूल है और न अटैचमेंट, और AWS पर उसे कभी कुछ भी शुरू नहीं करेगा। यही वह मामला है जिसके लिए core/manual-trigger मौजूद है, और aggrega build --release release-terraform-unscheduled.yaml --auto-pull उसका नाम लेते हुए रुक जाता है:
[… omitted: what resolving the lockfile prints, the same halt among it][CATALOG_ERROR E0033] Recipe/FeatureRecipe assertions caused by: Recipe "task-ecs" instance "report" assertion "schedule_translates": [… omitted: the template position and the assertion's own source]: error calling fail: assertion failed: the component "report" has no schedule and carries no core/manual-trigger attachment, so it runs once, and nothing on AWS starts a run that happens once: neither Terraform nor CloudFormation runs an Amazon ECS task when it applies, so the run would never happen. Give the component a schedule in the Aggregate; attach core/manual-trigger to it there to deploy its task definition alone, for the operator to start each run with aws ecs run-task; or map core/compute/task to helm/task in the Manifest, which runs it once on Kubernetesयहाँ शेड्यूल टास्क तक एक ऐसे पैरामीटर के ज़रिए पहुँचता है जिसे Release पूरा करता है, इसलिए घटक को शेड्यूल देने का अर्थ है report_schedule को पूरा करना, जैसा release-terraform.yaml करता है।