Skip to content

Commit

Permalink
Better scripts ✨ (#48)
Browse files Browse the repository at this point in the history
* Better scripts ✨
  • Loading branch information
cbldev authored Nov 14, 2024
1 parent 745ea11 commit f9d23cb
Show file tree
Hide file tree
Showing 33 changed files with 261 additions and 143 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
apt-get install --no-install-recommends -y build-essential git libpq-dev

# Install application gems
COPY --link Gemfile Gemfile.lock ./
COPY Gemfile Gemfile.lock ./
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
bundle config set app_config .bundle && \
bundle config set path /srv/vendor && \
Expand All @@ -40,7 +40,7 @@ RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
cp -ar /srv/vendor .

# Copy application code
COPY --link . .
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ https://github.com/nosia-ai/nosia/assets/1692273/671ccb6a-054c-4dc2-bcd9-2b874a8

https://github.com/nosia-ai/nosia/assets/1692273/ce60094b-abb5-4ed4-93aa-f69485e058b0

## Debian/Ubuntu one command installation
## macOS, Debian or Ubuntu one command installation

It will install Docker, Ollama, and Nosia on a Debian/Ubuntu machine.
It will install Docker, Ollama, and Nosia on a macOS, Debian or Ubuntu machine.

```bash
curl -fsSL https://raw.githubusercontent.com/nosia-ai/nosia-install/main/nosia-install.sh | sh
Expand All @@ -31,7 +31,7 @@ You should see the following output:

You can now access Nosia at `https://nosia.localhost`

## macOS installation with Debian/Ubuntu VM
## macOS installation with a Debian or Ubuntu VM

On macOS, install Homebrew:

Expand All @@ -46,6 +46,7 @@ Replace `<HOST_IP>` with the IP address of the host machine and run the followin
```bash
brew install ollama
ollama pull qwen2.5
ollama pull bespoke-minicheck
ollama pull nomic-embed-text
OLLAMA_BASE_URL=<HOST_IP>:11434 OLLAMA_MAX_LOADED_MODELS=3 ollama serve
```
Expand Down Expand Up @@ -84,7 +85,7 @@ After running the command, you can access Nosia at `https://nosia.localhost:<LOC

### Custom completion model

By default, Nosia uses the `qwen2.5` completion model and the `nomic-embed-text` embeddings model.
By default, Nosia uses the `qwen2.5` completion model, the `nomic-embed-text` embeddings model and the `bespoke-minicheck` checking model.

You can use any completion model available on Ollama by setting the `LLM_MODEL` environment variables during the installation.

Expand All @@ -104,14 +105,15 @@ You can start, upgrade and stop the services with the following commands:

```bash
cd nosia
./script/production/start
./script/production/upgrade
./script/production/stop
./script/start
./script/upgrade
./script/stop
```

## Troubleshooting

If you encounter any issue:

- during the installation, you can check the logs at `./log/production.log`
- during the use waiting for an AI response, you can check the jobs at `http://<IP>:3000/jobs`
- with Nosia, you can check the logs with `docker compose -f ./docker-compose.yml logs -f`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

if command -v docker &> /dev/null; then
if command -v docker &>/dev/null; then
echo "Docker is already installed"
exit 0
fi
Expand All @@ -15,8 +15,8 @@ sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
sudo apt-get update

# Install Docker:
Expand Down
8 changes: 8 additions & 0 deletions script/concerns/linux/setup-ollama
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

if command -v ollama &>/dev/null; then
echo "ollama is already installed"
exit 0
fi

curl -fsSL https://ollama.com/install.sh | sh
6 changes: 6 additions & 0 deletions script/concerns/linux/setup-openssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e

if ! command -v openssl &>/dev/null; then
sudo apt-get install -y openssl &>>./log/setup.log
fi

File renamed without changes.
8 changes: 8 additions & 0 deletions script/concerns/linux/upgrade-ollama
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

if ! command -v ollama &>/dev/null; then
echo "ollama is not installed"
exit 0
fi

curl -fsSL https://ollama.com/install.sh | sh
12 changes: 6 additions & 6 deletions script/concerns/loader
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

play_loader_loop() {
local animation=( ⌛️ ⏳ ⌛️ ⏳ )
local animation=(⌛️ ⏳ ⌛️ ⏳)

while true ; do
for frame in "${animation[@]}" ; do
while true; do
for frame in "${animation[@]}"; do
printf "\r%s" "${frame}"
sleep 0.25
done
Expand All @@ -21,19 +21,19 @@ start_loader() {

stop_loader() {
printf "\r✅"
kill "${loader_pid}" &> /dev/null
kill "${loader_pid}" &>/dev/null
printf "\n"
tput cnorm # Restore the terminal cursor
}

exit_loader() {
printf "\r ${MESSAGE}\n"
kill "${loader_pid}" &> /dev/null
kill "${loader_pid}" &>/dev/null
tput cnorm # Restore the terminal cursor
}

kill_loader() {
kill "${loader_pid}" &> /dev/null
kill "${loader_pid}" &>/dev/null
tput cnorm # Restore the terminal cursor
}

Expand Down
14 changes: 14 additions & 0 deletions script/concerns/pull-models
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -e

if ! command -v ollama &>/dev/null; then
echo "ollama is not installed"
exit 0
fi

if [ -n "$LLM_MODEL" ]; then
ollama pull $LLM_MODEL
else
ollama pull qwen2.5
fi
ollama pull bespoke-minicheck
ollama pull nomic-embed-text
14 changes: 4 additions & 10 deletions script/production/setup-env → script/concerns/setup-env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
NOSIA_URL=https://nosia.localhost
fi

if [ -n "$OLLAMA_URL" ]; then
if [ -n "$OLLAMA_BASE_URL" ]; then
echo "Using OLLAMA_BASE_URL from environment"
else
echo "OLLAMA_BASE_URL is not set, using default value"
Expand Down Expand Up @@ -46,20 +46,14 @@ POSTGRES_HOST=postgres-db
POSTGRES_PORT=5432
POSTGRES_DB=nosia_production
POSTGRES_USER=nosia
POSTGRES_PASSWORD=$(
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
echo ''
)
POSTGRES_PASSWORD=$(openssl rand -hex 32)
DATABASE_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB
SECRET_KEY_BASE=$(
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 63
echo ''
)
SECRET_KEY_BASE=$(openssl rand -hex 64)

echo "DATABASE_URL=$DATABASE_URL" >.env
echo "NOSIA_URL=$NOSIA_URL" >>.env
echo "OLLAMA_BASE_URL=$OLLAMA_BASE_URL" >>.env
echo "OLLAMA_API_KEY=" >> .env
echo "OLLAMA_API_KEY=" >>.env
echo "LLM_MODEL=$LLM_MODEL" >>.env
echo "CHECK_MODEL=$CHECK_MODEL" >>.env
echo "EMBEDDING_MODEL=$EMBEDDING_MODEL" >>.env
Expand Down
1 change: 0 additions & 1 deletion script/dev/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
./script/dev/setup-asdf
./script/dev/setup-ruby
./bin/setup
./script/ollama/setup
6 changes: 3 additions & 3 deletions script/dev/setup-asdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -d ~/.asdf ]; then
fi

git clone https://github.com/excid3/asdf.git ~/.asdf
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc
echo 'legacy_version_file = yes' >> ~/.asdfrc
echo '. "$HOME/.asdf/asdf.sh"' >>~/.bashrc
echo '. "$HOME/.asdf/completions/asdf.bash"' >>~/.bashrc
echo 'legacy_version_file = yes' >>~/.asdfrc
exec $SHELL
2 changes: 1 addition & 1 deletion script/dev/setup-ruby
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

if command -v ruby &> /dev/null; then
if command -v ruby &>/dev/null; then
echo "Ruby is already installed"
exit 0
fi
Expand Down
28 changes: 28 additions & 0 deletions script/linux/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash -e

. ./script/concerns/loader

start_loader "Setting up OpenSSL"
./script/concerns/linux/setup-openssl &>>./log/setup.log
stop_loader

if [ "$OLLAMA_BASE_URL" == "http://localhost:11434" ]; then
start_loader "Setting up Ollama"
./script/concerns/linux/setup-ollama &>>./log/setup.log
stop_loader

start_loader "Pulling models. This may take a while..."
./script/concerns/pull-models &>>./log/setup.log
stop_loader
fi

start_loader "Setting up Docker"
./script/concerns/linux/setup-docker &>>./log/setup.log
stop_loader

start_loader "Setting up Nosia"
# Set environment variables for Nosia
./script/concerns/setup-env &>>./log/setup.log
# Build Nosia
docker compose --env-file .env build &>>./log/setup.log
stop_loader
11 changes: 11 additions & 0 deletions script/linux/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. ./script/concerns/loader

start_loader "Starting ollama"
sudo systemctl start ollama.service &>>./log/ollama.log
stop_loader

start_loader "Starting Nosia"
docker compose --env-file .env up -d &>>./log/docker.log
stop_loader
11 changes: 11 additions & 0 deletions script/linux/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. ./script/concerns/loader

start_loader "Stopping Nosia"
docker compose down &>>./log/docker.log
stop_loader

start_loader "Stopping ollama"
sudo systemctl stop ollama.service &>>./log/ollama.log
stop_loader
20 changes: 20 additions & 0 deletions script/linux/upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -e

. ./script/concerns/loader

if command -v ollama &>/dev/null; then
start_loader "Upgrading ollama"
./script/concerns/linux/upgrade-ollama &>>./log/upgrade.log
stop_loader

start_loader "Pulling models. This may take a while..."
./script/concerns/pull-models &>>./log/upgrade.log
stop_loader
fi

start_loader "Upgrading Nosia"
# Pull latest changes
git pull &>>./log/upgrade.log
# Build Nosia
docker compose --env-file .env build &>>./log/upgrade.log
stop_loader
55 changes: 55 additions & 0 deletions script/macos/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

. ./script/concerns/loader

start_loader "Setting up prerequisites: brew and openssl"

# Install brew if not installed
if ! command -v brew &>/dev/null; then
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | sh &>./log/setup.log
fi

# Install openssl if not installed
if ! brew list openssl &>/dev/null; then
brew install openssl &>./log/setup.log
fi

stop_loader

start_loader "Setting up ollama"
# Install ollama if not installed
if ! brew list ollama &>/dev/null; then
brew install ollama &>./log/setup.log
fi
stop_loader

start_loader "Pulling models. This may take a while..."
# Start ollama
brew services start ollama &>./log/setup.log
# Wait for ollama to start
sleep 5
# Pull models
ollama pull $LLM_MODEL &>./log/setup.log
ollama pull bespoke-minicheck &>./log/setup.log
ollama pull nomic-embed-text &>./log/setup.log
stop_loader

start_loader "Setting up podman"
# Install podman if not installed
if ! brew list podman &>/dev/null; then
brew install podman podman-compose &>./log/setup.log
fi
stop_loader

start_loader "Setting up Nosia"
# Initialize podman machine
podman machine init &>./log/setup.log
# Set podman to rootful mode
podman machine set --rootful &>./log/setup.log
# Start podman machine
podman machine start &>./log/setup.log
# Set environment variables for Nosia
OLLAMA_BASE_URL=http://host.containers.internal:11434 ./script/concerns/setup-env &>./log/setup.log
# Build Nosia
podman-compose --env-file .env build &>./log/setup.log
stop_loader
12 changes: 12 additions & 0 deletions script/macos/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

. ./script/concerns/loader

start_loader "Starting ollama"
OLLAMA_MAX_LOADED_MODELS=3 ollama serve &>./log/ollama.log &
stop_loader

start_loader "Starting Nosia"
podman machine start &>./log/podman.log
podman-compose --env-file .env up -d &>./log/podman.log
stop_loader
12 changes: 12 additions & 0 deletions script/macos/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

. ./script/concerns/loader

start_loader "Stopping Nosia"
podman-compose down &>./log/podman.log
podman machine stop &>./log/podman.log
stop_loader

start_loader "Stopping ollama"
killall "ollama" &>./log/ollama.log
stop_loader
Loading

0 comments on commit f9d23cb

Please sign in to comment.