온디맨드로 실행되는 태스크: 하나의 Aggregate, 네 개의 대상
core/manual-trigger를 가진 태스크를 Kubernetes, Docker Compose, Terraform, CloudFormation에 시작하지 않은 채 배포하고, 아무것도 가지지 않은 태스크를 나란히 두며, 각 대상에서 실행을 시작하는 명령을 함께 보여 줍니다.
어떤 작업은 누군가 요청할 때만 완료될 때까지 실행됩니다. 일회성 데이터 수정이나 요청에 따른 백업 같은 것입니다. core/manual-trigger는 이를 위한 Feature입니다. 일정이 없는 core/compute/task에 연결되면 태스크를 시작하지 않고 배포하며, 각 실행은 누군가 대상 자체의 명령으로 직접 시작하는 실행이 됩니다.
이 워크스페이스는 네 개의 대상(Helm을 통한 Kubernetes, Docker Compose, Terraform, CloudFormation)을 위해 하나의 Aggregate를 빌드하고, 각 대상에서 연결이 렌더링된 출력의 무엇을 바꾸는지와 실행을 시작하는 명령을 보여 줍니다. 두 번째 태스크는 연결을 가지지 않으므로 같은 빌드 안에서 차이를 볼 수 있습니다. 추가로 두 Releases는 중단될 것으로 예상되며, 이 페이지는 각각이 출력하는 내용을 인용합니다.
구성되는 내용
| 인스턴스 | 카탈로그 Component | 연결 | 실행을 시작하는 것 |
|---|---|---|---|
data-fix | core/compute/task | core/manual-trigger | 누군가가 직접, 모든 대상에서 |
report | core/compute/task | 없음 | 해당 일정, 또는 Docker Compose에서는 스택 시작 |
연결은 Aggregate 안에서 그것이 변경하는 태스크 옆에 있습니다. 온디맨드 실행은 data-fix가 무엇인지의 일부이므로 개발자가 이를 작성하며, 해당 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입니다. 연결에 대해 FeatureRecipe를 바인딩하지 않는 Manifest는 그것을 명시하며 빌드를 중단합니다.
core/compute/task는 소프트웨어를 패키징하지 않으므로, 각 Release는 각 태스크가 실행하는 이미지를 infra.image 아래에 지정합니다. AWS Releases는 또한 infra.overrides 아래에 각 태스크가 사용하는 클러스터, 서브넷, 보안 그룹, 실행 역할을 지정하고, report에 일정이 있는 경우 일정이 각 실행을 시작할 때 사용하는 역할도 지정합니다. 그곳의 모든 계정별 값은 자리표시자입니다.
예제 생성하기
아래 명령으로 이 예제를 빌드하거나, AI 어시스턴트에게 대신 빌드하게 할 수 있습니다.
예제 이름을 딴 새 폴더에 예제를 씁니다:
aggrega scaffold --example task-run-on-demand그런 다음 이어서 실행할 명령을 출력합니다. 첫 번째 명령은 새 폴더로 이동합니다:
cd task-run-on-demand빌드
워크스페이스는 .aggrega-config.yaml이 지정하는 hub 레지스트리에서 표준 라이브러리 카탈로그를 읽습니다. 여기의 모든 Recipe는 카탈로그만으로 렌더링되므로, 잠금 파일이 해석되고 나면 모든 빌드가 오프라인으로 실행됩니다.
aggrega build --release release-helm.yaml --auto-pull # one Release문서 저장소의 체크아웃(aggrega scaffold --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 도구만 사용하고, 폴더를 직접 만들지 마십시오. 작업 영역 폴더에 아직 `task-run-on-demand` 폴더가 없으면 `example`을 `task-run-on-demand` 값으로 설정하고 `dir` 없이 `scaffold` 도구를 한 번 호출하십시오. 그러면 새 `task-run-on-demand` 폴더에 예제가 작성됩니다. 그런 다음 `workspace_root`를 `task-run-on-demand` 값으로, `release`를 `release-helm.yaml` 값으로, `auto_pull`을 true로, `write`를 true로 설정하여 `build` 도구를 호출하십시오. 빌드가 작성한 파일을 알려 주십시오. 파일은 `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 *는 어떤 해에도 없는 날짜인 2월 30일을 가리킵니다. 일시 중단된 상태에서 CronJob은 실행을 시작하지 않고, 재개되더라도 실행을 시작할 시각이 없습니다. 연결이 없으면 일정이 없는 태스크는 Job이 되며, 배포되자마자 실행됩니다.
report는 Release가 채운 일정에 따르는 CronJob이며 일시 중단되지 않습니다:
[… 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은 태스크마다 module 블록 하나를 가진 루트 구성과, 그 옆에 각 태스크의 모듈을 작성합니다. 두 블록은 일정에서 차이가 납니다:
# 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로 하여 번호가 매겨지고, Release가 시간대를 지정하지 않으므로 UTC가 사용됩니다.
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을 채우고, core/manual-trigger도 report에 연결합니다. 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가 채우는 매개변수를 통해 태스크에 도달하므로, 컴포넌트에 일정을 주는 것은 release-terraform.yaml이 하듯 report_schedule을 채우는 것을 뜻합니다.