-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build docker image as part of a workflow (#37)
Build docker image as part of a workflow Similar to : tenstorrent/tt-mlir#928 Docs
- Loading branch information
1 parent
89c6a7e
commit 7676cb0
Showing
5 changed files
with
123 additions
and
86 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -e | ||
|
||
REPO=tenstorrent/tt-xla | ||
BASE_IMAGE_NAME=ghcr.io/$REPO/tt-xla-base-ubuntu-22-04 | ||
CI_IMAGE_NAME=ghcr.io/$REPO/tt-xla-ci-ubuntu-22-04 | ||
|
||
# Compute the hash of the Dockerfile | ||
DOCKER_TAG=$(./.github/get-docker-tag.sh) | ||
echo "Docker tag: $DOCKER_TAG" | ||
|
||
# Are we on main branch | ||
ON_MAIN=$(git branch --show-current | grep -q main && echo "true" || echo "false") | ||
|
||
build_and_push() { | ||
local image_name=$1 | ||
local dockerfile=$2 | ||
local on_main=$3 | ||
|
||
|
||
if docker manifest inspect $image_name:$DOCKER_TAG > /dev/null; then | ||
echo "Image $image_name:$DOCKER_TAG already exists" | ||
else | ||
echo "Building image $image_name:$DOCKER_TAG" | ||
docker build \ | ||
--progress=plain \ | ||
--build-arg FROM_TAG=$DOCKER_TAG \ | ||
-t $image_name:$DOCKER_TAG \ | ||
-t $image_name:latest \ | ||
-f $dockerfile . | ||
|
||
echo "Pushing image $image_name:$DOCKER_TAG" | ||
docker push $image_name:$DOCKER_TAG | ||
|
||
# If we are on main branch also push the latest tag | ||
if [ "$on_main" = "true" ]; then | ||
echo "Pushing image $image_name:latest" | ||
docker push $image_name:latest | ||
fi | ||
fi | ||
} | ||
|
||
build_and_push $BASE_IMAGE_NAME .github/Dockerfile.base $ON_MAIN | ||
build_and_push $CI_IMAGE_NAME .github/Dockerfile.ci $ON_MAIN | ||
|
||
echo "All images built and pushed successfully" | ||
echo "CI_IMAGE_NAME:" | ||
echo $CI_IMAGE_NAME:$DOCKER_TAG |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Calculate hash for docker image tag. | ||
# The hash is based on the MLIR docker tag and the hash of the Dockerfile(s). | ||
|
||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
# Execute this in a separate bash process | ||
( | ||
# Read tt-mlir version from third_party/CMakeLists.txt and clone third_party/tt-mlir | ||
# Get the MLIR docker tag | ||
TT_MLIR_VERSION=$(grep -oP 'set\(TT_MLIR_VERSION "\K[^"]+' third_party/CMakeLists.txt) | ||
if [ ! -d "third_party/tt-mlir" ]; then | ||
git clone https://github.com/tenstorrent/tt-mlir.git third_party/tt-mlir --quiet | ||
fi | ||
cd third_party/tt-mlir | ||
git fetch --quiet | ||
git checkout $TT_MLIR_VERSION --quiet | ||
if [ -f ".github/get-docker-tag.sh" ]; then | ||
MLIR_DOCKER_TAG=$(.github/get-docker-tag.sh) | ||
else | ||
MLIR_DOCKER_TAG="default-tag" | ||
fi | ||
cd ../.. | ||
) | ||
|
||
DOCKERFILE_HASH_FILES=".github/Dockerfile.base .github/Dockerfile.ci" | ||
DOCKERFILE_HASH=$( (echo $MLIR_DOCKER_TAG; sha256sum $DOCKERFILE_HASH_FILES) | sha256sum | cut -d ' ' -f 1) | ||
echo dt-$DOCKERFILE_HASH |
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
This file was deleted.
Oops, something went wrong.