Skip to content

Commit

Permalink
feat: add enough configuration to use self-hosted runners
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Aug 20, 2024
1 parent 5765f2b commit 53c7410
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,47 @@ on:
SSH_PRIVATE_KEY:
description: 'Service user SSH key for repository checkout'
required: true
GH_PERSONAL_ACCESS_TOKEN:
description: 'GitHub personal access token'
required: true
AWS_ACCESS_KEY_ID:
description: 'AWS access key ID'
required: true
AWS_SECRET_ACCESS_KEY:
description: 'AWS secret access key'
required: true
AWS_REGION:
description: 'AWS region'
required: true

jobs:
build:
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: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Start EC2 runner
id: start-ec2-runner
uses: machulav/ec2-github-runner@v2
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
ec2-image-id: ami-06298721653b69e45
ec2-instance-type: m6i.2xlarge
subnet-id: subnet-08912dcec955b1bd9
security-group-id: sg-0d76181fdee037a27
build:
name: Build service image
needs: start-runner
runs-on: ${{ needs.start-runner.outputs.label }}

steps:
- name: Login to DockerHub
Expand Down Expand Up @@ -169,3 +206,25 @@ jobs:
run: |
. .tvm/bin/activate
tutor images push $SERVICE
stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner # required to get output from the start-runner job
- build # required to wait when the main job is done
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Stop EC2 runner
uses: machulav/ec2-github-runner@v2
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}

0 comments on commit 53c7410

Please sign in to comment.