Spaces:
Running
Running
name: Deploy to HuggingFace Spaces | |
on: | |
# Spaces doesn't have the RAM to build the image anymore | |
# We wait for docker-build.yaml to be done first | |
workflow_call: | |
inputs: | |
image-name: | |
required: true | |
type: string | |
jobs: | |
check-secret: | |
runs-on: ubuntu-latest | |
outputs: | |
token-set: ${{ steps.check-key.outputs.defined }} | |
steps: | |
- id: check-key | |
env: | |
HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
if: "${{ env.HF_TOKEN != '' }}" | |
run: echo "defined=true" >> $GITHUB_OUTPUT | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [check-secret] | |
if: needs.check-secret.outputs.token-set == 'true' | |
env: | |
HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
HF_USERNAME: ${{ secrets.HF_USERNAME }} | |
HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
lfs: true | |
- name: Remove git history | |
run: rm -rf .git | |
- name: Prepend YAML front matter to README.md | |
run: | | |
cat <<EOF >README.md | |
--- | |
title: Open WebUI | |
emoji: 🐳 | |
colorFrom: purple | |
colorTo: gray | |
sdk: docker | |
app_port: 8080 | |
hf_oauth: true | |
hf_oauth_scopes: | |
--- | |
$(cat README.md) | |
EOF | |
- name: Write new Dockerfile | |
run: | | |
echo "FROM ${{ inputs.image-name }}" > Dockerfile | |
echo "# This file is automatically generated by the deploy-to-hf-spaces.yml workflow" >> Dockerfile | |
echo "# HF Spaces doesn't have the RAM to build the image, so we use the pre-built image from the docker-build.yml workflow" >> Dockerfile | |
- name: Configure git | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
- name: Set up Git and push to Space | |
run: | | |
git init --initial-branch=main | |
git lfs install | |
git lfs track "*.ttf" | |
git lfs track "*.jpg" | |
rm demo.gif | |
git add . | |
git commit -m "GitHub deploy: ${{ github.sha }}" | |
git push --force https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME} main | |