Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] update CI to keep same with github action template #6

Merged
merged 8 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# shellcheck disable=SC1000-SC9999
name: Continuous Integration

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

jobs:
test-docker:
name: Docker Tests
runs-on: ubuntu-latest

# Run a local registry to push to
services:
registry:
image: registry:2
ports:
- 5001:5000

env:
TEST_TAG: localhost:5001/sustainable_computing_io/aws_ec2_self_hosted_runner:latest

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Setup Docker BuildX
id: setup-buildx
uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: network=host

- name: Build the Container
id: build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.TEST_TAG }}


setup-runner:
name: GitHub Actions Test create instance
runs-on: ubuntu-latest
outputs:
instance_id: ${{ steps.create-runner.outputs.instance_id }}
runner_name: ${{ steps.create-runner.outputs.runner_name }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test Local Action
id: create-runner
uses: ./
with:
action: "create"
aws_region: ${{ secrets.AWS_REGION }}
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_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: "ami-0e4d0bb9670ea8db0"
instance_type: "t2.micro"
create_s3_bucket: "false"
spot_instance_only: "true"

- name: Print Output
id: output
run: |
echo "instance_id ${{ steps.create-runner.outputs.instance_id }}"
echo "instance_ip ${{ steps.create-runner.outputs.instance_ip }}"
echo "runner_name ${{ steps.create-runner.outputs.runner_name }}"
echo "bucket_name ${{ steps.create-runner.outputs.bucket_name }}"

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

- 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
cat /etc/os-release
cat /proc/cpuinfo

destroy-runner:
if: always()
name: GitHub Actions Test destroy instance
needs: [setup-runner, test-runner]
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: unregister runner
id: unregister
uses: ./
with:
action: "unregister"
runner_name: ${{ needs.setup-runner.outputs.runner_name }}
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
github_repo: ${{ github.repository }}

- name: terminate instance
id: terminate
uses: ./
with:
action: "terminate"
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
instance_id: ${{ needs.setup-runner.outputs.instance_id }}

31 changes: 31 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: imagebuild

on:
push:
branches:
- main

permissions:
contents: read

jobs:
image_build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Login to Quay
uses: docker/login-action@v3
with:
registry: quay.io/sustainable_computing_io
username: ${{ secrets.username }}
password: ${{ secrets.password }}
- name: Build and push the container
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: true
tags: quay.io/sustainable_computing_io/aws_ec2_self_hosted_runner:latest
labels: latest
file: Dockerfile
159 changes: 0 additions & 159 deletions .github/workflows/pr.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
echo "instance_id ${{ steps.create-runner.outputs.instance_id }}"
echo "instance_ip ${{ steps.create-runner.outputs.instance_ip }}"
echo "runner_name ${{ steps.create-runner.outputs.runner_name }}"
echo "bucket_name ${{ steps.create-runner.outputs.bucket_name }}"

test-runner:
needs: setup-runner
Expand Down
12 changes: 7 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ inputs:
required: true
github_token:
description: 'The GitHub token to use'
required: true
required: false
aws_access_key_id:
description: 'The AWS access key id to use'
required: true
required: false
aws_secret_access_key:
description: 'The AWS secret access key to use'
required: true
required: false
security_group_id:
description: 'The AWS security group id to use'
required: true
required: false
aws_region:
description: 'The AWS region to use'
required: false
Expand Down Expand Up @@ -55,8 +55,10 @@ inputs:

# Define your outputs here.
outputs:
instane_id:
instance_id:
description: The AWS EC2 instance id
instance_ip:
description: The AWS EC2 instance ip
runner_name:
description: The name of the self hosted runner
bucket_name:
Expand Down