Skip to content

Commit 699f494

Browse files
authored
Merge pull request #73 from wiseflat/dev/mgarcia/saas-litellm
feat(ansible): Create litellm saas role
2 parents efae485 + dec9abb commit 699f494

11 files changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Role: `litellm`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
# Environments variables
3+
litellm_env:
4+
- key: LITELLM_MASTER_KEY
5+
value: sk-1234
6+
- key: LITELLM_SALT_KEY
7+
value: sk-1234
8+
- key: DATABASE_URL
9+
value: postgresql://llmproxy:dbpassword9090@db:5432/litellm
10+
- key: STORE_MODEL_IN_DB
11+
value: true
12+
- key: OVHCLOUD_API_KEY
13+
value: changeme
14+
15+
# Default configuration
16+
litellm_config:
17+
model_list:
18+
- model_name: ovhcloud/gpt-oss-120b
19+
litellm_params:
20+
model: ovhcloud/gpt-oss-120b
21+
api_key: os.environ/OVHCLOUD_API_KEY
22+
23+
litellm_dbhost: localhost
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: Include upstream variables
3+
ansible.builtin.include_vars: upstream.yml
4+
5+
- name: Set custom variables
6+
ansible.builtin.set_fact:
7+
image_version: "{{ latest_version }}"
8+
image_name: "{{ image.name }}"
9+
image_labels: "{{ image.labels }}"
10+
image_build: "{{ image.build }}"
11+
12+
- name: End playbook if no new version
13+
ansible.builtin.meta: end_host
14+
when: softwares[image.name] is defined and softwares[image.name].version == image_version
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- name: Stop nomad job
3+
ansible.builtin.include_role:
4+
name: nomad
5+
tasks_from: job_stop.yml
6+
7+
- name: Remove software directory
8+
ansible.builtin.file:
9+
path: "{{ software_path }}"
10+
state: absent
11+
delegate_to: "{{ software.instance }}"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
- name: Install mandatories packages
3+
ansible.builtin.apt:
4+
pkg:
5+
- python3-psycopg2
6+
7+
- name: Create postgresql database
8+
community.postgresql.postgresql_db:
9+
login_password: "{{ lookup('simple-stack-ui', type='secret', key=software.litellm_dbhost, subkey='passwd', missing='error') }}"
10+
login_host: "{{ lookup('simple-stack-ui', type='secret', key=software.litellm_dbhost, subkey='service_name', missing='error') }}"
11+
login_user: postgres
12+
name: "{{ service_name }}"
13+
encoding: UTF8
14+
state: present
15+
16+
- name: Create postgresql user
17+
community.postgresql.postgresql_user:
18+
login_password: "{{ lookup('simple-stack-ui', type='secret', key=software.litellm_dbhost, subkey='passwd', missing='error') }}"
19+
login_host: "{{ lookup('simple-stack-ui', type='secret', key=software.litellm_dbhost, subkey='service_name', missing='error') }}"
20+
login_user: postgres
21+
login_db: "{{ service_name }}"
22+
name: "{{ service_name }}"
23+
password: "{{ lookup('simple-stack-ui', type='secret', key=domain, subkey='litellm_dbpasswd', missing='create', length=12) }}"
24+
state: present
25+
26+
- name: Create postgresql privileges
27+
community.postgresql.postgresql_privs:
28+
login_password: "{{ lookup('simple-stack-ui', type='secret', key=software.litellm_dbhost, subkey='passwd', missing='error') }}"
29+
login_host: "{{ lookup('simple-stack-ui', type='secret', key=software.litellm_dbhost, subkey='service_name', missing='error') }}"
30+
login_user: postgres
31+
db: "{{ service_name }}"
32+
roles: "{{ service_name }}"
33+
type: schema
34+
objs: public
35+
privs: CREATE
36+
state: present
37+
38+
- name: Copy nomad job
39+
ansible.builtin.template:
40+
src: nomad.hcl
41+
dest: "/var/tmp/{{ domain }}.nomad"
42+
owner: root
43+
group: root
44+
mode: '0600'
45+
become: true
46+
47+
- name: Run nomad job
48+
ansible.builtin.include_role:
49+
name: nomad
50+
tasks_from: job_run.yml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
---
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
job "{{ domain }}" {
2+
region = "{{ fact_instance.region }}"
3+
datacenters = ["{{ fact_instance.datacenter }}"]
4+
type = "service"
5+
6+
{% if software.constraints is defined and software.constraints.location is defined %}
7+
constraint {
8+
attribute = "${meta.location}"
9+
set_contains = "{{ software.constraints.location }}"
10+
}
11+
{% endif %}
12+
13+
constraint {
14+
attribute = "${meta.instance}"
15+
set_contains = "{{ software.instance }}"
16+
}
17+
18+
group "{{ domain }}" {
19+
count = 1
20+
21+
network {
22+
port "litellm" {
23+
to = 4000
24+
{% if software.static_port is defined %}
25+
static = {{ software.static_port }}
26+
{% endif %}
27+
}
28+
}
29+
30+
service {
31+
name = "{{ service_name }}"
32+
port = "litellm"
33+
provider = "nomad"
34+
tags = [
35+
{{ lookup('template', '../../traefik/templates/traefik_tag.j2') | indent(8) }}
36+
]
37+
check {
38+
type = "http"
39+
path = "/health/liveliness"
40+
interval = "30s"
41+
timeout = "10s"
42+
}
43+
}
44+
45+
task "{{ domain }}-milvus" {
46+
driver = "docker"
47+
48+
template {
49+
change_mode = "restart"
50+
destination = "local/config.yaml"
51+
perms = "644"
52+
data = <<EOH
53+
{{ (software.litellm_config | to_nice_yaml) | default(litellm_config) }}
54+
EOH
55+
}
56+
57+
config {
58+
image = "ghcr.io/berriai/litellm:v{{ softwares.litellm.version }}"
59+
ports = ["litellm"]
60+
args = [
61+
"--config=/local/config.yaml"
62+
]
63+
}
64+
65+
env {
66+
{% for env in (lookup('simple-stack-ui', type='secret', key=domain, subkey='litellm_env', missing='warn') | from_json) | default(litellm_env) %}
67+
{{ env.key }} = "{{ env.value }}"
68+
{% endfor %}
69+
}
70+
71+
resources {
72+
cpu = {{ size[software.size].cpu }}
73+
memory = {{ size[software.size].memory }}
74+
memory_max = {{ size[software.size].memory * 2 }}
75+
}
76+
}
77+
}
78+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
image:
3+
build: false
4+
upstream:
5+
source: github
6+
user: BerriAI
7+
repo: litellm
8+
os: linux
9+
labels: {}
10+
name: litellm
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
upstream_versions: "{{ (lookup('url', 'https://api.github.com/repos/' + image.upstream.user + '/' + image.upstream.repo + '/tags', headers={'Accept': 'application/vnd.github+json', 'Authorization': 'Bearer ' + lookup('ansible.builtin.env', 'GITHUB_API_TOKEN') })) }}"
3+
latest_version: "{{ upstream_versions | community.general.json_query('[].name') | select('match', '^(v|r)?\\d{1,4}(\\.\\d{1,4})(\\.\\d{1,4})(-stable)$') | community.general.version_sort | last | replace('v', '') }}"

0 commit comments

Comments
 (0)