From bd491714559cf8401422e6c27f1e8ebd0af61e30 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Fri, 9 Apr 2021 15:59:08 -0700 Subject: [PATCH] stdlib/aws: implemented ecs run-task script to invoke containers on ecs Signed-off-by: Sam Alba --- stdlib/aws/ecs/run-task.cue | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 stdlib/aws/ecs/run-task.cue diff --git a/stdlib/aws/ecs/run-task.cue b/stdlib/aws/ecs/run-task.cue new file mode 100644 index 00000000..3e4c25f0 --- /dev/null +++ b/stdlib/aws/ecs/run-task.cue @@ -0,0 +1,64 @@ +package ecs + +import ( + "dagger.io/aws" +) + +// RunTask implement ecs run-task +#RunTask: { + + // AWS Config + config: aws.#Config + + // ECS cluster name + cluster: string + + // Arn of the task to run + taskArn: string + + // Environment variables of the task + containerEnvironment: [string]: string + + // Container name + containerName: string + + // Container command to give + containerCommand: [...string] + + // Task role ARN + roleArn: string | *"" + + containerOverrides: { + "containerOverrides": [{ + name: containerName + if len(containerCommand) > 0 { + "command": containerCommand + } + if len(containerEnvironment) > 0 { + "environment": [ for k, v in containerEnvironment {"name": k, "value": v}] + } + }] + if roleArn != "" { + taskRoleArn: roleArn + } + } + + aws.#Script & { + "config": config + export: "/out" + files: { + "/inputs/cluster": cluster + "/inputs/task_arn": taskArn + "/inputs/container_overrides": containerOverrides + } + code: #""" + cat /inputs/container_overrides | jq + + aws ecs run-task \ + --cluster "$(cat /inputs/cluster)" \ + --task-definition "$(cat /inputs/task_arn)" \ + --overrides "$(cat /inputs/container_overrides)" \ + > /out + """# + } +}