Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor Dockerfile setup for improved modularity and maintainability #36

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
poetry.lock
docker/
53 changes: 0 additions & 53 deletions Dockerfile

This file was deleted.

29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,49 +143,52 @@ have them.

### CPU Image
```bash
docker build --target selfie-cpu -t selfie:cpu .
./docker/build.sh cpu

docker run -p 8181:8181 \
--name selfie-cpu \
-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:cpu
```

### Nvidia GPU Image
```bash
docker build --target selfie-gpu -t selfie:gpu .
./docker/build.sh gpu

docker run -p 8181:8181 \
--name selfie-gpu \
-v $(pwd)/data:/selfie/data \
-v $(pwd)/selfie:/selfie/selfie \
-v $(pwd)/selfie-ui:/selfie/selfie-ui \
-v $HOME/.cache/huggingface:/root/.cache/huggingface \
--gpus all \
--ipc=host --ulimit memlock=-1 --ulimit stack=67108864 \
selfie:gpu
````

### MacOS ARM64 Image


> Disclaimer:
>
> This Docker container is designed to run on a wide range of architectures, including Apple's M1 and M2 chips.
However, due to current limitations with Docker on macOS, direct access to Metal APIs is not available for containers.
As a result, applications requiring intensive graphics processing may experience reduced performance compared to running natively on macOS.
This setup is recommended for development and testing purposes only. Running it on a native machine is recommended for better performance.
>
> We're continuously exploring ways to improve performance and compatibility.



```bash
DOCKER_BUILDKIT=0 docker build --target selfie-arm64 -t selfie:arm64 .
./docker/build.sh arm64

docker run -p 8181:8181 \
--name selfie-arm64 \
-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:arm64
```

> **Note**: on an M1/M2/M3 Mac, you may need to prefix the build command with `DOCKER_BUILDKIT=0` to disable BuildKit.
> ```bash
> DOCKER_BUILDKIT=0 docker build -t selfie:arm64 .
> ```

## Setting Up Selfie

Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM selfie-base as selfie-arm64
EXPOSE 8181
CMD ["python", "-m", "selfie", "--gpu", "--verbose"]
17 changes: 17 additions & 0 deletions docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:18-alpine as selfie-ui
WORKDIR /selfie
COPY selfie-ui/package.json selfie-ui/yarn.lock ./
RUN yarn install --frozen-lockfile --non-interactive
COPY selfie-ui/ .
RUN yarn run build

FROM python:3.11 as selfie-base
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR=1
WORKDIR /selfie
COPY . .
COPY --from=selfie-ui /selfie/out/ ./selfie-ui/out
RUN pip install poetry --no-cache-dir
RUN poetry config virtualenvs.create false
RUN poetry install --no-interaction --no-ansi
3 changes: 3 additions & 0 deletions docker/Dockerfile.cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM selfie-base as selfie-cpu
EXPOSE 8181
CMD ["python", "-m", "selfie"]
17 changes: 17 additions & 0 deletions docker/Dockerfile.gpu
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM nvcr.io/nvidia/pytorch:23.10-py3 as selfie-gpu

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR=1

WORKDIR /selfie
COPY . .
COPY --from=selfie-ui /selfie/out/ ./selfie-ui/out

RUN pip install poetry --no-cache-dir
ENV PATH="/root/.local/bin:$PATH"
RUN poetry install --no-interaction --no-ansi

RUN bash /selfie/scripts/llama-cpp-python-cublas.sh

CMD ["poetry", "run", "python", "-m", "selfie", "--gpu", "--verbose"]
6 changes: 6 additions & 0 deletions docker/Dockerfile.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:18-alpine as selfie-ui
WORKDIR /selfie
COPY selfie-ui/package.json selfie-ui/yarn.lock ./
RUN yarn install --frozen-lockfile --non-interactive
COPY selfie-ui/ .
RUN yarn run build
28 changes: 28 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

TARGET_ARCH=$1
shift

if [ -z "$TARGET_ARCH" ]; then
echo "Please provide the target architecture (cpu, gpu, or arm64) as an argument."
exit 1
fi

# Build the base image first
docker build -t selfie-base -f docker/Dockerfile.base .

case $TARGET_ARCH in
cpu)
docker build -t selfie:cpu -f docker/Dockerfile.cpu "$@" .
;;
gpu)
docker build -t selfie:gpu -f docker/Dockerfile.gpu "$@" .
;;
arm64)
docker build -t selfie:arm64 -f docker/Dockerfile.arm64 "$@" .
;;
*)
echo "Invalid target architecture. Please choose from cpu, gpu, or arm64."
exit 1
;;
esac