Skip to content

Commit

Permalink
feat(config): handle slab profile as input
Browse files Browse the repository at this point in the history
  • Loading branch information
soonum committed Jan 29, 2024
1 parent 67eeef5 commit f646bcc
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 71 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,25 @@ jobs:
job-secret: ${{ secrets.JOB_SECRET }}
region: eu-west-3
label: ${{ steps.test-start.outputs.label }}
ec2-instance-id: ${{ steps.test-start.outputs.ec2-instance-id }}

- name: Test start instance with profile
id: test-start-profile
uses: ./
with:
mode: start
github-token: ${{ secrets.SLAB_ACTION_TOKEN }}
slab-url: ${{ secrets.SLAB_BASE_URL }}
job-secret: ${{ secrets.JOB_SECRET }}
profile: ci-test

- name: Test stop instance with profile
id: test-stop-profile
if: ${{ always() }}
uses: ./
with:
mode: stop
github-token: ${{ secrets.SLAB_ACTION_TOKEN }}
slab-url: ${{ secrets.SLAB_BASE_URL }}
job-secret: ${{ secrets.JOB_SECRET }}
profile: ci-test
label: ${{ steps.test-start-profile.outputs.label }}
71 changes: 56 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ See [below](#example) the YAML code of the depicted workflow.

### Inputs

| Name | Required | Description |
|----------------------|--------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | Always required. | Specify here which mode you want to use: `start` to start a new runner, `stop` to stop the previously created runner. |
| `github-token` | Always required. | GitHub Personal Access Token with the `repo` scope assigned. |
| `slab-url` | Always required. | URL to Slab CI server. |
| `job-secret` | Always required. | Secret key used by Slab to perform HMAC computation. |
| `region` | Always required. | AWS deploy region. |
| `ec2-image-id` | Required if you use the `start` mode. | EC2 Image ID (AMI).The new runner will be launched from this image. The action is compatible with Amazon Linux 2 images. |
| `ec2-instance-type` | Required if you use the `start` mode. | EC2 Instance Type. |
| `subnet-id` | Optional. Used only with the `start` mode. | VPC Subnet ID.The subnet should belong to the same VPC as the specified security group. |
| `security-group-ids` | Optional. Used only with the `start` mode. | EC2 Security Group IDs.The security group should belong to the same VPC as the specified subnet.Only the outbound traffic for port 443 should be allowed. No inbound traffic is required. |
| `label` | Required if you use the `stop` mode. | Name of the unique label assigned to the runner.The label is provided by the output of the action in the `start` mode.The label is used to remove the runner from GitHub when the runner is not needed anymore. |
| `ec2-instance-id` | Required if you use the `stop` mode. | EC2 Instance ID of the created runner.The ID is provided by the output of the action in the `start` mode.The ID is used to terminate the EC2 instance when the runner is not needed anymore. | |
| Name | Required | Description |
|----------------------|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | Always required. | Specify here which mode you want to use: `start` to start a new runner, `stop` to stop the previously created runner. |
| `github-token` | Always required. | GitHub Personal Access Token with the `repo` scope assigned. |
| `slab-url` | Always required. | URL to Slab CI server. |
| `job-secret` | Always required. | Secret key used by Slab to perform HMAC computation. |
| `profile` | Optional. | Profile to use as described slab.toml file in repository that uses the action. |
| `region` | Required if you don't use `profile`. | AWS deploy region. |
| `ec2-image-id` | Required if you don't use `profile` with `start` mode. | EC2 Image ID (AMI).The new runner will be launched from this image. The action is compatible with Amazon Linux 2 images. |
| `ec2-instance-type` | Required if you don't use `profile` with `start` mode. | EC2 Instance Type. |
| `subnet-id` | Optional. Used only if you don't use `profile` with `start` mode. | VPC Subnet ID.The subnet should belong to the same VPC as the specified security group. |
| `security-group-ids` | Optional. Used only if you don't use `profile` with `start` mode. | EC2 Security Group IDs.The security group should belong to the same VPC as the specified subnet.Only the outbound traffic for port 443 should be allowed. No inbound traffic is required. |
| `label` | Required if you don't use `profile` with `stop` mode. | Name of the unique label assigned to the runner.The label is provided by the output of the action in the `start` mode.The label is used to remove the runner from GitHub when the runner is not needed anymore. |

### Outputs

Expand All @@ -42,7 +42,7 @@ See [below](#example) the YAML code of the depicted workflow.
| `label` | Name of the unique label assigned to the runner. The label is used in two cases: to use as the input of `runs-on` property for the following jobs and to remove the runner from GitHub when it is not needed anymore. |
| `ec2-instance-id` | EC2 Instance ID of the created runner.The ID is used to terminate the EC2 instance when the runner is not needed anymore. |

### Example
### Examples

The workflow showed in the picture above and declared in `do-the-job.yml` looks like this:

Expand Down Expand Up @@ -90,8 +90,49 @@ jobs:
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
region: eu-west-3
label: ${{ needs.start-runner.outputs.label }}
```
Here's the same workflow but using a profile declared in `ci/slab.toml` within the calling repository

```yml
name: do-the-job
on: pull_request
jobs:
start-runner:
name: Start self-hosted EC2 runner
runs-on: ubuntu-latest
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: Start EC2 runner
id: start-ec2-runner
uses: zama-ai/slab-github-runner@v1
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
profile: cpu-test
do-the-job:
# ... #
stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner # required to get output from the start-runner job
- do-the-job # required to wait when the main job is done
runs-on: ubuntu-latest
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
steps:
- name: Stop EC2 runner
uses: zama-ai/slab-github-runner@v1
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
profile: cpu-test
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
```

## License Summary
Expand Down
15 changes: 10 additions & 5 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,39 @@ inputs:
description: >-
Secret key used by Slab to perform HMAC computation.
required: true
profile:
description: >-
Profile to use as described slab.toml file in repository that uses the action.
required: false
region:
description: >-
AWS deployment region.
required: true
Mutually exclusive with 'profile' input.
required: false
ec2-image-id:
description: >-
EC2 Image Id (AMI). The new runner will be launched from this image.
This input is required if you use the 'start' mode.
Mutually exclusive with 'profile' input.
required: false
ec2-instance-type:
description: >-
EC2 Instance Type.
This input is required if you use the 'start' mode.
Mutually exclusive with 'profile' input.
required: false
subnet-id:
description: >-
VPC Subnet Id. The subnet should belong to the same VPC as the specified security group.
This input is required if you use the 'start' mode.
Mutually exclusive with 'profile' input.
required: false
security-group-ids:
description: >-
EC2 Security Group Ids.
The security group should belong to the same VPC as the specified subnet.
The runner doesn't require any inbound traffic. However, outbound traffic should be allowed.
Mutually exclusive with 'profile' input.
required: false
label:
description: >-
Expand All @@ -68,10 +77,6 @@ outputs:
The label is used in two cases:
- to use as the input of 'runs-on' property for the following jobs;
- to remove the runner from GitHub when it is not needed anymore.
ec2-instance-id:
description: >-
EC2 Instance Id of the created runner.
The id is used to terminate the EC2 instance when the runner is not needed anymore.
runs:
using: node20
main: ./dist/index.js
11 changes: 11 additions & 0 deletions ci/slab.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This profile is dedicated to test action behavior by replicating
#profiles that can be found on repository using this workflow.
[profile.ci-test]
region = "eu-west-3"
image_id = "ami-01d21b7be69801c2f" # Ubuntu 22.04
instance_type = "t3.2xlarge"

[command.placeholder]
workflow = "no-workflow.yml"
profile = "ci-test"
check_run_name = "Placeholder command to test slab action"
102 changes: 77 additions & 25 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f646bcc

Please sign in to comment.