diff --git a/.github/workflows/build-images.yaml b/.github/workflows/build-images.yaml index 9dc73d9..8b2a1bf 100644 --- a/.github/workflows/build-images.yaml +++ b/.github/workflows/build-images.yaml @@ -6,6 +6,8 @@ on: pull_request: branches: - main + paths: + - huggingface-modelcar-builder/** paths-ignore: - .github/** - .gitignore @@ -14,18 +16,16 @@ on: - docs/** jobs: - build-granite-image: + build-huggingface-modelcar-builder-image: uses: ./.github/workflows/workflow-build-image.yaml with: registry: quay.io/redhat-ai-services - image-name: modelcar-catalog - context: granite-3.0-2b-instruct - containerfile: ./granite-3.0-2b-instruct/Containerfile - tag: "granite-3.0-2b-instruct" + image-name: huggingface-modelcar-builder + context: huggingface-modelcar-builder + push-latest: true secrets: registry-username: ${{ secrets.REGISTRY_USERNAME }} registry-password: ${{ secrets.REGISTRY_PASSWORD }} - hf-token: ${{ secrets.HF_TOKEN }} # build-mistral-image: # uses: ./.github/workflows/workflow-build-image.yaml diff --git a/.github/workflows/workflow-build-image.yaml b/.github/workflows/workflow-build-image.yaml index 03ec347..7fd74c2 100644 --- a/.github/workflows/workflow-build-image.yaml +++ b/.github/workflows/workflow-build-image.yaml @@ -9,15 +9,24 @@ on: required: true type: string context: - required: true + required: false type: string + default: . containerfile: required: false type: string default: ./Containerfile - tag: - required: true + tag-base: + required: false + type: string + tag-suffix: + required: false type: string + default: "" + push-latest: + required: false + type: boolean + default: false secrets: registry-username: required: true @@ -47,16 +56,34 @@ jobs: # sudo apt-get remove containerd.io # sudo apt-get install docker.io=24.0.7-0ubuntu2~22.04.1 - - name: Extract version number + - name: Create tags id: version run: | - MAIN_TAG=${{ inputs.tag }} + PYPROJECT_FILE = "${{ inputs.context }}/pyproject.toml" + if [ -f ${PYPROJECT_FILE} ]; then + VERSION=$(awk 'NR==3 {print $3}' ${PYPROJECT_FILE} | tr -d '"') + echo "version=$VERSION" | tee -a $GITHUB_OUTPUT + fi + + MAIN_TAG=${{ inputs.tag-base }}${VERSION}${{ inputs.tag-suffix }} echo "main_tag=$MAIN_TAG" | tee -a $GITHUB_OUTPUT + DATE=$(date -u +'%Y%m%dt%H%Mz') echo "date=${DATE}" | tee -a $GITHUB_OUTPUT + DATE_TAG=${MAIN_TAG}-${DATE} echo "date_tag=${DATE_TAG}" | tee -a $GITHUB_OUTPUT + TAGS="${MAIN_TAG} ${DATE_TAG}" + + if ${{ inputs.push-latest }}; then + LATEST_TAG="latest${{ inputs.tag-suffix }}" + echo "latest_tag=${LATEST_TAG}" | tee -a $GITHUB_OUTPUT + TAGS="${TAGS} ${LATEST_TAG}" + fi + + echo "tags=${TAGS}" | tee -a $GITHUB_OUTPUT + # - name: Image-Pull-Check # id: image_pull_check # run: | @@ -73,9 +100,9 @@ jobs: uses: redhat-actions/buildah-build@v2 with: image: ${{ inputs.image-name }} - tags: ${{ steps.version.outputs.main_tag }} ${{ steps.version.outputs.date_tag }} + tags: ${{ steps.version.outputs.tags }} context: ${{ inputs.context }} - containerfiles: ${{ inputs.containerfile }} + containerfiles: ${{ inputs.context }}/${{ inputs.containerfile }} build-args: HF_TOKEN=${{ secrets.hf-token }} - name: Push-Image diff --git a/huggingface-modelcar-builder/Containerfile b/huggingface-modelcar-builder/Containerfile new file mode 100644 index 0000000..66d4e0c --- /dev/null +++ b/huggingface-modelcar-builder/Containerfile @@ -0,0 +1,10 @@ +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4 as base + +COPY requirements.txt . + +# Install necessary Python dependencies +RUN microdnf -y install git git-lfs python3-pip && \ + microdnf clean all && \ + pip3 install -r requirements.txt + +COPY download_model.py . diff --git a/huggingface-modelcar-builder/README.md b/huggingface-modelcar-builder/README.md new file mode 100644 index 0000000..42f02de --- /dev/null +++ b/huggingface-modelcar-builder/README.md @@ -0,0 +1 @@ +# Huggingface-modelcar-builder diff --git a/huggingface-modelcar-builder/download_model.py b/huggingface-modelcar-builder/download_model.py new file mode 100755 index 0000000..0c60ff8 --- /dev/null +++ b/huggingface-modelcar-builder/download_model.py @@ -0,0 +1,13 @@ +import os + +from huggingface_hub import snapshot_download + +model_repo = os.getenv("MODEL_REPO") + +print(f"Attempting to download the following model from huggingface: {model_repo}") + +snapshot_download( + repo_id=model_repo, + local_dir="/models", + allow_patterns=["*.safetensors", "*.json", "*.txt"], +) diff --git a/huggingface-modelcar-builder/pyproject.toml b/huggingface-modelcar-builder/pyproject.toml new file mode 100644 index 0000000..7a69f50 --- /dev/null +++ b/huggingface-modelcar-builder/pyproject.toml @@ -0,0 +1,4 @@ +[project] +name = "huggingface-modelcar-builder" +description = "A container image to help build modelcar images" +version = "0.1.0" diff --git a/huggingface-modelcar-builder/requirements.txt b/huggingface-modelcar-builder/requirements.txt new file mode 100644 index 0000000..39f3cd0 --- /dev/null +++ b/huggingface-modelcar-builder/requirements.txt @@ -0,0 +1 @@ +huggingface-hub