Skip to content

Commit

Permalink
add modelcar builder image
Browse files Browse the repository at this point in the history
  • Loading branch information
strangiato committed Nov 4, 2024
1 parent 1dd1436 commit 6aa6266
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 13 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
pull_request:
branches:
- main
paths:
- huggingface-modelcar-builder/**
paths-ignore:
- .github/**
- .gitignore
Expand All @@ -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
Expand Down
41 changes: 34 additions & 7 deletions .github/workflows/workflow-build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions huggingface-modelcar-builder/Containerfile
Original file line number Diff line number Diff line change
@@ -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 .
1 change: 1 addition & 0 deletions huggingface-modelcar-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Huggingface-modelcar-builder
13 changes: 13 additions & 0 deletions huggingface-modelcar-builder/download_model.py
Original file line number Diff line number Diff line change
@@ -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"],
)
4 changes: 4 additions & 0 deletions huggingface-modelcar-builder/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[project]
name = "huggingface-modelcar-builder"
description = "A container image to help build modelcar images"
version = "0.1.0"
1 change: 1 addition & 0 deletions huggingface-modelcar-builder/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
huggingface-hub

0 comments on commit 6aa6266

Please sign in to comment.