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

feat: Docker support #25

Merged
merged 41 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d8bf74d
chore: fix start.sh for all environments
tnunamak Mar 4, 2024
89ceb15
feat: add Dockerfile to provide an easy way to run selfie with docker
volod-vana Mar 5, 2024
037da63
doc: Documentation on how to run selfie with docker
volod-vana Mar 5, 2024
79f10c6
feat: add --skip-deps and --skip-build to skip installing dependencie…
volod-vana Mar 5, 2024
6b2d072
Update Dockerfile
tnunamak Mar 5, 2024
a477247
Update start.sh
tnunamak Mar 5, 2024
955142f
Update README.md
tnunamak Mar 5, 2024
21ecb22
feat: add mapping for Huggingface cache dir to reduce model loading t…
volod-vana Mar 5, 2024
3d0fc4d
Simplify startup scripts
tnunamak Mar 5, 2024
9181128
Update README.md
tnunamak Mar 5, 2024
0515fb4
Merge branch 'fix-start-sh' into docker
volod-vana Mar 6, 2024
59ad015
Merge branch 'main' into docker
volod-vana Mar 7, 2024
b4ec0ef
feat: GPU support for Docker container
volod-vana Mar 7, 2024
cee0022
fix: deleting documents
tnunamak Mar 7, 2024
313a2df
fix: embeddings that are too large
tnunamak Mar 7, 2024
246ef06
fix: pyinstaller instructions
tnunamak Mar 8, 2024
961d5e5
Build macOS
tnunamak Mar 8, 2024
8b09a91
Split package workflow out to another branch
tnunamak Mar 8, 2024
ac36db1
Fix get_default_completion
tnunamak Mar 8, 2024
0a6d063
Merge branch 'fixes-3-7' into docker
volod-vana Mar 11, 2024
f89761b
feat: Optimize Dockerfile and remove start.sh dependency
volod-vana Mar 11, 2024
1fed0b9
feat: revert yarn.lock
volod-vana Mar 11, 2024
38bba3f
feat: update poetry
volod-vana Mar 11, 2024
26cd651
feat: separate files for GPU and CPU
volod-vana Mar 11, 2024
acad9ee
feat: add for nvidia docker install build tools and compilers
volod-vana Mar 11, 2024
f6e295e
feat: cleanup
volod-vana Mar 11, 2024
df479ea
feat: cleanup
volod-vana Mar 11, 2024
93c912b
feat: cleanup
volod-vana Mar 11, 2024
4479dc7
feat: cleanup
volod-vana Mar 11, 2024
71ee9d7
Merge branch 'main' into docker
volod-vana Mar 11, 2024
1de39d9
feat: add poetry.lock to .dockerignore
volod-vana Mar 11, 2024
64a0576
Update nvidia.Dockerfile
tnunamak Mar 11, 2024
9bec30a
Update .dockerignore
tnunamak Mar 11, 2024
f7e3580
Update cpu.Dockerfile
tnunamak Mar 11, 2024
34e7c60
feat: consolidating the different version into a single multi-stage D…
volod-vana Mar 12, 2024
c416bda
Use Nvidia image for selfie-gpu
tnunamak Mar 14, 2024
6eca14b
doc: updates to docker related doc
volod-vana Mar 15, 2024
3f1d1f3
feat: remove file based stages, code moved to single Dockerfile
volod-vana Mar 15, 2024
0e45e5b
fix: typo in doc
volod-vana Mar 18, 2024
e889f3f
doc: cleanup
volod-vana Mar 18, 2024
199ffbc
Doc edits
tnunamak Mar 18, 2024
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
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Build the UI using minimalistic nodejs image and yarn
volod-vana marked this conversation as resolved.
Show resolved Hide resolved
FROM node:18.19-alpine3.18 AS selfie-ui

# Set the working directory in the container
WORKDIR /selfie

# Copy the package.json and yarn.lock files
COPY selfie-ui/package.json selfie-ui/yarn.lock ./

# Install dependencies
RUN yarn install
volod-vana marked this conversation as resolved.
Show resolved Hide resolved

# Copy the rest of the code
COPY selfie-ui/ .

# Build the project (if needed)
RUN yarn build

# Use the official Python image to run selfie
FROM python:3.11 as selfie

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Install libGL
volod-vana marked this conversation as resolved.
Show resolved Hide resolved
RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \
&& rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /selfie

# Copy code and dependencies into the docker image
COPY . .

# Copy the built UI from the previous stage
COPY --from=selfie-ui /selfie/out/ ./selfie-ui/out

# Install poetry
RUN pip install poetry --no-cache-dir

# Install dependencies
RUN poetry run poetry add colorlog
volod-vana marked this conversation as resolved.
Show resolved Hide resolved

EXPOSE 8181

# Run start.sh, add --skip-deps and --skip-build to skip installing dependencies and building the UI
# since that is done in the previous stages
volod-vana marked this conversation as resolved.
Show resolved Hide resolved
CMD ["/selfie/start.sh", "--skip-deps", "--skip-build"]
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ For most users, the easiest way to install Selfie is to follow the [Quick Start]

> **Note**: You can host selfie at a publicly-accessible URL with [ngrok](https://ngrok.com). Add your ngrok token (and optionally, ngrok domain) in `selfie/.env` and run `poetry run python -m selfie --share`.

## Using docker
tnunamak marked this conversation as resolved.
Show resolved Hide resolved

You can also run Selfie using Docker. To do so, follow these steps:

1. Ensure that [Docker](https://www.docker.com) is installed.
2. Clone or [download](https://github.com/vana-com/selfie) selfie repository.
3. In a terminal, navigate to the project directory.

```shell
docker build -t selfie .
docker run -p 8181:8181 \
--name selfie \
-v $(pwd)/data:/selfie/data \
-v $(pwd)/selfie:/selfie/selfie \
-v $(pwd)/selfie-ui:/selfie/selfie-ui \
selfie:latest
```
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.

## Setting Up Selfie

Expand Down
54 changes: 42 additions & 12 deletions start.sh
volod-vana marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
#!/bin/bash

# Flags to optionally skip dependencies and build, used for docker multi-stage builds
SKIP_DEPS=false
SKIP_BUILD=false

# Parse flags
for arg in "$@"
do
case $arg in
--skip-deps)
SKIP_DEPS=true
shift # Remove --skip-deps from processing
;;
--skip-build)
SKIP_BUILD=true
shift # Remove --skip-build from processing
;;
*)
# Unknown option
;;
esac
done

if [ ! -f "selfie/.env" ]; then
echo "Copying selfie/.env.example to selfie/.env..."
cp selfie/.env.example selfie/.env
else
echo "selfie/.env already exists. Skipping copy."
fi

MISSING_DEPENDENCIES=""
command -v python >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Python (https://www.python.org/downloads/)\n"
command -v poetry >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Poetry (https://python-poetry.org/docs/#installation)\n"
command -v yarn >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Yarn (https://yarnpkg.com/getting-started/install)\n"
if [ "$SKIP_DEPS" = false ]; then
MISSING_DEPENDENCIES=""
command -v python >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Python (https://www.python.org/downloads/)\n"
command -v poetry >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Poetry (https://python-poetry.org/docs/#installation)\n"
command -v yarn >/dev/null 2>&1 || MISSING_DEPENDENCIES="${MISSING_DEPENDENCIES} Yarn (https://yarnpkg.com/getting-started/install)\n"

if [ ! -z "$MISSING_DEPENDENCIES" ]; then
echo -e "Missing dependencies:\n$MISSING_DEPENDENCIES"
exit 1
if [ ! -z "$MISSING_DEPENDENCIES" ]; then
echo -e "Missing dependencies:\n$MISSING_DEPENDENCIES"
exit 1
fi
else
echo "Skipping dependency checks..."
fi

echo "Installing Python dependencies with Poetry..."
poetry check || poetry install
echo "Installing Python dependencies with Poetry including dev..."
poetry check || poetry install --with dev

echo "Building UI with Yarn..."
./scripts/build-ui.sh
if [ "$SKIP_BUILD" = false ]; then
echo "Building UI with Yarn..."
./scripts/build-ui.sh
else
echo "Skipping UI build..."
fi

ACCELERATION_FLAG=""

Expand All @@ -38,4 +68,4 @@ else
fi

echo "Running selfie..."
poetry run python -m selfie $ACCELERATION_FLAG
poetry run python -m selfie $ACCELERATION_FLAG
tnunamak marked this conversation as resolved.
Show resolved Hide resolved