Skip to content

Commit 82cd501

Browse files
authored
Merge pull request #13 from sustainable-computing-io/amiMetric
[CI] Enhance with AMI ID, fix for #11
2 parents feb6371 + 3990215 commit 82cd501

File tree

2 files changed

+152
-113
lines changed

2 files changed

+152
-113
lines changed

.github/workflows/ci.yml

Lines changed: 51 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# shellcheck disable=SC1000-SC9999
2-
name: Continuous Integration
2+
name: Continuous Integration Entry
33

44
on:
55
pull_request:
@@ -12,115 +12,53 @@ permissions:
1212

1313
jobs:
1414
test-docker:
15-
name: Docker Tests
16-
runs-on: ubuntu-latest
17-
18-
# Run a local registry to push to
19-
services:
20-
registry:
21-
image: registry:2
22-
ports:
23-
- 5001:5000
24-
25-
env:
26-
TEST_TAG: localhost:5001/sustainable_computing_io/aws_ec2_self_hosted_runner:latest
27-
28-
steps:
29-
- name: Checkout
30-
id: checkout
31-
uses: actions/checkout@v4
32-
33-
- name: Setup Docker BuildX
34-
id: setup-buildx
35-
uses: docker/setup-buildx-action@v3
36-
with:
37-
install: true
38-
driver-opts: network=host
39-
40-
- name: Build the Container
41-
id: build
42-
uses: docker/build-push-action@v5
43-
with:
44-
context: .
45-
push: true
46-
tags: ${{ env.TEST_TAG }}
47-
48-
49-
setup-runner:
50-
name: GitHub Actions Test create instance
51-
runs-on: ubuntu-latest
52-
outputs:
53-
instance_id: ${{ steps.create-runner.outputs.instance_id }}
54-
runner_name: ${{ steps.create-runner.outputs.runner_name }}
55-
steps:
56-
- name: Checkout
57-
id: checkout
58-
uses: actions/checkout@v4
59-
60-
- name: Test Local Action
61-
id: create-runner
62-
uses: ./
63-
with:
64-
action: "create"
65-
aws_region: ${{ secrets.AWS_REGION }}
66-
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
67-
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
68-
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
69-
security_group_id: ${{ secrets.AWS_SECURITY_GROUP_ID }}
70-
github_repo: ${{ github.repository }}
71-
ami_id: "ami-0e4d0bb9670ea8db0"
72-
instance_type: "t2.micro"
73-
create_s3_bucket: "false"
74-
spot_instance_only: "true"
75-
76-
- name: Print Output
77-
id: output
78-
run: |
79-
echo "instance_id ${{ steps.create-runner.outputs.instance_id }}"
80-
echo "instance_ip ${{ steps.create-runner.outputs.instance_ip }}"
81-
echo "runner_name ${{ steps.create-runner.outputs.runner_name }}"
82-
echo "bucket_name ${{ steps.create-runner.outputs.bucket_name }}"
83-
84-
test-runner:
85-
needs: setup-runner
86-
runs-on: [self-hosted, linux, x64]
87-
steps:
88-
- name: Checkout
89-
uses: actions/checkout@v4
90-
91-
- name: Run Tests
92-
run: |
93-
export INSTANCE_ID="${{ needs.setup-runner.outputs.instance_id }}"
94-
echo "Running tests on self-hosted runner with instance ${INSTANCE_ID}"
95-
uname -a # or any other command
96-
cat /etc/os-release
97-
cat /proc/cpuinfo
98-
99-
destroy-runner:
100-
if: always()
101-
name: GitHub Actions Test destroy instance
102-
needs: [setup-runner, test-runner]
103-
runs-on: ubuntu-latest
104-
steps:
105-
- name: Checkout
106-
id: checkout
107-
uses: actions/checkout@v4
108-
109-
- name: unregister runner
110-
id: unregister
111-
uses: ./
112-
with:
113-
action: "unregister"
114-
runner_name: ${{ needs.setup-runner.outputs.runner_name }}
115-
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
116-
github_repo: ${{ github.repository }}
117-
118-
- name: terminate instance
119-
id: terminate
120-
uses: ./
121-
with:
122-
action: "terminate"
123-
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
124-
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
125-
instance_id: ${{ needs.setup-runner.outputs.instance_id }}
126-
15+
name: Docker Tests
16+
runs-on: ubuntu-latest
17+
18+
# Run a local registry to push to
19+
services:
20+
registry:
21+
image: registry:2
22+
ports:
23+
- 5001:5000
24+
25+
env:
26+
TEST_TAG: localhost:5001/sustainable_computing_io/aws_ec2_self_hosted_runner:latest
27+
28+
steps:
29+
- name: Checkout
30+
id: checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Docker BuildX
34+
id: setup-buildx
35+
uses: docker/setup-buildx-action@v3
36+
with:
37+
install: true
38+
driver-opts: network=host
39+
40+
- name: Build the Container
41+
id: build
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
push: true
46+
tags: ${{ env.TEST_TAG }}
47+
48+
unitpreOS:
49+
strategy:
50+
matrix:
51+
# us-east-2
52+
# Ubuntu 20.04 AMI is ami-0e4d0bb9670ea8db0
53+
# ubuntu 22.04 AMI is ami-05fb0b8c1424f266b
54+
# RHEL 9 AMI is ami-078cbc4c2d057c244
55+
AMI_ID: [ami-0e4d0bb9670ea8db0,ami-05fb0b8c1424f266b,ami-078cbc4c2d057c244]
56+
uses: ./.github/workflows/ci_unit.yml
57+
secrets:
58+
AWS_REGION: ${{ secrets.AWS_REGION }}
59+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
60+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
61+
GH_SELF_HOSTED_RUNNER_TOKEN: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
62+
AWS_SECURITY_GROUP_ID: ${{ secrets.AWS_SECURITY_GROUP_ID }}
63+
AMI_ID: ${{matrix.AMI_ID}}
64+

.github/workflows/ci_unit.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# shellcheck disable=SC1000-SC9999
2+
name: Continuous Integration
3+
4+
on:
5+
workflow_call:
6+
secrets:
7+
AWS_REGION:
8+
required: true
9+
AWS_ACCESS_KEY_ID:
10+
required: true
11+
AWS_SECRET_ACCESS_KEY:
12+
required: true
13+
AWS_SECURITY_GROUP_ID:
14+
required: true
15+
AMI_ID:
16+
required: true
17+
GH_SELF_HOSTED_RUNNER_TOKEN:
18+
required: true
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
setup-runner:
25+
name: GitHub Actions Test create instance
26+
runs-on: ubuntu-latest
27+
outputs:
28+
instance_id: ${{ steps.create-runner.outputs.instance_id }}
29+
runner_name: ${{ steps.create-runner.outputs.runner_name }}
30+
steps:
31+
- name: Checkout
32+
id: checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Test Local Action
36+
id: create-runner
37+
uses: ./
38+
with:
39+
action: "create"
40+
aws_region: ${{ secrets.AWS_REGION }}
41+
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
42+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
43+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44+
security_group_id: ${{ secrets.AWS_SECURITY_GROUP_ID }}
45+
github_repo: ${{ github.repository }}
46+
ami_id: ${{ secrets.AMI_ID }}
47+
instance_type: "t2.micro"
48+
create_s3_bucket: "false"
49+
spot_instance_only: "true"
50+
51+
- name: Print Output
52+
id: output
53+
run: |
54+
echo "instance_id ${{ steps.create-runner.outputs.instance_id }}"
55+
echo "instance_ip ${{ steps.create-runner.outputs.instance_ip }}"
56+
echo "runner_name ${{ steps.create-runner.outputs.runner_name }}"
57+
echo "bucket_name ${{ steps.create-runner.outputs.bucket_name }}"
58+
59+
test-runner:
60+
needs: setup-runner
61+
runs-on: [self-hosted, linux, x64]
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
66+
- name: Run Tests
67+
run: |
68+
export INSTANCE_ID="${{ needs.setup-runner.outputs.instance_id }}"
69+
echo "Running tests on self-hosted runner with instance ${INSTANCE_ID}"
70+
uname -a # or any other command
71+
cat /etc/os-release
72+
cat /proc/cpuinfo
73+
74+
destroy-runner:
75+
if: always()
76+
name: GitHub Actions Test destroy instance
77+
needs: [setup-runner, test-runner]
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Checkout
81+
id: checkout
82+
uses: actions/checkout@v4
83+
84+
- name: unregister runner
85+
id: unregister
86+
uses: ./
87+
with:
88+
action: "unregister"
89+
runner_name: ${{ needs.setup-runner.outputs.runner_name }}
90+
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
91+
github_repo: ${{ github.repository }}
92+
93+
- name: terminate instance
94+
id: terminate
95+
uses: ./
96+
with:
97+
action: "terminate"
98+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
99+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
100+
instance_id: ${{ needs.setup-runner.outputs.instance_id }}
101+

0 commit comments

Comments
 (0)