deploy #23
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy | |
on: | |
pull_request: | |
push: | |
branches: [main, '*-assessment-year'] | |
workflow_dispatch: | |
inputs: | |
instance_type: | |
description: Type of the EC2 instance to provision | |
required: false | |
type: string | |
default: t2.micro | |
enable_gpu: | |
description: Whether to provision a GPU-enabled instance | |
required: false | |
type: boolean | |
default: false | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
publish-docker-image: | |
runs-on: ubuntu-latest | |
outputs: | |
imageid: ${{ steps.build-and-push.outputs.imageid }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
# Tag the following types of images: | |
# * On a branch, tag with the branch name (e.g. `master`) | |
# * On a PR, tag with the PR number (e.g. `pr-12`) | |
# * On all events, tag with the short git SHA (e.g. `e956384`) | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=ref,event=tag | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
provenance: false | |
launch-runner: | |
needs: [publish-docker-image] | |
runs-on: ubuntu-latest | |
environment: deploy | |
# These permissions are needed to interact with GitHub's OIDC Token endpoint | |
# so that we can authenticate with AWS | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup CML | |
uses: iterative/setup-cml@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_IAM_ROLE_TO_ASSUME_ARN }} | |
aws-region: us-east-1 | |
- name: Deploy runner on EC2 | |
# TODO: | |
# * Add cloud-permission-set | |
# * Add cloud-aws-security-group | |
# * Potentially add cloud-aws-subnet? | |
# * Add cloud-spot and cloud-spot-price | |
# * Switch to real instance size after testing and enable GPU | |
run: | | |
cml runner launch \ | |
--cloud aws \ | |
--cloud-region us-east-1 \ | |
--cloud-type "$CLOUD_TYPE" \ | |
--cloud-gpu "$CLOUD_GPU" \ | |
--name cml-runner \ | |
--labels=cml-runner \ | |
--no-retry \ | |
--single | |
shell: bash | |
env: | |
CLOUD_TYPE: ${{ inputs.instance_type }} | |
CLOUD_GPU: ${{ inputs.enable_gpu }} | |
run-model: | |
needs: [publish-docker-image, launch-runner] | |
runs-on: [self-hosted, cml-runner] | |
container: | |
image: ${{ needs.publish-docker-image.outputs.imageid }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Pull input data | |
run: dvc pull | |
shell: bash | |
- name: Run the model | |
run: dvc repro |