Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
Signed-off-by: Huamin Chen <[email protected]>
  • Loading branch information
rootfs committed Dec 12, 2023
1 parent 9d848fc commit ead70c4
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 57 deletions.
4 changes: 2 additions & 2 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Repository CODEOWNERS

* @actions/actions-runtime
* @ncalteen
* @sustainable-computing-io/kepler-action-team

147 changes: 92 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
# Hello, World! Docker Action
# AWS Self Hosted Runner Github Action

[![GitHub Super-Linter](https://github.com/actions/hello-world-docker-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/actions/hello-world-docker-action/actions/workflows/ci.yml/badge.svg)

This action prints `Hello, World!` or `Hello, <who-to-greet>!` to the log. To
learn how this action was built, see
[Creating a Docker container action](https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action).

## Create Your Own Action

To create your own action, you can use this repository as a template! Just
follow the below instructions:

1. Click the **Use this template** button at the top of the repository
1. Select **Create a new repository**
1. Select an owner and name for your new repository
1. Click **Create repository**
1. Clone your new repository

> [!CAUTION]
>
> Make sure to remove or update the [`CODEOWNERS`](./CODEOWNERS) file! For
> details on how to use this file, see
> [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners).
[![GitHub Super-Linter](https://github.com/sustainable-computing-io/aws_ec2_self_hosted_runner/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/sustainable-computing-io/aws_ec2_self_hosted_runner/actions/workflows/ci.yml/badge.svg)

## Usage

Expand All @@ -34,43 +13,106 @@ name: Example Workflow
on:
workflow_dispatch:
inputs:
who-to-greet:
description: Who to greet in the log
required: true
default: 'World'
type: string

ami_id:
description: 'AWS Machine Image ID'
required: false
default: 'ami-0e4d0bb9670ea8db0'
instance_type:
description: 'AWS EC2 Instance Type'
required: false
default: 't2.micro'
need_s3_bucket:
description: 'Need S3 bucket?'
required: false
default: 'false'
jobs:
say-hello:
name: Say Hello
setup-runner:
name: setup self hosted runner
runs-on: ubuntu-latest

steps:
# Change @main to a specific commit SHA or version tag, e.g.:
# actions/hello-world-docker-action@e76147da8e5c81eaf017dede5645551d4b94427b
# actions/[email protected]
- name: Print to Log
id: print-to-log
uses: actions/hello-world-docker-action@main
- name: setup runner
uses: sustainable-computing-io/aws_ec2_self_hosted_runner@main
with:
who-to-greet: ${{ inputs.who-to-greet }}
ACTION: "create"
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SECURITY_GROUP_ID: ${{ secrets.AWS_SECURITY_GROUP_ID }}
GITHUB_REPO: ${{ github.repository }}
AMI_ID: ${{ github.event.inputs.ami_id }}
INSTANCE_TYPE: ${{ github.event.inputs.instance_type }
CREATE_S3_BUCKET: ${{ github.event.inputs.need_s3_bucket }}

run-tests:
needs: setup-runner
name: run tests
runs-on: [self-hosted, linux, x64]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run Tests
run: |
export INSTANCE_ID=${{ needs.setup-runner.outputs.instance_id }}
echo "Running tests on self-hosted runner with instance $INSTANCE_ID"
uname -a # or any other command
destroy-runner:
if: always()
needs: [setup-runner, run-tests]
runs-on: ubuntu-latest
steps:
- name: Unregister runner
uses: sustainable-computing-io/aws_ec2_self_hosted_runner@main
with:
ACTION: "unregister"
env:
RUNNER_NAME: ${{ needs.setup-runner.outputs.runner_name }}
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
- name: Terminate instance
uses: sustainable-computing-io/aws_ec2_self_hosted_runner@main
with:
ACTION: "terminate"
env:
INSTANCE_ID: ${{ needs.setup-runner.outputs.instance_id }}
AWS_REGION: ${{ secrets.AWS_REGION }}
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
BUCKET_NAME: ${{ needs.setup-runner.outputs.bucket_name }}
```
For example workflow runs, check out the
[Actions tab](https://github.com/actions/hello-world-docker-action/actions)!
:rocket:
## Inputs
| Input | Default | Description |
| -------------- | ------- | ------------------------------- |
| `who-to-greet` | `World` | The name of the person to greet |
| Parameter | Description | Default Value |
|----------------------|-------------------------------------------------------------------------------------------------------|------------------------------------------|
| AMI_ID | The ID of the Amazon Machine Image (AMI) to use for the instance. | "ami-0e4d0bb9670ea8db0" (Ubuntu Server 20.04 LTS) |
| INSTANCE_TYPE | The type of the instance to launch. | "t2.micro" |
| SECURITY_GROUP_ID | The ID of the security group to associate with the instance. | Replace "YOUR_SECURITY_GROUP_ID" with the actual security group ID. |
| GITHUB_TOKEN | The GitHub token to authenticate with the GitHub API. Must have repo admin permission. | Replace "YOUR_TOKEN" with the actual GitHub token. |
| GITHUB_REPO | The GitHub repository in the format "owner/repo" to clone and use. | "sustainable-computing-io/kepler-model-server" |
| REGION | The AWS region to launch the spot instance. | "us-east-2" |
| DEBUG | Enable or disable debug mode. | "false" |
| KEY_NAME | The name of the key pair to use for the instance. | Replace "YOUR_KEY_NAME" with the actual key pair name. |
| GITHUB_OUTPUT | The name of the file to output the instance ID to. ***This is only for local test use. Don't set it in the workflow file.*** | "github_output.txt" |
| ROOT_VOLUME_SIZE | The size of the root volume in GB. | 200 |
| SPOT_INASTANCE_ONLY | If true, only create a spot instance. | "true" |
| CREATE_S3_BUCKET | If true, create a S3 bucket to store the model. | "false" |
| BUCKET_NAME | The name of the S3 bucket to store the model. | The bucket name is the same as the repo name with time date stamp. |
## Outputs
| Output | Description |
| ------ | ----------------------- |
| `time` | The time we greeted you |
| `instance_id` | AWS EC2 instance ID |
| `runner_name` | Github self hosted runner name |
| `instance_ip` | AWS EC2 instance IP |
| `bucket_name` | AWS S3 bucket name |

## Test Locally

Expand All @@ -85,27 +127,22 @@ need to perform some initial setup steps before you can test your action.

1. :hammer_and_wrench: Build the container

Make sure to replace `actions/hello-world-docker-action` with an appropriate
Make sure to replace `actions/aws_ec2_self_hosted_runner` with an appropriate
label for your container.

```bash
docker build -t actions/hello-world-docker-action .
docker build -t actions/aws_ec2_self_hosted_runner .
```

1. :white_check_mark: Test the container

You can pass individual environment variables using the `--env` or `-e` flag.

```bash
$ docker run --env INPUT_WHO_TO_GREET="Mona Lisa Octocat" actions/hello-world-docker-action
::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat!
```

Or you can pass a file with environment variables using `--env-file`.

```bash
$ echo "INPUT_WHO_TO_GREET=\"Mona Lisa Octocat\"" > ./.env.test
$ docker run --env-file ./.env.test actions/hello-world-docker-action
::notice file=entrypoint.sh,line=7::Hello, Mona Lisa Octocat!
```

0 comments on commit ead70c4

Please sign in to comment.