Skip to content

Commit c155fce

Browse files
authored
Initial release
1 parent c0af0e3 commit c155fce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1155
-353
lines changed

.dockerignore

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
.DS_Store
21
.env
32
.env.dev
3+
.env.prod
44
.git
55
.github
66
.gitignore
77
.idea
88
.jekyll-cache
99
.jekyll-metadata
1010
.sass-cache
11-
tests
12-
__pycache__
1311
_releaser
1412
_site
13+
**/.DS_Store
14+
**/__pycache__
15+
**/node_modules
1516
CONTRIBUTING.md
1617
db.sqlite3
1718
Dockerfile
1819
docker-compose.yml
19-
client/node_modules
20-
/vendor
20+
docker-compose.dev.yml
21+
fixtures
22+
nginx
23+
tests
24+
web

.env.dev

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
DJANGO_SECRET_KEY='3!4^11rgx0-53)!n#18(1_^)&pj-3n^Afpc#mbm(+!fj4r$rp7ea!s'
21
DEBUG=True
2+
LOG_LEVEL=INFO
3+
SECRET_KEY='3!4^11rgx0-53)!n#18(1_^)&pj-3n^Afpc#mbm(+!fj4r$rp7ea!s'
4+
CIPHER_KEY_SALT=salt
35
SINGLE_THREAD=False
46
AUTORELOAD=True
5-
LOG_LEVEL=INFO
6-
DJANGO_LOG_LEVEL=INFO
7-
DJANGO_ALLOWED_HOSTS=*
8-
CORS_ORIGIN_WHITELIST=http://localhost:3000,http://localhost:9000
9-
7+
ALLOWED_HOSTS=*
108
DATABASE_ENGINE=postgresql
119
DATABASE_NAME=postgres
1210
DATABASE_USERNAME=postgres
1311
DATABASE_PASSWORD=
1412
DATABASE_HOST=postgres
1513
DATABASE_PORT=5432
16-
DJANGO_MANAGEPY_MIGRATE=off
17-
DJANGO_MANAGEPY_COLLECTSTATIC=on
18-
DJANGO_MANAGEPY_CREATECACHETABLE=on
19-
DJANGO_MANAGEPY_CLEARCACHE=on
20-
DJANGO_MANAGEPY_CLEARCACHE=on
21-
DJANGO_CIPHER_KEY_SALT=salt
22-
DJANGO_STATIC_URL=static/
2314
REDIS_PORT=6379
2415
REDIS_HOST=redis
25-
REDIS_DB=0
16+
REDIS_DB=0
17+
STATIC_URL=static/
18+
19+
# Persistent volumes
20+
POSTGRES_VOLUME=/tmp/postgres_llmstack_dev
21+
REDIS_VOLUME=/tmp/redis_llmstack_dev
22+
WEAVIATE_VOLUME=/tmp/weaviate_llmstack_dev
23+
24+
# Platform keys
25+
DEFAULT_OPENAI_API_KEY=
26+
DEFAULT_DREAMSTUDIO_API_KEY=
27+
DEFAULT_AZURE_OPENAI_API_KEY=
28+
DEFAULT_COHERE_API_KEY=
29+
DEFAULT_FOREFRONTAI_API_KEY=
30+
DEFAULT_ELEVENLABS_API_KEY=

.env.prod

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SECRET_KEY='3!4^11rgx0-53)!n#18(1_^)&pj-3n^Afpc#mbm(+!fj4r$rp7ea!s'
2+
CIPHER_KEY_SALT=salt
3+
DATABASE_PASSWORD=llmstack
4+
5+
# Persistent volumes
6+
POSTGRES_VOLUME=/tmp/postgres_llmstack
7+
REDIS_VOLUME=/tmp/redis_llmstack
8+
WEAVIATE_VOLUME=/tmp/weaviate_llmstack
9+
10+
# Platform keys
11+
DEFAULT_OPENAI_API_KEY=
12+
DEFAULT_DREAMSTUDIO_API_KEY=
13+
DEFAULT_AZURE_OPENAI_API_KEY=
14+
DEFAULT_COHERE_API_KEY=
15+
DEFAULT_FOREFRONTAI_API_KEY=
16+
DEFAULT_ELEVENLABS_API_KEY=
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Docker Images CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
# Publish semver tags as releases.
7+
tags: ["v*.*.*"]
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
ORG: trypromptly
12+
IMAGE_NAME_API: "llmstack-api"
13+
IMAGE_NAME_NGINX: "llmstack-nginx"
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
permissions:
20+
contents: read
21+
packages: write
22+
# This is used to complete the identity challenge
23+
# with sigstore/fulcio when running outside of PRs.
24+
id-token: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
30+
# Install the cosign tool except on PR
31+
# https://github.com/sigstore/cosign-installer
32+
- name: Install cosign
33+
if: github.event_name != 'pull_request'
34+
uses: sigstore/[email protected]
35+
with:
36+
cosign-release: "v2.1.1"
37+
38+
# Setup QEMU for cross compilation
39+
- name: Set up QEMU
40+
uses: docker/setup-qemu-action@v2
41+
42+
# Setup Docker Buildx
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v2
45+
46+
# Login against a Docker registry except on PR
47+
# https://github.com/docker/login-action
48+
- name: Log into registry ${{ env.REGISTRY }}
49+
if: github.event_name != 'pull_request'
50+
uses: docker/[email protected]
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
# Extract metadata (tags, labels) for Docker
57+
# https://github.com/docker/metadata-action
58+
- name: Extract Docker metadata for API
59+
id: meta-api
60+
uses: docker/metadata-action@v4
61+
with:
62+
images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME_API }}
63+
tags: |
64+
type=raw,value=latest,event=push,enabled={{is_default_branch}}
65+
type=semver,enabled={{starts_with(github.ref, 'refs/tags/v')}},pattern={{version}}
66+
67+
- name: Extract Docker metadata for nginx
68+
id: meta-nginx
69+
uses: docker/metadata-action@v4
70+
with:
71+
images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME_NGINX }}
72+
tags: |
73+
type=raw,value=latest,event=push,enabled={{is_default_branch}}
74+
type=semver,enabled={{starts_with(github.ref, 'refs/tags/v')}},pattern={{version}}
75+
76+
# Build client
77+
- name: Build client
78+
run: |
79+
cd client
80+
npm install
81+
npm run build
82+
83+
# Build and push Docker image with Buildx (don't push on PR)
84+
# https://github.com/docker/build-push-action
85+
- name: Build and push LLMStack API Docker image
86+
id: build-and-push-api
87+
uses: docker/build-push-action@v4
88+
with:
89+
context: .
90+
push: ${{ github.event_name != 'pull_request' }}
91+
tags: ${{ steps.meta-api.outputs.tags }}
92+
labels: ${{ steps.meta-api.outputs.labels }}
93+
cache-from: type=gha
94+
cache-to: type=gha,mode=max
95+
file: Dockerfile
96+
platforms: linux/amd64,linux/arm64
97+
98+
- name: Build and push LLMStack nginx Docker image
99+
id: build-and-push-nginx
100+
uses: docker/build-push-action@v4
101+
with:
102+
context: .
103+
push: ${{ github.event_name != 'pull_request' }}
104+
tags: ${{ steps.meta-nginx.outputs.tags }}
105+
labels: ${{ steps.meta-nginx.outputs.labels }}
106+
cache-from: type=gha
107+
cache-to: type=gha,mode=max
108+
file: Dockerfile.nginx
109+
platforms: linux/amd64,linux/arm64
110+
build-args: REGISTRY=${{ env.REGISTRY }}/${{ env.ORG }}/
111+
112+
- name: Sign the published LLMStack API Docker image
113+
if: ${{ github.event_name != 'pull_request' }}
114+
env:
115+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
116+
TAGS: ${{ steps.meta-api.outputs.tags }}
117+
DIGEST: ${{ steps.build-and-push-api.outputs.digest }}
118+
# This step uses the identity token to provision an ephemeral certificate
119+
# against the sigstore community Fulcio instance.
120+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
121+
122+
- name: Sign the published LLMStack nginx Docker image
123+
if: ${{ github.event_name != 'pull_request' }}
124+
env:
125+
TAGS: ${{ steps.meta-nginx.outputs.tags }}
126+
DIGEST: ${{ steps.build-and-push-nginx.outputs.digest }}
127+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ cython_debug/
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161161

162+
# Vscode
163+
.vscode
164+
162165
# LLMStack
163166
static/css
164167
static/js

Dockerfile

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
FROM python:3.9
1+
# Stage 1: Compile and build code
2+
FROM python:3.9 AS builder
3+
4+
ADD requirements_base.txt /requirements_base.txt
5+
RUN pip install --no-cache-dir -r /requirements_base.txt
6+
RUN playwright install chromium
7+
8+
ADD requirements_datasources.txt /requirements_datasources.txt
9+
RUN pip install --no-cache-dir -r /requirements_datasources.txt
10+
11+
ADD requirements_processors.txt /requirements_processors.txt.txt
12+
RUN pip install --no-cache-dir -r /requirements_processors.txt.txt
13+
14+
RUN mkdir /code/
15+
WORKDIR /code/
16+
ADD . /code/
17+
18+
ENV DJANGO_SETTINGS_MODULE=llmstack.settings
19+
RUN python manage.py collectstatic --noinput --clear
20+
21+
# Stage 2: Build final image
22+
FROM python:3.9-slim
223

3-
# Create a group and user to run our app
424
ARG APP_USER=appuser
525
RUN groupadd -r ${APP_USER} && useradd --no-log-init -r -g ${APP_USER} ${APP_USER} \
626
&& mkdir -p /home/${APP_USER} \
727
&& chown -R ${APP_USER}:${APP_USER} /home/${APP_USER}
828

9-
# Install packages needed to run your application
10-
RUN set -ex \
11-
&& RUN_DEPS=" \
12-
libpcre3 \
29+
RUN apt-get update && apt-get install -y libpcre3 \
1330
mime-support \
1431
ffmpeg \
1532
postgresql-client \
@@ -19,44 +36,24 @@ RUN set -ex \
1936
libcups2-dev \
2037
libxkbcommon-x11-0 \
2138
libxcomposite-dev \
22-
libxdamage-dev \
23-
" \
24-
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
25-
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
26-
&& rm -rf /var/lib/apt/lists/*
27-
28-
# Copy requirements files and build them
29-
ADD requirements_base.txt /requirements_base.txt
30-
RUN pip install --no-cache-dir -r /requirements_base.txt
39+
libxdamage-dev && rm -rf /var/lib/apt/lists/*
3140

32-
ADD requirements_datasources.txt /requirements_datasources.txt
33-
RUN pip install --no-cache-dir -r /requirements_datasources.txt
41+
COPY --from=builder /code/ /code/
42+
COPY --from=builder /root/.cache/pip /root/.cache/pip
43+
COPY --from=builder /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/
44+
COPY --from=builder /usr/local/bin/ /usr/local/bin/
3445

35-
ADD requirements_processors.txt /requirements_processors.txt.txt
36-
RUN pip install --no-cache-dir -r /requirements_processors.txt.txt
46+
COPY --from=builder /root/.cache/ms-playwright /home/${APP_USER}/.cache/ms-playwright
47+
RUN chown -R ${APP_USER}:${APP_USER} /home/${APP_USER}/.cache
3748

38-
# Copy app code
39-
RUN mkdir /code/
4049
WORKDIR /code/
41-
ADD . /code/
42-
43-
# aWSGI will listen on this port
44-
EXPOSE 9000
4550

46-
# Static environment variables needed by Django
4751
ENV DJANGO_SETTINGS_MODULE=llmstack.settings
4852

49-
# Collect static
50-
RUN python manage.py collectstatic --noinput --clear
53+
EXPOSE 9000
5154

52-
# Change to a non-root user
5355
USER ${APP_USER}:${APP_USER}
5456

55-
# Install playwright browser
56-
RUN playwright install chromium
57-
58-
# Run entrypoint script
5957
ENTRYPOINT ["/code/docker-entrypoint.sh"]
6058

61-
# Start aWSGI
6259
CMD ["/usr/local/bin/gunicorn", "promptly.asgi:application", "-w", "2", "-t", "120", "-b", ":9000", "-k", "uvicorn.workers.UvicornWorker"]

Dockerfile.nginx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG REGISTRY
2+
FROM ${REGISTRY:-}llmstack-api:${TAG:-latest} as builder
3+
FROM nginx:stable-alpine3.17-slim
4+
5+
RUN rm /etc/nginx/conf.d/default.conf
6+
COPY nginx.conf /etc/nginx/conf.d
7+
8+
# Copy static files from Django to nginx
9+
COPY --from=builder /code/static /usr/share/nginx/html/static

0 commit comments

Comments
 (0)