From 4e4a0a38779bb8c6ae8e5c16f3bdb8cf98700143 Mon Sep 17 00:00:00 2001 From: Darksome Date: Thu, 25 Apr 2024 10:57:11 +0000 Subject: [PATCH] feat: runner timeout --- .../workflows/{run-task.yml => setup-runners.yml} | 14 ++++++-------- Dockerfile | 2 ++ main.tf | 10 ++++++++-- {run_task => setup-runners}/main.tf | 8 ++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) rename .github/workflows/{run-task.yml => setup-runners.yml} (90%) rename {run_task => setup-runners}/main.tf (92%) diff --git a/.github/workflows/run-task.yml b/.github/workflows/setup-runners.yml similarity index 90% rename from .github/workflows/run-task.yml rename to .github/workflows/setup-runners.yml index 209096a..ba257bc 100644 --- a/.github/workflows/run-task.yml +++ b/.github/workflows/setup-runners.yml @@ -1,12 +1,9 @@ -name: Run ECS Fargate Github Action Runner task(s) - on: workflow_call: inputs: cpu: description: 'Amount of CPU units to allocate to a single task' type: string - required: true default: '512' memory: description: 'Amount of memory (MB) to allocate to a single task' @@ -15,13 +12,15 @@ on: labels: description: 'Coma-separated list of labels to assign to the tasks' type: string - required: true default: '' count: description: 'Number of tasks to run' type: string - required: true default: '1' + timeout: + description: 'Runner timeout' + type: string + default: '30m' secrets: TF_API_TOKEN: required: true @@ -29,8 +28,7 @@ on: required: true jobs: - run-task: - name: Run ECS task + setup-runners: runs-on: ubuntu-latest steps: - name: Generate runner token @@ -71,7 +69,7 @@ jobs: echo 'run_task=true' >> .auto.tfvars echo 'cpu=${{ inputs.cpu }}' >> .auto.tfvars echo 'memory=${{ inputs.memory }}' >> .auto.tfvars - echo 'runner_token="${{ steps.gen-token.outputs.result }}"' >> .auto.tfvars + echo 'runner_token="::add-mask::${{ steps.gen-token.outputs.result }}"' >> .auto.tfvars echo 'repo_url="https://github.com/${{ github.repository }}"' >> .auto.tfvars echo 'labels="${{ inputs.labels }}"' >> .auto.tfvars echo 'desired_count=${{ inputs.count }}' >> .auto.tfvars diff --git a/Dockerfile b/Dockerfile index 6a30d3e..7476a78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,3 +3,5 @@ FROM myoung34/github-runner:ubuntu-focal # modify actions runner binaries to allow custom cache server implementation # https://gha-cache-server.falcondev.io/getting-started RUN sed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /actions-runner/bin/Runner.Worker.dll + +CMD ["timeout", "$TIMEOUT", "./bin/Runner.Listener", "run", "--startuptype", "service"] diff --git a/main.tf b/main.tf index d1cb917..573dd65 100644 --- a/main.tf +++ b/main.tf @@ -61,6 +61,11 @@ variable "desired_count" { default = null } +variable "timeout" { + type = string + default = null +} + locals { availability_zone = "eu-central-1a" } @@ -121,13 +126,14 @@ module "runner" { cache_url = module.cache-server.url } -module "run_task" { +module "setup-runners" { count = var.run_task ? 1 : 0 - source = "./run_task" + source = "./setup-runners" cpu = var.cpu memory = var.memory runner_token = var.runner_token repo_url = var.repo_url labels = var.labels desired_count = var.desired_count + timeout = var.timeout } diff --git a/run_task/main.tf b/setup-runners/main.tf similarity index 92% rename from run_task/main.tf rename to setup-runners/main.tf index 64434c8..3dfbf54 100644 --- a/run_task/main.tf +++ b/setup-runners/main.tf @@ -22,6 +22,10 @@ variable "desired_count" { type = number } +variable "timeout" { + type = string +} + data "aws_ecs_cluster" "this" { cluster_name = "github-actions-runner" } @@ -76,6 +80,10 @@ data "aws_ecs_task_execution" "this" { key = "START_DOCKER_SERVICE" value = true } + environment { + key = "TIMEOUT" + value = var.timeout + } } } }