-
Notifications
You must be signed in to change notification settings - Fork 8
187 lines (163 loc) · 6.09 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: CI
on:
push:
branches:
- "*"
jobs:
###############################################################
## Test Backend
###############################################################
test:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.modified, 'backend/') || contains(github.event.head_commit.added, '.github/')
env:
APP_ENV: development
APP_SECRET: this-is-a-test-secret
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
BUCKET: pe-oss-bucket
S3_REGION: us-east-1
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_SECRET_KEY: ${{ secrets.ACCESS_SECRET_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Cache Python dependencies
id: cache-python
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/backend/requirements.txt', '**/backend/requirements-dev.txt', '**/backend/constraints.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
working-directory: ./backend
run: |
pip install --upgrade pip
pip install uv
uv pip install -v --system --no-cache-dir \
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt
- name: Run tests
working-directory: ./backend
env:
PYTHONPATH: ./src:.
run: |
# Create the database directory
mkdir -p data
# Run your tests
pytest
###############################################################
## Build Docker Image
###############################################################
build:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/development' && contains(github.event.head_commit.modified, 'backend/')
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Build and push Docker image
working-directory: ./backend
run: |
COMMIT_SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
DOCKER_IMAGE=docker.io/promptengineers/llm-server:${COMMIT_SHORT_SHA}
echo "Building image: $DOCKER_IMAGE"
# docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_IMAGE .
docker build --push -t $DOCKER_IMAGE .
###############################################################
## Deploy to Cloud Run
###############################################################
deploy:
runs-on: ubuntu-latest
needs: [test, build]
if: github.ref == 'refs/heads/development' && contains(github.event.head_commit.modified, 'backend/')
env:
APP_ENV: development
APP_SECRET: ${{ secrets.APP_SECRET }}
APP_ADMIN_EMAIL: admin@example.com
APP_ADMIN_PASS: test1234
APP_WORKERS: 1
DATABASE_URL: ${{ secrets.DATABASE_URL }}
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE_ENV: ${{ secrets.PINECONE_ENV }}
PINECONE_INDEX: ${{ secrets.PINECONE_INDEX }}
REDIS_URL: ${{ secrets.REDIS_URL }}
DOCKER_USERNAME: promptengineers
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
# OLLAMA_BASE_URL: ${{ secrets.OLLAMA_BASE_URL }}
# MINIO_HOST: ${{ secrets.MINIO_HOST }}
BUCKET: ${{ secrets.BUCKET }}
S3_REGION: ${{ secrets.S3_REGION }}
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
ACCESS_SECRET_KEY: ${{ secrets.ACCESS_SECRET_KEY }}
steps:
- name: Authenticate to Google Cloud
id: 'auth'
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ env.GCP_SA_KEY }}
- name: Setup Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
version: 'latest'
- name: Deploy to Cloud Run
run: |
COMMIT_SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
DOCKER_IMAGE=docker.io/promptengineers/llm-server:${COMMIT_SHORT_SHA}
gcloud config set project ${{ env.GCP_PROJECT }}
echo "Deploying $DOCKER_IMAGE to Cloud Run Server"
declare -a ENV_VARS=(
## App
"APP_ENV=$APP_ENV"
"APP_VERSION=$COMMIT_SHORT_SHA"
"APP_SECRET=$APP_SECRET"
"APP_ADMIN_EMAIL=$APP_ADMIN_EMAIL"
"APP_ADMIN_PASS=$APP_ADMIN_PASS"
"APP_WORKERS=$APP_WORKERS"
## Database
"DATABASE_URL=$DATABASE_URL"
"PINECONE_API_KEY=$PINECONE_API_KEY"
"PINECONE_ENV=$PINECONE_ENV"
"PINECONE_INDEX=$PINECONE_INDEX"
"REDIS_URL=$REDIS_URL"
## LLM
"OPENAI_API_KEY=$OPENAI_API_KEY"
"GROQ_API_KEY=$GROQ_API_KEY"
"ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY"
# "OLLAMA_BASE_URL=$OLLAMA_BASE_URL" # Commented out if not using Ollama (Requires GPU server)
## Storage
# "MINIO_HOST=$MINIO_HOST" # Commented out if not using Minio (Requires Minio server)
"BUCKET=$BUCKET"
"S3_REGION=$S3_REGION"
"ACCESS_KEY_ID=$ACCESS_KEY_ID"
"ACCESS_SECRET_KEY=$ACCESS_SECRET_KEY"
)
# Join array elements into a comma-separated string
VARS=$(IFS=,; echo "${ENV_VARS[*]}")
# Deploy
gcloud run deploy llm-server \
--image docker.io/promptengineers/llm-server:${COMMIT_SHORT_SHA} \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars $VARS