Skip to content

Commit ed26d8d

Browse files
committed
CI: enhance with AMI ID, fix for #11
Signed-off-by: Sam Yuan <[email protected]>
1 parent feb6371 commit ed26d8d

File tree

2 files changed

+151
-114
lines changed

2 files changed

+151
-114
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 114 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:
@@ -11,116 +11,19 @@ permissions:
1111
contents: read
1212

1313
jobs:
14-
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-
14+
unitpreOS:
15+
strategy:
16+
matrix:
17+
# us-east-2
18+
# Ubuntu 20.04 AMI is ami-0e4d0bb9670ea8db0
19+
# ubuntu 22.04 AMI is ami-05fb0b8c1424f266b
20+
# RHEL 9 AMI is ami-078cbc4c2d057c244
21+
AMI_ID: [ami-0e4d0bb9670ea8db0,ami-05fb0b8c1424f266b,ami-078cbc4c2d057c244]
22+
uses: ./.github/workflows/ci_unit.yml
23+
secrets:
24+
AWS_REGION: ${{ secrets.AWS_REGION }}
25+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
26+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27+
GH_SELF_HOSTED_RUNNER_TOKEN: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
28+
AMI_ID: ${{matrix.AMI_ID}}
29+

.github/workflows/ci_unit.yml

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

0 commit comments

Comments
 (0)