Skip to content

Commit

Permalink
feat: consolidating the different version into a single multi-stage D…
Browse files Browse the repository at this point in the history
…ockerfile with separate stages
  • Loading branch information
volod-vana committed Mar 12, 2024
1 parent f7e3580 commit 34e7c60
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 204 deletions.
1 change: 0 additions & 1 deletion Dockerfile

This file was deleted.

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Use the base image
FROM selfie-base as selfie

# Use the CPU-specific stage
FROM selfie-cpu as selfie-cpu

# Use the GPU-specific stage
FROM selfie-gpu as selfie-gpu

# Use the ARM64-specific stage
FROM selfie-arm64 as selfie-arm64
49 changes: 39 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,35 +135,64 @@ You can also run Selfie using Docker. To do so, follow these steps:
2. Clone or [download](https://github.com/vana-com/selfie) selfie repository.
3. In a terminal, navigate to the project directory.

We provide Dockerfiles for different GPU configurations and CPU-only environments.
Choose the appropriate Dockerfile based on your setup:
### Build image

- NVIDIA GPUs - default image, same as `Dockerfile`. Use `nvidia.Dockerfile` for systems with NVIDIA GPUs. This Dockerfile installs the necessary CUDA toolkit and the accelerated `llama-cpp-python` package.
- No GPU (CPU-only): Use `cpu.Dockerfile` for systems without a GPU. This Dockerfile uses the standard Python image and runs the application on the CPU.
Build the base image:
```bash
docker build -f docker/Dockerfile.base -t selfie-base .
```

To build and run the Docker image, navigate to the project directory and run the following commands:
Build the CPU-specific image:
```bash
docker build -f docker/Dockerfile.cpu -t selfie:cpu .
```

Build the GPU-specific image:
```bash
# Build the Docker image
docker build -t selfie .
docker build -f docker/Dockerfile.gpu -t selfie:gpu .
````

# Or, for CPU-only image:
docker build -t selfie -f cpu.Dockerfile .
Build the ARM64-specific image:
```bash
docker build -f docker/Dockerfile.arm64 -t selfie:arm64 .
```

Note: if you are on M1/M2 mac you might need to prefix the build command with `DOCKER_BUILDKIT=0 ` to be able to build for different architectures.
```bash
DOCKER_BUILDKIT=0 docker build -t selfie:arm64 .
```

Build the final image:
```bash
docker build -t selfie:latest .
```

This approach builds the stage-specific images separately and then builds the final image using the Dockerfile in the root directory.

You can then run the appropriate image based on your architecture:


Or simply use `selfie:latest`, and Docker will use the appropriate stage based on the build order defined in the root Dockerfile.

# Run the Docker container

```bash
docker run -p 8181:8181 \
--name selfie \
-v $(pwd)/data:/selfie/data \
-v $(pwd)/selfie:/selfie/selfie \
-v $(pwd)/selfie-ui:/selfie/selfie-ui \
-v $HOME/.cache/huggingface:/root/.cache/huggingface \
selfie:latest
selfie:gpu
```

This will start the server and the UI in your browser at http://0.0.0.0:8181/.
Your personal data will be stored in the `data` directory.
This mounts your Hugging Face cache into the container, so you don't have to download the models again if you already
have them.
## Setting Up Selfie
Selfie comes with a web-based UI that you can use to import your data and interact with it.
Expand Down
17 changes: 17 additions & 0 deletions docker/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM selfie-base as selfie-arm64

# Uncomment and modify the following lines if additional dependencies are needed for ARM64
# RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# <arm64-specific-dependencies> \
# && \
# rm -rf /var/lib/apt/lists/*

# Run the application with GPU support if available
CMD if [ "$(uname -m)" = "arm64" ]; then \
echo "Running with GPU support"; \
python -m selfie --gpu; \
else \
echo "Running without GPU support"; \
python -m selfie; \
fi
15 changes: 5 additions & 10 deletions cpu.Dockerfile → docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build the UI
# Base image for building the UI
FROM node:18.19-alpine3.18 AS selfie-ui

# Set the working directory in the container
Expand All @@ -16,12 +16,13 @@ COPY selfie-ui/ .
# Build the project
RUN yarn run build

# Use the official Python image with CUDA support
FROM python:3.11 as selfie
# Base image for the application
FROM python:3.11 as selfie-base

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR=1

# Set the working directory
WORKDIR /selfie
Expand All @@ -39,10 +40,4 @@ RUN pip install poetry --no-cache-dir
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi

# Run the installation script
RUN bash /selfie/scripts/llama-cpp-python-cublas.sh

EXPOSE 8181

# Run the application
CMD ["python", "-m", "selfie"]
EXPOSE 8181
4 changes: 4 additions & 0 deletions docker/Dockerfile.cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM selfie-base as selfie-cpu

# Run the application
CMD python -m selfie
7 changes: 7 additions & 0 deletions docker/Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM selfie-base as selfie-gpu

# Run the installation script for GPU support
RUN bash /selfie/scripts/llama-cpp-python-cublas.sh

# Run the application with GPU support
CMD ["python", "-m", "selfie", "--gpu"]
50 changes: 0 additions & 50 deletions nvidia.Dockerfile

This file was deleted.

Loading

0 comments on commit 34e7c60

Please sign in to comment.