Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Aug 13, 2024
1 parent f389c54 commit e40d49e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 33 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create_instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
OVH_REGION: ${{ vars.OVH_REGION }}

USERS: ${{ vars.USERS }}
GIT_REPO: ${{ vars.GIT_REPO }}

OVH_APPLICATION_KEY: ${{ secrets.OVH_APPLICATION_KEY }}
OVH_APPLICATION_SECRET: ${{ secrets.OVH_APPLICATION_SECRET }}
Expand Down
32 changes: 16 additions & 16 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ services:
capabilities: [gpu]
volumes:
- /opt/vllm/cache:/root/.cache:rw
healthcheck:
test: curl --fail http://localhost:8000/v1/models || exit 1
interval: 10s
timeout: 30s
retries: 60
start_period: 60s
# healthcheck:
# test: curl --fail http://localhost:8000/v1/models || exit 1
# interval: 10s
# timeout: 30s
# retries: 60
# start_period: 60s

reverse-proxy:
image: traefik:v2.4
Expand All @@ -57,13 +57,13 @@ services:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./letsencrypt:/letsencrypt"

autoheal:
image: willfarrell/autoheal:latest
tty: true
restart: always
environment:
- AUTOHEAL_INTERVAL=60
- AUTOHEAL_START_PERIOD=300
- AUTOHEAL_DEFAULT_STOP_TIMEOUT=10
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# autoheal:
# image: willfarrell/autoheal:latest
# tty: true
# restart: always
# environment:
# - AUTOHEAL_INTERVAL=60
# - AUTOHEAL_START_PERIOD=300
# - AUTOHEAL_DEFAULT_STOP_TIMEOUT=10
# volumes:
# - /var/run/docker.sock:/var/run/docker.sock
92 changes: 75 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def indentString(input_string, indent_level=4):
users = os.getenv("USERS", "")
gitPrivateDeployKey = os.getenv("GIT_PRIVATE_DEPLOY_KEY", "")
pythonVersion = os.getenv("PYTHON_VERSION", "3.11")
gitRepo = os.getenv("GIT_REPO", "")

gitPrivateDeployKey = indentString(gitPrivateDeployKey, 8)

Expand All @@ -67,12 +68,13 @@ def indentString(input_string, indent_level=4):
if 'primary_group' not in user:
user['primary_group'] = user['name']
if 'groups' not in user:
user['groups'] = [user['primary_group'], 'sshusers']
else:
if user['primary_group'] not in user['groups']:
user['groups'] = []
if user['primary_group'] not in user['groups']:
user['groups'].append(user['primary_group'])
if 'sshusers' not in user['groups']:
user['groups'].append('sshusers')
if 'sshusers' not in user['groups']:
user['groups'].append('sshusers')
if 'docker' not in user['groups']:
user['groups'].append('docker')
users = yaml.dump(parsedUsers)


Expand All @@ -86,35 +88,88 @@ def indentString(input_string, indent_level=4):
ssh_pwauth: false
packages:
# creds
- apache2-utils
- pwgen
# debug
- micro
- bpytop
# scripting
- jq
- pyenv
# python pyenv deps
- make
- build-essential
- libssl-dev
- zlib1g-dev
- libbz2-dev
- libreadline-dev
- libsqlite3-dev
- wget
- curl
- llvm
- libncurses5-dev
- libncursesw5-dev
- xz-utils
- tk-dev
- libffi-dev
- liblzma-dev
- python3-openssl
write_files:
- path: /etc/profile.d/pyenv.sh
permissions: "0444"
owner: root:root
content: |
#!/bin/bash
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
# Check if pyenv is not installed
if ! command -v pyenv 1>/dev/null 2>&1; then
curl https://pyenv.run | bash
# Reload the shell to recognize pyenv
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
PYTHON_VERSION="{pythonVersion}"
pyenv install $PYTHON_VERSION
pyenv global $PYTHON_VERSION
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Set Poetry to use the pyenv Python version
poetry env use $(pyenv which python)
fi
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
- path: /home/ubuntu/.ssh/id_ed25519
permissions: "0600"
owner: ubuntu:ubuntu
content: |
{gitPrivateDeployKey}
- path: /opt/vllm/init.sh
owner: ubuntu:sshusers
permissions: "0775"
content: |
#!/bin/bash
set -Eeuo pipefail
# setup extra packages
## setup python env
pyenv install {pythonVersion}
pyenv global {pythonVersion}
curl -sSL https://install.python-poetry.org | python3 -
poetry env use $(pyenv which python)
sudo usermod -a -G sshusers ubuntu # ubuntu groups seem to be overided
# init config
mkdir -p /opt/vllm
sudo mkdir -p /opt/vllm
sudo chown -R ubuntu:sshusers /opt
sudo chmod -R 0775 /opt
cd /opt/vllm
cat <<'EOF' > docker-compose.yaml
{dockerCompose}
Expand All @@ -125,13 +180,16 @@ def indentString(input_string, indent_level=4):
echo "HUGGING_FACE_HUB_TOKEN='{huggingFaceHubToken}'" >> .env
echo "MODEL='{model}'" >> .env
# share repo between users
chown -R ubuntu:sshusers /opt
chmod -R 0775 /opt
# up docker compose services
docker compose up -d --build
touch /tmp/runcmd_finished
# clone working git repo
cd /opt/vllm
if [ -n "{gitRepo}" ]; then
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
sudo su - ubuntu -c "git clone {gitRepo}"
fi
- path: /etc/ssh/sshd_config.d/90-custom-settings.conf
content: |
AuthenticationMethods publickey
Expand Down

0 comments on commit e40d49e

Please sign in to comment.