-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path.gitlab-ci.yml
182 lines (172 loc) · 5.3 KB
/
.gitlab-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
stages:
- test
- build
- deploy
variables:
BUCKET: pe-oss-bucket
S3_REGION: us-east-1
PYTHONPATH: "${CI_PROJECT_DIR}/backend/src:${CI_PROJECT_DIR}/backend"
GCP_PROJECT: pe-open-source-chat
GCP_SERVICE_NAME: llm-server-dev
REPOSITORY: promptengineers
LOCATION: us-central1
DOCKER_IMAGE: $LOCATION-docker.pkg.dev/$GCP_PROJECT/$REPOSITORY/llm-server
# Define the template to set DOCKER_IMAGE_TAG
.set_docker_image_tag_template: &set_docker_image_tag_template
- |
if [ "$CI_COMMIT_REF_NAME" == "development" ]; then
export DOCKER_IMAGE_TAG="$CI_COMMIT_SHORT_SHA"
else
export DOCKER_IMAGE_TAG="$CI_COMMIT_REF_NAME"
fi
cache:
paths:
- .cache/pip
test:
stage: test
image: python:3.10
variables:
APP_ENV: test
POSTGRES_USER: admin
POSTGRES_PASSWORD: test1234
POSTGRES_DB: llm_server_test
DATABASE_URL: postgresql+asyncpg://admin:test1234@postgres:5432/llm_server_test
POSTGRES_URL: postgresql+psycopg://admin:test1234@postgres:5432/llm_server_test
REDIS_URL: redis://redis:6379/0 # Add the Redis URL as a variable
environment:
name: $APP_ENV
services:
- name: pgvector/pgvector:pg16
alias: postgres
- name: redis:alpine # Add Redis service
alias: redis
before_script:
- python --version
- pip install --upgrade pip
- env | sort
script:
- cd backend
- mkdir -p data
- pip install uv
- |
uv pip install -v --system --no-cache-dir \
-c constraints.txt \
-r requirements.txt \
-r requirements-dev.txt
- pytest -rs
only:
changes:
- backend/**/*
except:
- tags
#################################################################
## Gitlab Container Registry
#################################################################
# build:
# stage: build
# image: docker:latest
# services:
# - docker:dind
# before_script:
# - docker login -u "$CI_REGISTRY_USER" -p "$CI_JOB_TOKEN" "$CI_REGISTRY"
# - *set_docker_image_tag_template
# script:
# - cd backend
# - docker build -t "$CI_REGISTRY_IMAGE:${DOCKER_IMAGE_TAG}" .
# - docker push "$CI_REGISTRY_IMAGE:${DOCKER_IMAGE_TAG}"
# only:
# - development
# - tags
#################################################################
## Google Container Registry
#################################################################
build-gcr:
stage: build
image: google/cloud-sdk:alpine
services:
- name: docker:dind
command: ["--tls=false"]
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
before_script:
- apk add --no-cache docker-cli
- echo "$GCP_SA_KEY" | base64 -d > /tmp/gcp_key.json
- gcloud auth activate-service-account --key-file=/tmp/gcp_key.json
- gcloud config set project $GCP_PROJECT
- gcloud auth configure-docker $LOCATION-docker.pkg.dev
- echo "$GCP_SA_KEY" | docker login -u _json_key_base64 --password-stdin https://$LOCATION-docker.pkg.dev
- *set_docker_image_tag_template
script:
- cd backend
- docker build -t "$DOCKER_IMAGE:$DOCKER_IMAGE_TAG" .
- docker push "$DOCKER_IMAGE:$DOCKER_IMAGE_TAG"
after_script:
- rm /tmp/gcp_key.json
only:
changes:
- backend/**/*
- .gitlab-ci.yml
only:
- development
- tags
deploy:
stage: deploy
image: google/cloud-sdk:latest
needs: [build-gcr]
environment:
name: $CI_COMMIT_REF_NAME
variables:
APP_ENV: development
APP_ADMIN_EMAIL: [email protected]
APP_ADMIN_PASS: test1234
APP_WORKERS: 1
before_script:
- *set_docker_image_tag_template
- echo "$GCP_SA_KEY" | base64 -d > /tmp/gcp_key.json
- gcloud auth activate-service-account --key-file=/tmp/gcp_key.json
- gcloud config set project $GCP_PROJECT
after_script:
- rm /tmp/gcp_key.json
script:
- echo "Deploying $DOCKER_IMAGE:$DOCKER_IMAGE_TAG to Cloud Run Server"
- |
declare -a ENV_VARS=(
"APP_ENV=$APP_ENV"
"APP_VERSION=$DOCKER_IMAGE_TAG"
"APP_SECRET=$APP_SECRET"
"APP_ADMIN_EMAIL=$APP_ADMIN_EMAIL"
"APP_ADMIN_PASS=$APP_ADMIN_PASS"
"APP_WORKERS=$APP_WORKERS"
"DATABASE_URL=$DATABASE_URL"
"REDIS_URL=$REDIS_URL"
"POSTGRES_URL=$POSTGRES_URL"
"AZURE_OPENAI_API_KEY=$AZURE_OPENAI_API_KEY"
"AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT"
"OPENAI_API_KEY=$OPENAI_API_KEY"
"GROQ_API_KEY=$GROQ_API_KEY"
"ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY"
"BUCKET=$BUCKET"
"S3_REGION=$S3_REGION"
"ACCESS_KEY_ID=$ACCESS_KEY_ID"
"ACCESS_SECRET_KEY=$ACCESS_SECRET_KEY"
"OAUTH_GITHUB_REDIRECT_URI=$OAUTH_GITHUB_REDIRECT_URI"
"OAUTH_GITHUB_CLIENT_ID=$OAUTH_GITHUB_CLIENT_ID"
"OAUTH_GITHUB_CLIENT_SECRET=$OAUTH_GITHUB_CLIENT_SECRET"
"OAUTH_GOOGLE_REDIRECT_URI=$OAUTH_GOOGLE_REDIRECT_URI"
"OAUTH_GOOGLE_CLIENT_ID=$OAUTH_GOOGLE_CLIENT_ID"
"OAUTH_GOOGLE_CLIENT_SECRET=$OAUTH_GOOGLE_CLIENT_SECRET"
)
# Join array elements into a comma-separated string
VARS=$(IFS=,; echo "${ENV_VARS[*]}")
# Deploy
gcloud run deploy $GCP_SERVICE_NAME \
--image $DOCKER_IMAGE:$DOCKER_IMAGE_TAG \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--set-env-vars $VARS
only:
- development
- tags