Skip to content

Commit

Permalink
feat: runner timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
xDarksome committed Apr 25, 2024
1 parent f4dc8b4 commit 4e4a0a3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,22 +12,23 @@ 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
GITHUB_PAT:
required: true

jobs:
run-task:
name: Run ECS task
setup-runners:
runs-on: ubuntu-latest
steps:
- name: Generate runner token
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
10 changes: 8 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ variable "desired_count" {
default = null
}

variable "timeout" {
type = string
default = null
}

locals {
availability_zone = "eu-central-1a"
}
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions run_task/main.tf → setup-runners/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ variable "desired_count" {
type = number
}

variable "timeout" {
type = string
}

data "aws_ecs_cluster" "this" {
cluster_name = "github-actions-runner"
}
Expand Down Expand Up @@ -76,6 +80,10 @@ data "aws_ecs_task_execution" "this" {
key = "START_DOCKER_SERVICE"
value = true
}
environment {
key = "TIMEOUT"
value = var.timeout
}
}
}
}
Expand Down

0 comments on commit 4e4a0a3

Please sign in to comment.