-
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 workflow
- Loading branch information
1 parent
da2ad32
commit df44f58
Showing
5 changed files
with
127 additions
and
85 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,39 @@ | ||
#!/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 | ||
|
||
# Silence stdout | ||
# exec 3>&1 1>/dev/null 2>&1 | ||
|
||
# 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 | ||
fi | ||
cd third_party/tt-mlir | ||
git fetch | ||
git checkout $TT_MLIR_VERSION | ||
if [ -f ".github/get-docker-tag.sh" ]; then | ||
MLIR_DOCKER_TAG=$(.github/get-docker-tag.sh) | ||
else | ||
MLIR_DOCKER_TAG="default-tag" | ||
fi | ||
cd ../.. | ||
) | ||
|
||
# Restore stdout | ||
# exec 1>&3 3>&- | ||
|
||
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.