README / README.md
razzfazz-io's picture
Fix example dockerfile
a7ca8f5 verified
|
raw
history blame
6.02 kB
metadata
title: README
emoji: πŸ‘€
colorFrom: blue
colorTo: red
sdk: static
pinned: false
Spaces Dev Mode is currently in beta. It's available for PRO users (personnal Spaces) or Enterprise organizations (org Spaces).
Please share your feedback about Spaces Dev Mode in the Community tab.

Spaces Dev Mode (feature preview)

About Spaces

Spaces offer a simple way to host ML demos and apps on your profile or your organization's profile. In essence, a Space is a Docker container that runs your application.

Learn more about Spaces here: https://huggingface.co/docs/hub/spaces.

Spaces Dev Mode

Whenever your commit some changes to your Space repo, the underlying Docker image gets rebuilt, and then a new virtual machine is provisioned to host the new container.

The Dev Mode allows you to update your Space much quicker by overriding the Docker image.

The Dev Mode Docker image starts your application as a sub-process, allowing you to restart it without stopping the Space container itself. It also starts a VS Code server and a SSH server in the background for you to connect to the Space.

The ability to connect to the running Space unlocks several use cases:

  • You can make changes to the app code without the Space rebuilding everytime
  • You can debug a running application and monitor resources live

Overall it makes developing and experimenting with Spaces much faster by skipping the Docker image rebuild phase.

Interface

Once the Dev Mode is enabled on your Space, you should see a modal like the following.

The application does not restart automatically when you change the code. For your changes to appear in the Space, you need to use the Refresh button that will restart the app.

If you're using the Streamlit or Gradio SDK, or if your application is Pyhton-based, note that requirements are not installed automatically. You will need to manually run `pip install` from VS Code or SSH.

Persisting changes

The changes you make when the Dev Mode is enabled are not persisted to the Space repo automatically. By default, they will be discarded when the Dev Mode is disabled or when the Space goes to sleep.
If you wish to persist changes made while the Dev Mode is enabled, you need to use `git` from inside the Space container (using VS Code or SSH). For example:
# Add changes and commit them
git add .
git commit -m "Persist changes from Dev Mode"

# Push the commit to persist them in the repo
git push

The modal will display a warning if you have uncommitted or unpushed changes in the Space:

image/png

How to enable the Dev Mode

Go to your Space's settings and click on "Enable Dev Mode".

image/png

You can also enable the Dev Mode from the quick actions dropdown.

image/png

Limitations

The Dev Mode is currently not available for static Spaces. Docker Spaces also have some additional requirements.

Docker Spaces

Dev Mode is supported for Docker Spaces. However, your Space needs to comply with the following rules for the Dev Mode to work properly.

  1. The following packages must be installed:
  • bash (required to establish SSH connections)
  • curl, wget and procps (required by the VS Code server process)
  • git and git-lfs to be able to commit and push changes from your Dev Mode environment
  1. Your application code must be located in the /app folder for the Dev Mode daemon to be able to detect changes.

  2. The /app folder must be owned by the user with uid 1000 to allow you to make changes to the code.

  3. The Dockerfile must contain a CMD instruction for startup. Checkout Docker's documentation about the CMD instruction for more details.

The Dev Mode works well when the base image is debian-based (eg, ubuntu).

More exotic linux distros (eg, alpine) are not tested and the Dev Mode is not guaranteed to work on them.

Example of a compatible Dockerfile

This is an example of a Dockerfile compatible with Spaces Dev Mode.

It installs the required packages with apt-get, along with a couple more for developer convenience (namely: top, vim and nano). It then starts a NodeJS application from /app.

FROM node:19-slim

RUN apt-get update && \
    apt-get install -y \
      bash \
      git git-lfs \
      wget curl procps \
      htop vim nano && \
    rm -rf /var/lib/apt/lists/*

RUN useradd -m -u 1000 user

WORKDIR /app
COPY --link --chown=1000 ./ /app
RUN  npm ci 

CMD ["node", "index.mjs"]