Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/lambdas/aws-64f7ae5156
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm authored Oct 2, 2024
2 parents ffe859f + fd2d0c6 commit b22d709
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lambda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
working-directory: ./lambdas

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run prettier
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/packer-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
working-directory: images/${{ matrix.image }}
steps:
- name: "Checkout"
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: packer init
run: packer init .
- name: check packer formatting
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: 20
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Build dist
working-directory: lambdas
run: yarn install --frozen-lockfile && yarn run test && yarn dist
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/semantic-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Semantic Commit Message Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5.5.3
name: Check PR for Semantic Commit Message
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
image: hashicorp/terraform:${{ matrix.terraform }}
steps:
- name: "Checkout"
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: "Fake zip files" # Validate will fail if it cannot find the zip files
run: |
touch lambdas/functions/webhook/webhook.zip
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
container:
image: hashicorp/terraform:${{ matrix.terraform }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: terraform init
run: terraform init -get -backend=false -input=false
- if: contains(matrix.terraform, '1.3.')
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
container:
image: hashicorp/terraform:${{ matrix.terraform }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: terraform init
run: terraform init -get -backend=false -input=false
- if: contains(matrix.terraform, '1.5.')
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/update-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout with GITHUB Action token
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}

# use an app to ensure CI is triggered
- name: Generate TF docs
if: github.repository_owner == 'philips-labs'
uses: terraform-docs/gh-actions@cca78c27ac9e2b6545debf2ecae9df930fd3461c # v1.2.2
uses: terraform-docs/gh-actions@aeae0038ed47a547e0c0fca5c059d3335f48fb25 # v1.3.0
with:
find-dir: .
git-commit-message: "docs: auto update terraform docs"
Expand All @@ -33,7 +33,7 @@ jobs:

- name: Generate TF docs (forks)
if: github.repository_owner != 'philips-labs'
uses: terraform-docs/gh-actions@cca78c27ac9e2b6545debf2ecae9df930fd3461c # v1.2.2
uses: terraform-docs/gh-actions@aeae0038ed47a547e0c0fca5c059d3335f48fb25 # v1.3.0
with:
find-dir: .
git-commit-message: "docs: auto update terraform docs"
Expand All @@ -56,7 +56,7 @@ jobs:
needs: [docs]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
Expand Down
46 changes: 23 additions & 23 deletions README.md

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A pertinent question may arise: why not opt for Kubernetes? The current strategy

## Overview

The module is designed to be used in a GitHub organization. It can also be used in a GitHub repository, but this not supports all features. The module is receiving GitHub webhook events for the `workflow_job` event. The module will create a new runner if the event is for a workflow that requires a runner, and no runner is available. Alteratively the module can be configured as ephemeral runners. In this case the module will create a new runner for each workflow job event.
The module is designed to be used in a GitHub organization. It can also be used in a GitHub repository, but this does not supports all features. The module is receiving GitHub webhook events for the `workflow_job` event. The module will create a new runner if the event is for a workflow that requires a runner, and no runner is available. Alternatively the module can be configured as ephemeral runners. In this case the module will create a new runner for each workflow job event.

For ephemeral runners a pool is can be configured. The pool maintains a minimum number of runners based on a schedule. The pool works only for org level runners.

Expand Down Expand Up @@ -46,7 +46,7 @@ The "Scale Up Runner" Lambda actively monitors the SQS queue, processing incomin

The Lambda first requests a JIT configuration or registration token from GitHub, which is needed later by the runner to register itself. This avoids the case that the EC2 instance, which later in the process will install the agent, needs administration permissions to register the runner. Next, the EC2 spot instance is created via the launch template. The launch template defines the specifications of the required instance and contains a [`user_data`](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) script. This script will install the required software and configure it. The configuration for the runner is shared via EC2 tags and the parameter store (SSM), from which the user data script will fetch it and delete it once it has been retrieved. Once the user data script is finished, the action runner should be online, and the workflow will start in seconds.

The current method for scaling down runners employs a straightforward approach: at predefined intervals, the Lambda conducts a thorough examination of each runner (instance) to assess its activity. If a runner is found to be idle, it is deregistered from GitHub, and the associated AWS instance is terminated. For ephemeral runners the the instance is terminated immediately after the workflow is finished. Instances not registered in GitHub as a runner after a minimal boot time will be marked orphan and removed in a next cycle. To avoid orphaned runners the scale down lambda is active in this cae as well.
The current method for scaling down runners employs a straightforward approach: at predefined intervals, the Lambda conducts a thorough examination of each runner (instance) to assess its activity. If a runner is found to be idle, it is deregistered from GitHub, and the associated AWS instance is terminated. For ephemeral runners the instance is terminated immediately after the workflow is finished. Instances not registered in GitHub as a runner after a minimal boot time will be marked orphan and removed in a next cycle. To avoid orphaned runners the scale down lambda is active in this case as well.

### Pool

Expand Down Expand Up @@ -79,18 +79,19 @@ The Instance Termination Watcher is creating log and optional metrics for termin

This feature is Beta, changes will not trigger a major release as long in beta.

The Job Retry will allow you to retry scaling when a job is not started. When enabled the scale up lambda will send a retry message to the a SQS queue. The job retry lambda will check after a delay if the job is still queued. And if so it will send a retry command de the scale up lambda via SQS. The feature is designed to be used with ephemeral runners. The feature is opt in, it will not be created by default.
The Job Retry will allow you to retry scaling when a job is not started. When enabled the scale up lambda will send a retry message to the a SQS queue. The Job Retry lambda will check after a delay if the job is still queued, and if so, it will send a retry command to the scale up lambda via SQS. The feature is designed to be used with ephemeral runners. The feature is opt in, it will not be created by default.

Consequences of enabling the feature are:

- Increase of calls to the GitHub API, could cause reaching the rate limit.
- Could create new instance when job are not started caused by other failures, resulting in more costs and useless instance creation.
- Could create new instance when jobs are not started caused by other failures, resulting in more costs and useless instance creation.


### Security

Sensitive information such as secrets and private keys is stored securely in the SSM Parameter Store. These values undergo encryption using either the default KMS key for SSM or a custom KMS key, depending on the specified configuration.
Sensitive information such as secrets and private keys are stored securely in the SSM Parameter Store. These values undergo encryption using either the default KMS key for SSM or a custom KMS key, depending on the specified configuration.

Permission are managed in several places. Below are the most important ones. For details check the Terraform sources.
Permissions are managed in several places. Below are the most important ones. For details check the Terraform sources.

- The GitHub App requires access to actions and to publish `workflow_job` events to the AWS webhook (API gateway).
- The scale up lambda should have access to EC2 for creating and tagging instances.
Expand All @@ -112,5 +113,5 @@ Both modules are built on top of the same base modules. When using the multi-run
The module contains a lot of configuration options. The default values are a good starting point. But you may want to tweak some of the values. Below are some recommendations. We suggest the following configuration for the runners:

- Use the multi-runner module to create multiple runners in one go.
- Use the ephemeral runners for org level runners. To improve the security of your runners.
- Use the ephemeral runners for org level runners to improve the security of your runners.
- Use pre-built AMIs to speed up the startup of your runners.
2 changes: 1 addition & 1 deletion examples/arm64/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ terraform output -raw webhook_secret

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub App for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub App for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ terraform output -raw webhook_secret
|------|-------------|------|---------|:--------:|
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | `"eu-west-1"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Environment name, used as prefix. | `string` | `null` | no |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion examples/ephemeral/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ terraform output webhook_secret
|------|-------------|------|---------|:--------:|
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region. | `string` | `"eu-west-1"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Environment name, used as prefix | `string` | `null` | no |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion examples/multi-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ terraform output -raw webhook_secret
|------|-------------|------|---------|:--------:|
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region to deploy to | `string` | `"eu-west-1"` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Environment name, used as prefix | `string` | `null` | no |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion examples/permissions-boundary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ terraform apply

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion examples/prebuilt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ terraform output webhook_secret
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_ami_name_filter"></a> [ami\_name\_filter](#input\_ami\_name\_filter) | AMI name filter for the action runner AMI. By default amazon linux 2 is used. | `string` | `"github-runner-al2023-x86_64-*"` | no |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |
| <a name="input_runner_os"></a> [runner\_os](#input\_runner\_os) | The EC2 Operating System type to use for action runner instances (linux,windows). | `string` | `"linux"` | no |

## Outputs
Expand Down
2 changes: 1 addition & 1 deletion examples/ubuntu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ terraform output webhook_secret

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion examples/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ terraform output webhook_secret

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br> id = string<br> key_base64 = string<br> })</pre> | n/a | yes |
| <a name="input_github_app"></a> [github\_app](#input\_github\_app) | GitHub for API usages. | <pre>object({<br/> id = string<br/> key_base64 = string<br/> })</pre> | n/a | yes |

## Outputs

Expand Down
2 changes: 1 addition & 1 deletion lambdas/functions/control-plane/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@octokit/core": "5.2.0",
"@octokit/plugin-throttling": "8.2.0",
"@octokit/rest": "20.1.1",
"@octokit/types": "^13.5.0",
"@octokit/types": "^13.6.0",
"cron-parser": "^4.9.0",
"typescript": "^5.5.4"
},
Expand Down
2 changes: 1 addition & 1 deletion lambdas/functions/gh-agent-syncer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@aws-sdk/types": "^3.654.0",
"@middy/core": "^4.7.0",
"@octokit/rest": "20.1.1",
"axios": "^1.7.5"
"axios": "^1.7.7"
},
"nx": {
"includedScripts": [
Expand Down
2 changes: 1 addition & 1 deletion lambdas/functions/webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@aws-sdk/client-sqs": "^3.658.1",
"@middy/core": "^4.7.0",
"@octokit/rest": "20.1.1",
"@octokit/types": "^13.5.0",
"@octokit/types": "^13.6.0",
"@octokit/webhooks": "^12.2.0",
"aws-lambda": "^1.0.7"
},
Expand Down
19 changes: 15 additions & 4 deletions lambdas/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ __metadata:
"@octokit/core": "npm:5.2.0"
"@octokit/plugin-throttling": "npm:8.2.0"
"@octokit/rest": "npm:20.1.1"
"@octokit/types": "npm:^13.5.0"
"@octokit/types": "npm:^13.6.0"
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
"@types/aws-lambda": "npm:^8.10.143"
"@types/jest": "npm:^29.5.12"
Expand Down Expand Up @@ -250,7 +250,7 @@ __metadata:
"@vercel/ncc": "npm:^0.38.1"
aws-sdk-client-mock: "npm:^4.0.2"
aws-sdk-client-mock-jest: "npm:^4.0.1"
axios: "npm:^1.7.5"
axios: "npm:^1.7.7"
eslint: "npm:^8.57.0"
eslint-plugin-prettier: "npm:5.2.1"
jest: "npm:^29.7.0"
Expand Down Expand Up @@ -302,7 +302,7 @@ __metadata:
"@aws-sdk/client-sqs": "npm:^3.658.1"
"@middy/core": "npm:^4.7.0"
"@octokit/rest": "npm:20.1.1"
"@octokit/types": "npm:^13.5.0"
"@octokit/types": "npm:^13.6.0"
"@octokit/webhooks": "npm:^12.2.0"
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
"@types/aws-lambda": "npm:^8.10.143"
Expand Down Expand Up @@ -6044,7 +6044,7 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.7.2, axios@npm:^1.7.4, axios@npm:^1.7.5":
"axios@npm:^1.7.2, axios@npm:^1.7.4":
version: 1.7.5
resolution: "axios@npm:1.7.5"
dependencies:
Expand All @@ -6055,6 +6055,17 @@ __metadata:
languageName: node
linkType: hard

"axios@npm:^1.7.7":
version: 1.7.7
resolution: "axios@npm:1.7.7"
dependencies:
follow-redirects: "npm:^1.15.6"
form-data: "npm:^4.0.0"
proxy-from-env: "npm:^1.1.0"
checksum: 10c0/4499efc89e86b0b49ffddc018798de05fab26e3bf57913818266be73279a6418c3ce8f9e934c7d2d707ab8c095e837fc6c90608fb7715b94d357720b5f568af7
languageName: node
linkType: hard

"babel-jest@npm:^29.7.0":
version: 29.7.0
resolution: "babel-jest@npm:29.7.0"
Expand Down
Loading

0 comments on commit b22d709

Please sign in to comment.