Last active
May 6, 2025 15:42
-
-
Save korc/084683a1f51ac95c2bb33be5c26e5909 to your computer and use it in GitHub Desktop.
Start a simple dockerized stack of ollama / code-server. Run with `docker compose up` and access with browser via http://127.0.0.1:8080
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION IF NOT EXISTS plpython3u; | |
CREATE EXTENSION IF NOT EXISTS vector; | |
CREATE OR REPLACE FUNCTION ollama_embed(model text, prompt text[]) RETURNS SETOF vector | |
LANGUAGE plpython3u | |
AS $$ | |
from http.client import HTTPConnection | |
import json | |
conn = HTTPConnection("ollama:11434") | |
conn.request("POST", "/api/embed", json.dumps(dict(model=model, input=prompt))) | |
response = conn.getresponse() | |
result = response.read().decode('utf-8') | |
return json.loads(result)["embeddings"] | |
$$; | |
CREATE OR REPLACE FUNCTION ollama_embed(model text, prompt text) RETURNS vector | |
LANGUAGE sql | |
AS $$ | |
SELECT v from ollama_embed(model, ARRAY[prompt]) v | |
$$; | |
CREATE OR REPLACE FUNCTION ollama_list_models() RETURNS SETOF jsonb | |
LANGUAGE plpython3u | |
AS $$ | |
from http.client import HTTPConnection | |
import json | |
conn = HTTPConnection("ollama:11434") | |
conn.request("GET", "/api/tags") | |
response = conn.getresponse() | |
result = response.read().decode('utf-8') | |
return [json.dumps(z) for z in json.loads(result)["models"]] | |
$$; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
networks: | |
int: | |
## set net_internal=false in .env to allow direct internet access | |
internal: ${net_internal:-true} | |
volumes: | |
## set local_code in .env to local code directory if needed | |
code: | |
ollama: | |
sock: | |
pg_data: | |
services: | |
code-server: | |
build: | |
dockerfile: Dockerfile.code-server | |
volumes: | |
- ${local_code:-code}:/home/coder/Code | |
- sock:/run/sock | |
command: | |
- --auth | |
- none | |
- --socket | |
- /run/sock/cs.sock | |
networks: | |
- int | |
depends_on: | |
setup-volumes: | |
condition: service_completed_successfully | |
proxy: | |
condition: service_started | |
db: | |
build: | |
dockerfile: Dockerfile.db | |
volumes: | |
- pg_data:/var/lib/postgresql/data | |
networks: | |
- int | |
environment: | |
- POSTGRES_PASSWORD=password | |
- POSTGRES_DB=vectordb | |
ollama: | |
build: | |
dockerfile: Dockerfile.ollama | |
volumes: | |
- ollama:/root/.ollama | |
ports: # share ollama instance for other (desktop) apps. comment out to disable. | |
- ${ollama_listen:-127.0.0.1:11434}:11434 | |
networks: # internet access allowed by default for downloading models / shared usage. comment out 'default' if done. | |
- int | |
- default | |
## comment out if you don't have or can't use GPU | |
# deploy: | |
# resources: | |
# reservations: | |
# devices: | |
# - driver: nvidia | |
# count: 1 | |
# capabilities: [gpu] | |
web-front: | |
image: korc/onefile-websrv | |
command: | |
- -listen | |
- :8080 | |
- -map | |
- "/=http:unix:/run/sock/cs.sock:" | |
ports: | |
- 127.0.0.1:8080:8080 | |
volumes: | |
- sock:/run/sock | |
setup-volumes: | |
build: | |
dockerfile: Dockerfile.setup-volumes | |
volumes: | |
- sock:/vol/sock | |
- code:/vol/code | |
proxy: | |
build: | |
dockerfile: Dockerfile.proxy | |
networks: | |
- int | |
- default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Local Assistant | |
version: 1.0.0 | |
schema: v1 | |
models: | |
- name: auto | |
provider: ollama | |
model: AUTODETECT | |
apiBase: http://ollama:11434 | |
roles: | |
- chat | |
- edit | |
- apply | |
- name: Qwen2.5-Coder 1.5B | |
provider: ollama | |
apiBase: http://ollama:11434 | |
model: qwen2.5-coder:1.5b-base | |
roles: | |
- autocomplete | |
- name: Nomic Embed | |
provider: ollama | |
apiBase: http://ollama:11434 | |
model: nomic-embed-text:latest | |
roles: | |
- embed | |
context: | |
- provider: code | |
- provider: docs | |
- provider: diff | |
- provider: terminal | |
- provider: problems | |
- provider: folder | |
- provider: codebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM codercom/code-server | |
RUN --mount=type=cache,target=/var/lib/apt/lists --mount=type=cache,target=/var/cache/apt/archives \ | |
sudo apt-get update && \ | |
sudo apt-get install -y --no-install-recommends \ | |
acl iproute2 bash-completion command-not-found iputils-ping strace \ | |
jq yq pgcli | |
RUN code-server \ | |
--install-extension Continue.continue \ | |
--install-extension dbcode.dbcode \ | |
--install-extension mtxr.sqltools \ | |
--install-extension mtxr.sqltools-driver-pg | |
COPY --chown=1000:1000 continue-config.yaml /home/coder/.continue/config.yaml | |
COPY --chown=1000:1000 user-settings.json /home/coder/.local/share/code-server/User/settings.json | |
RUN sudo apt update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM pgvector/pgvector:pg17 | |
RUN --mount=type=cache,target=/var/lib/apt/lists --mount=type=cache,target=/var/cache/apt/archives \ | |
apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
postgresql-plpython3-17 | |
COPY 50-init-pgvec-ollama.sql /docker-entrypoint-initdb.d/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ollama/ollama | |
ARG models=llama3.1:8b qwen2.5-coder:1.5b-base nomic-embed-text:latest | |
ENV models=${models} | |
ENTRYPOINT [ "sh", "-c", "ollama serve & pid=$! && for model in $models; do ollama pull $model; done; wait $pid" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang AS builder | |
WORKDIR /src | |
COPY proxy.go /src | |
RUN \ | |
go mod init proxy && \ | |
go mod tidy && \ | |
CGO_ENABLED=0 go build -o /go/bin/proxy | |
FROM scratch | |
COPY --from=builder /go/bin/proxy /bin/ | |
ENTRYPOINT [ "/bin/proxy" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine | |
ENTRYPOINT [ "sh", "-c", "chown 1000:1000 /vol/sock /vol/code" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/elazarl/goproxy" | |
"log" | |
"net/http" | |
) | |
func main() { | |
proxy := goproxy.NewProxyHttpServer() | |
proxy.Verbose = true | |
log.Fatal(http.ListenAndServe(":3128", proxy)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS texts ( | |
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), | |
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | |
t TEXT NOT NULL, | |
v vector | |
); | |
DELETE FROM texts; | |
INSERT INTO texts (t) VALUES | |
('PostgreSQL is an open-source relational database management system (RDBMS) that provides a powerful, scalable, and highly customizable platform for storing, managing, and querying data, offering features such as support for SQL, indexing, caching, and advanced security.'), | |
('The solar system consists of eight planets (Mercury, Mars, Venus, Earth, Neptune, Uranus, Saturn, and Jupiter), dwarf planets, asteroids, comets, and other smaller bodies orbiting around the Sun, a massive ball of hot, glowing gas at the center.'), | |
('Linux is an open-source, customizable, and highly secure operating system that provides a robust platform for various applications, devices, and use cases, allowing users to personalize and tailor it to their specific needs.'); | |
-- this could take a while depending on your hardware.. | |
UPDATE texts SET v = ollama_embed('nomic-embed-text:latest', t); | |
WITH q(qv) AS (SELECT ollama_embed('nomic-embed-text:latest', 'information on planets')) | |
SELECT qv<->v as l2, qv<=>v as cos, qv<+>v as l1, * FROM texts,q ORDER BY 1; | |
WITH q(qv) AS (SELECT ollama_embed('nomic-embed-text:latest', 'operating system')) | |
SELECT qv<->v as l2, qv<=>v as cos, qv<+>v as l1, * FROM texts,q ORDER BY 1; | |
WITH q(qv) AS (SELECT ollama_embed('nomic-embed-text:latest', 'database')) | |
SELECT qv<->v as l2, qv<=>v as cos, qv<+>v as l1, * FROM texts,q ORDER BY 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"terminal.integrated.allowChords": false, | |
"telemetry.telemetryLevel": "off", | |
"continue.telemetryEnabled": false, | |
"window.menuBarVisibility": "visible", | |
"json.schemaDownload.enable": false, | |
"debug.javascript.automaticallyTunnelRemoteServer": false, | |
"http.proxy": "http://proxy:3128", | |
"extensions.autoUpdate": false, | |
"extensions.autoCheckUpdates": false, | |
"remote.autoForwardPorts": false, | |
"remote.forwardOnOpen": false, | |
"dbcode.ai.inlineCompletion": false, | |
"dbcode.connections": [ | |
{ | |
"connectionId": "coZnS9fy7AtLZG8qy0Zdp", | |
"name": "db", | |
"driver": "postgres", | |
"connectionType": "host", | |
"host": "db", | |
"port": 5432, | |
"ssl": false, | |
"username": "postgres", | |
"password": "password", | |
"savePassword": "yes", | |
"database": "vectordb", | |
"connectionTimeout": 30 | |
} | |
], | |
"sqltools.connections": [ | |
{ | |
"previewLimit": 50, | |
"server": "db", | |
"port": 5432, | |
"driver": "PostgreSQL", | |
"name": "db", | |
"database": "vectordb", | |
"username": "postgres", | |
"password": "password" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment