Skip to content

train-model: Sentiment Analysis @ EC2 Spot #3

train-model: Sentiment Analysis @ EC2 Spot

train-model: Sentiment Analysis @ EC2 Spot #3

name: "train-model: Sentiment Analysis @ EC2 Spot"
on:
workflow_dispatch:
inputs:
aws_region:
description: 'AWS_REGION'
required: true
default: 'eu-west-2'
type: string
ami_id:
description: 'AMI_ID'
required: true
default: 'ami-093cb9fb2d34920ad'
type: string
ec2-instance-type:
description: 'AMI_ID'
required: true
default: 't3.nano'
type: string
jobs:
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: ${{ github.event.inputs.aws_region }}
- name: Start EC2 runner
id: start-ec2-runner
uses: digital-defiance/ec2-github-runner@v2
with:
mode: start
pre-runner-script: |
sudo yum update -y && \
sudo yum install docker git libicu -y
sudo systemctl enable docker
sudo systemctl start docker
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
market-type: spot
ec2-image-id: ${{ github.event.inputs.ami_id }}
ec2-instance-type: t3.nano
subnet-id: subnet-07512e20d23632607
security-group-id: sg-098d5c6cb021e55a4
training-loop:
name: Train model
needs: start-runner # required to start the main job when the runner is ready
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
container:
image: python:3.11
env:
MODEL_PARAM_1: 'yes'
steps:
- uses: actions/checkout@v3
- name: Hello World
run: echo 'Hello World!'
- name: Where am I
run: ls
- name: Do I see the parameter ?
run: echo $MODEL_PARAM_1
stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner # required to get output from the start-runner job
- training-loop # required to wait when the main job is done
runs-on: ubuntu-latest
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
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: ${{ github.event.inputs.aws_region }}
- name: Stop EC2 runner
uses: digital-defiance/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 }}