| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- /*
- Copyright 2026 LocoStack.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- package downloader
- import (
- "github.com/LocoStack/loco-operator/api/v1alpha1"
- corev1 "k8s.io/api/core/v1"
- "k8s.io/utils/ptr"
- )
- const (
- DOWNLOADER_DOWNLOAD_DIR = "/data"
- command = `pip install -q huggingface_hub && \
- hf download $HF_REPO $HF_REPO_FILENAME --local-dir $DOWNLOAD_DIR --revision $HF_REPO_REVISION`
- )
- var HFDownloaderTemplate = v1alpha1.Template{
- Name: "hf-downloader",
- Spec: v1alpha1.TemplateSpec{
- Runtime: v1alpha1.RuntimeSpec{
- Name: "downloader",
- Image: "python:3.11-slim",
- Command: []string{"/bin/sh", "-c", command},
- Args: []string{},
- Env: []corev1.EnvVar{
- {Name: "DOWNLOAD_DIR", Value: DOWNLOADER_DOWNLOAD_DIR},
- {Name: "HF_REPO", Value: "$(spec.hfRepo)"},
- {Name: "HF_REPO_FILENAME", Value: "$(spec.hfFilename)"},
- {Name: "HF_REPO_REVISION", Value: "$(spec.hfRevision)"},
- {Name: "HF_ENDPOINT", Value: "$(spec.hfEndpoint)"},
- {Name: "HF_TOKEN", ValueFrom: &corev1.EnvVarSource{
- SecretKeyRef: &corev1.SecretKeySelector{
- LocalObjectReference: corev1.LocalObjectReference{Name: "$(spec.hfToken.name)"},
- Key: "$(spec.hfToken.key)",
- Optional: ptr.To(true),
- },
- }},
- },
- VolumeMounts: []corev1.VolumeMount{
- {Name: "artifacts", MountPath: DOWNLOADER_DOWNLOAD_DIR},
- },
- },
- Volumes: []corev1.Volume{
- {
- Name: "artifacts",
- VolumeSource: corev1.VolumeSource{
- PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
- ClaimName: "$(spec.pvcName)",
- },
- },
- },
- },
- },
- }
|