build-svelte-demo / Dockerfile
severo's picture
severo HF Staff
add Dockerfile and the app
e3c0beb
raw
history blame
1.46 kB
FROM ubuntu:22.04
# The site space name must be passed as an environment variable
# https://huggingface.co/docs/hub/spaces-sdks-docker#buildtime
ARG STATIC_SPACE
# Install Node.js 22 - https://github.com/nodesource/distributions?tab=readme-ov-file#installation-instructions-deb
RUN apt update
RUN apt install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
RUN bash nodesource_setup.sh
RUN apt install -y nodejs
# Build the app
WORKDIR /tmp/app
COPY svelte-demo/ ./
RUN npm ci
RUN npm rebuild
RUN npm run build
# Install Python 3 and huggingface_hub
WORKDIR /tmp/python
RUN apt install -y python3 python3-pip
RUN pip install --upgrade "huggingface_hub[cli]"
# Replace the site space with the new build
RUN mv /tmp/app/dist /tmp/space
WORKDIR /tmp/space
# The Hugging Face token must be passed as a secret (https://huggingface.co/docs/hub/spaces-sdks-docker#buildtime)
# 1. get README.md from the site space
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true huggingface-cli download --token=$(cat /run/secrets/HF_TOKEN) --repo-type=space --local-dir=. $STATIC_SPACE README.md
RUN rm -rf ./.cache
# 2. upload the new build to the site space, including README.md
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true huggingface-cli upload --token=$(cat /run/secrets/HF_TOKEN) --repo-type=space $STATIC_SPACE /tmp/space . --delete "*"
# Halt execution because the code space is not meant to run.
RUN exit 1