Skip to content

Commit

Permalink
#8082: Infra to build and run docker images in CI (#11179)
Browse files Browse the repository at this point in the history
* #0: add docker run action

* #0: add docker image build and upload workflow
  • Loading branch information
TT-billteng authored Aug 8, 2024
1 parent 567598b commit f188d45
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/actions/docker-run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "Run set of commands in Docker"
description: "Run commands in docker"

inputs:
run_args:
description: 'Commands to run in docker'
required: true
docker_image:
description: 'Docker image to run commands in'
required: false
default: tt-metalium/ubuntu-20.04-amd64
docker_image_arch:
description: 'Is this a wormhole.b0, grayskull, or blackhole image'
required: true
docker_username:
description: docker login username
required: true
docker_password:
description: docker login password
required: true
docker_opts:
description: 'Docker options'
required: false

runs:
using: "composite"
steps:
- name: Set up dynamic env vars for build
shell: bash
run: |
echo "TT_METAL_HOME=$(pwd)" >> $GITHUB_ENV
echo "RUNNER_UID=$(id -u)" >> $GITHUB_ENV
echo "RUNNER_GID=$(id -g)" >> $GITHUB_ENV
- name: Create correct Docker Tag
shell: bash
run: |
if [[ "${GITHUB_REF_NAME}" == "main" ]]; then
echo "BASE_IMAGE_TAG=latest" >> $GITHUB_ENV
echo "OUTPUT_IMAGE_TAG=${{ env.ARCH_NAME }}" >> $GITHUB_ENV
else
echo "BASE_IMAGE_TAG=${GITHUB_ACTOR}" >> $GITHUB_ENV
echo "OUTPUT_IMAGE_TAG=dev-${GITHUB_ACTOR}.${{ inputs.docker_image_arch }}.${{ github.sha }}" >> $GITHUB_ENV
echo "RUNNER UID"
echo "${{ env.RUNNER_UID }}:${{ env.RUNNER_GID }}"
fi
- name: Docker login
uses: docker/login-action@v3
with:
registry: https://ghcr.io
username: ${{ inputs.docker_username }}
password: ${{ inputs.docker_password }}
- uses: addnab/docker-run-action@v3
with:
shell: bash
username: ${{ inputs.docker_username }}
password: ${{ inputs.docker_password }}
registry: ghcr.io
image: ghcr.io/${{ github.repository }}/${{ inputs.docker_image }}/${{ inputs.docker_image_arch }}:${{ env.OUTPUT_IMAGE_TAG }}
options: |
-u ${{ env.RUNNER_UID }}:${{ env.RUNNER_GID }}
-v ${{ github.workspace }}:/app/mtl
-v /home/ubuntu/.cache/huggingface:/home/ubuntu/.cache/huggingface
-v /home/ubuntu/.cache/matplotlib:/home/ubuntu/.cache/matplotlib
-v /home/ubuntu/.cache/pre-commit:/home/ubuntu/.cache/pre-commit
-v /home/ubuntu/.cache/torch:/home/ubuntu/.cache/torch
--net=host
${{ inputs.docker_opts }}
run: |
${{ inputs.run_args }}
41 changes: 41 additions & 0 deletions .github/workflows/build-docker-artifact.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Build tt-metal docker artifact"

on:
workflow_call:
workflow_dispatch:

jobs:
build-docker-image:
env:
TT_METAL_ENV: ${{ vars.TT_METAL_ENV }}
CONFIG: ci
SILENT: 0
VERBOSE: 1
TT_METAL_DOCKER_IMAGE: tt-metalium/ubuntu-20.04-amd64
TT_METAL_DOCKER_IMAGE_TAG: ${{ github.sha }}
environment: dev
runs-on: build-docker
steps:
- uses: tenstorrent-metal/metal-workflows/.github/actions/[email protected]
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: https://ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: |
./scripts/docker/build_docker_image.sh ${{ env.TT_METAL_DOCKER_IMAGE }}:${{ env.TT_METAL_DOCKER_IMAGE_TAG }}
- name: Determine Docker Image Tag
id: set-image
run: |
if [[ "${GITHUB_REF_NAME}" == "main" ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
else
echo "IMAGE_TAG=dev-${GITHUB_ACTOR}" >> $GITHUB_ENV
fi
- name: Push Docker image to GitHub Container Registry
run: |
GITHUB_REPO_DOCKER_IMAGE_TAG=ghcr.io/${{ github.repository }}/${{ env.TT_METAL_DOCKER_IMAGE }}:${{ env.IMAGE_TAG }}
docker tag ${{ env.TT_METAL_DOCKER_IMAGE }}:${{ env.TT_METAL_DOCKER_IMAGE_TAG }} $GITHUB_REPO_DOCKER_IMAGE_TAG
docker push $GITHUB_REPO_DOCKER_IMAGE_TAG

0 comments on commit f188d45

Please sign in to comment.