Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit f589a03

Browse files
authored
Merge branch 'main' into issue-580
2 parents 546f1db + 7593f72 commit f589a03

File tree

17 files changed

+346
-128
lines changed

17 files changed

+346
-128
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ RUN chown -R codegate /var/lib/nginx && \
7878
chown -R codegate /var/log/nginx && \
7979
chown -R codegate /run
8080

81-
COPY nginx.conf /etc/nginx/conf.d/default.conf
81+
COPY nginx.conf /etc/nginx/nginx.conf
8282

8383
# Remove include /etc/nginx/sites-enabled/*; from the default nginx.conf
8484
# This way we don't introduce unnecessary configurations nor serve

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.PHONY: clean install format lint test security build all
22
CONTAINER_BUILD?=docker buildx build
3-
VER?=0.1.7
3+
# This is the container tag. Only used for development purposes.
4+
VER?=latest
45

56
clean:
67
rm -rf build/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ With Continue, you can choose from several leading AI model providers:
6767

6868
🔮 Many more on the way!
6969

70-
- **[Aider](https://aider.chat)
70+
- **[Aider](https://aider.chat)**
7171

7272
With Aider, you can choose from two leading AI model providers:
7373

alembic.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Database configuration.
2+
# See the full list of options at:
3+
# https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
4+
5+
[alembic]
6+
# path to migration scripts
7+
# Use forward slashes (/) also on windows to provide an os agnostic path
8+
script_location = migrations
9+
10+
# sys.path path, will be prepended to sys.path if present.
11+
# defaults to the current working directory.
12+
prepend_sys_path = .
13+
14+
# version path separator; is the character used to split
15+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
16+
version_path_separator = os # Use os.pathsep.
17+
18+
# DB connection string
19+
sqlalchemy.url = sqlite:///codegate_volume/db/codegate.db

migrations/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

migrations/env.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from alembic import context
2+
from sqlalchemy import engine_from_config, pool
3+
4+
# this is the Alembic Config object, which provides
5+
# access to the values within the .ini file in use.
6+
config = context.config
7+
8+
# add your model's MetaData object here
9+
# for 'autogenerate' support
10+
# from myapp import mymodel
11+
# target_metadata = mymodel.Base.metadata
12+
target_metadata = None
13+
14+
# other values from the config, defined by the needs of env.py,
15+
# can be acquired:
16+
# my_important_option = config.get_main_option("my_important_option")
17+
# ... etc.
18+
19+
20+
def run_migrations_offline() -> None:
21+
"""Run migrations in 'offline' mode.
22+
23+
This configures the context with just a URL
24+
and not an Engine, though an Engine is acceptable
25+
here as well. By skipping the Engine creation
26+
we don't even need a DBAPI to be available.
27+
28+
Calls to context.execute() here emit the given string to the
29+
script output.
30+
31+
"""
32+
url = config.get_main_option("sqlalchemy.url")
33+
context.configure(
34+
url=url,
35+
target_metadata=target_metadata,
36+
literal_binds=True,
37+
dialect_opts={"paramstyle": "named"},
38+
)
39+
40+
with context.begin_transaction():
41+
context.run_migrations()
42+
43+
44+
def run_migrations_online() -> None:
45+
"""Run migrations in 'online' mode.
46+
47+
In this scenario we need to create an Engine
48+
and associate a connection with the context.
49+
50+
"""
51+
connectable = engine_from_config(
52+
config.get_section(config.config_ini_section, {}),
53+
prefix="sqlalchemy.",
54+
poolclass=pool.NullPool,
55+
)
56+
print(config.config_ini_section)
57+
with connectable.connect() as connection:
58+
context.configure(connection=connection, target_metadata=target_metadata)
59+
60+
with context.begin_transaction():
61+
context.run_migrations()
62+
63+
64+
if context.is_offline_mode():
65+
run_migrations_offline()
66+
else:
67+
run_migrations_online()

migrations/script.py.mako

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
${imports if imports else ""}
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = ${repr(up_revision)}
16+
down_revision: Union[str, None] = ${repr(down_revision)}
17+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19+
20+
21+
def upgrade() -> None:
22+
${upgrades if upgrades else "pass"}
23+
24+
25+
def downgrade() -> None:
26+
${downgrades if downgrades else "pass"}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""init db
2+
3+
Revision ID: 30d0144e1a50
4+
Revises:
5+
Create Date: 2025-01-15 09:30:00.490697
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision: str = "30d0144e1a50"
15+
down_revision: Union[str, None] = None
16+
branch_labels: Union[str, Sequence[str], None] = None
17+
depends_on: Union[str, Sequence[str], None] = None
18+
19+
20+
def upgrade() -> None:
21+
# Schema for codegate database using SQLite
22+
# Prompts table
23+
op.execute(
24+
"""
25+
CREATE TABLE prompts (
26+
id TEXT PRIMARY KEY, -- UUID stored as TEXT
27+
timestamp DATETIME NOT NULL,
28+
provider TEXT, -- VARCHAR(255)
29+
request TEXT NOT NULL, -- Record the full request that arrived to the server
30+
type TEXT NOT NULL -- VARCHAR(50) (e.g. "fim", "chat")
31+
);
32+
"""
33+
)
34+
# Outputs table
35+
op.execute(
36+
"""
37+
CREATE TABLE outputs (
38+
id TEXT PRIMARY KEY, -- UUID stored as TEXT
39+
prompt_id TEXT NOT NULL,
40+
timestamp DATETIME NOT NULL,
41+
output TEXT NOT NULL, -- Record the full response. If stream will be a list of objects
42+
FOREIGN KEY (prompt_id) REFERENCES prompts(id)
43+
);
44+
"""
45+
)
46+
# Alerts table
47+
op.execute(
48+
"""
49+
CREATE TABLE alerts (
50+
id TEXT PRIMARY KEY, -- UUID stored as TEXT
51+
prompt_id TEXT NOT NULL,
52+
code_snippet TEXT,
53+
trigger_string TEXT, -- VARCHAR(255)
54+
trigger_type TEXT NOT NULL, -- VARCHAR(50)
55+
trigger_category TEXT,
56+
timestamp DATETIME NOT NULL,
57+
FOREIGN KEY (prompt_id) REFERENCES prompts(id)
58+
);
59+
"""
60+
)
61+
# Settings table
62+
op.execute(
63+
"""
64+
CREATE TABLE settings (
65+
id TEXT PRIMARY KEY, -- UUID stored as TEXT
66+
ip TEXT, -- VARCHAR(45)
67+
port INTEGER,
68+
llm_model TEXT, -- VARCHAR(255)
69+
system_prompt TEXT,
70+
other_settings TEXT -- JSON stored as TEXT
71+
);
72+
"""
73+
)
74+
# Create indexes for foreign keys and frequently queried columns
75+
op.execute("CREATE INDEX idx_outputs_prompt_id ON outputs(prompt_id);")
76+
op.execute("CREATE INDEX idx_alerts_prompt_id ON alerts(prompt_id);")
77+
op.execute("CREATE INDEX idx_prompts_timestamp ON prompts(timestamp);")
78+
op.execute("CREATE INDEX idx_outputs_timestamp ON outputs(timestamp);")
79+
op.execute("CREATE INDEX idx_alerts_timestamp ON alerts(timestamp);")
80+
81+
82+
def downgrade() -> None:
83+
pass

nginx.conf

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,68 @@
1-
server {
2-
listen 9090;
1+
worker_processes 1;
2+
pid /run/nginx.pid;
3+
error_log /var/log/nginx/error.log;
4+
include /etc/nginx/modules-enabled/*.conf;
35

4-
server_name localhost;
6+
events {
7+
worker_connections 128;
8+
}
9+
10+
http {
11+
12+
##
13+
# Basic Settings
14+
##
15+
16+
sendfile on;
17+
tcp_nopush on;
18+
types_hash_max_size 2048;
19+
20+
##
21+
# Disable unnecessary features
22+
##
23+
24+
server_tokens off;
25+
autoindex off;
26+
27+
include /etc/nginx/mime.types;
28+
default_type application/octet-stream;
29+
30+
##
31+
# Logging Settings
32+
##
33+
34+
access_log off;
35+
error_log /var/log/nginx/error.log;
36+
37+
##
38+
# Gzip Settings
39+
##
40+
41+
gzip on;
42+
43+
server {
44+
listen 9090;
45+
46+
server_name localhost;
547

6-
root /var/www/html;
7-
index index.html;
48+
add_header X-Frame-Options SAMEORIGIN;
49+
add_header X-Content-Type-Options nosniff;
50+
add_header X-XSS-Protection "1; mode=block";
851

9-
location / {
10-
try_files $uri /index.html =404;
11-
}
52+
root /var/www/html;
53+
index index.html;
1254

13-
# Serve certificates from /app/codegate_volume/certs at /certificates
14-
location /certificates/codegate_ca.crt {
15-
alias /app/codegate_volume/certs/ca.crt;
16-
types { application/x-x509-ca-cert crt; }
17-
default_type application/x-x509-ca-cert;
18-
}
55+
location / {
56+
try_files $uri /index.html =404;
57+
expires 1h; # Cache files for 1 hour
58+
add_header Cache-Control "public, max-age=3600";
59+
}
1960

20-
error_log /var/log/nginx/error.log;
21-
access_log /var/log/nginx/access.log;
61+
# Serve certificates from /app/codegate_volume/certs at /certificates
62+
location /certificates/codegate_ca.crt {
63+
alias /app/codegate_volume/certs/ca.crt;
64+
types { application/x-x509-ca-cert crt; }
65+
default_type application/x-x509-ca-cert;
66+
}
67+
}
2268
}

poetry.lock

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)