-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Yuan <45984206+Yuan325@users.noreply.github.com>
- Loading branch information
1 parent
da374d9
commit 4245020
Showing
13 changed files
with
782 additions
and
121 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Deploy to Cloud Run | ||
|
||
## Pre-reqs | ||
|
||
* Google Cloud Project | ||
* Enabled APIs: | ||
* Cloud Run | ||
* Vertex AI | ||
* Cloud SQL or AlloyDB | ||
* Compute | ||
* Cloud Build | ||
* Artifact Registry | ||
* Service Networking | ||
* Cloud SQL PostgreSQL instance or AlloyDB cluster and primary instance | ||
|
||
## Datastore Setup | ||
|
||
|
||
## Deployment | ||
|
||
1. For easier deployment, set environment variables: | ||
|
||
```bash | ||
export PROJECT_ID=<YOUR_PROJECT_ID> | ||
``` | ||
|
||
1. Create a backend service account: | ||
|
||
```bash | ||
gcloud iam service-accounts create extension-identity | ||
``` | ||
|
||
1. Grant permissions to access Cloud SQL and/or AlloyDB: | ||
|
||
```bash | ||
gcloud projects add-iam-policy-binding $PROJECT_ID \ | ||
--member serviceAccount:extension-identity@$PROJECT_ID.iam.gserviceaccount.com \ | ||
--role roles/cloudsql.client | ||
``` | ||
|
||
```bash | ||
gcloud projects add-iam-policy-binding $PROJECT_ID \ | ||
--member serviceAccount:extension-identity@$PROJECT_ID.iam.gserviceaccount.com \ | ||
--role roles/alloydb.client | ||
``` | ||
|
||
1. Change into the service directory: | ||
|
||
```bash | ||
cd extension_service | ||
``` | ||
|
||
1. Deploy backend service to Cloud Run: | ||
|
||
* For Cloud SQL: | ||
|
||
```bash | ||
gcloud run deploy extension-service \ | ||
--source . \ | ||
--no-allow-unauthenticated \ | ||
--service-account extension-identity \ | ||
--region us-central1 \ | ||
--add-cloudsql-instances <PROJECT_ID:REGION:CLOUD_SQL_INSTANCE_NAME> | ||
``` | ||
|
||
* For AlloyDB: | ||
|
||
```bash | ||
gcloud alpha run deploy extension-service \ | ||
--source . \ | ||
--no-allow-unauthenticated \ | ||
--service-account extension-identity \ | ||
--region us-central1 \ | ||
--network=default \ | ||
--subnet=default | ||
``` | ||
|
||
1. Retrieve extension URL: | ||
|
||
```bash | ||
export EXTENSION_URL=$(gcloud run services describe extension-service --format 'value(status.url)') | ||
``` | ||
|
||
1. Create a frontend service account: | ||
|
||
```bash | ||
gcloud iam service-accounts create demo-identity | ||
``` | ||
|
||
1. Grant the service account access to invoke the backend service and VertexAI API: | ||
|
||
```bash | ||
gcloud run services add-iam-policy-binding extension-service \ | ||
--member serviceAccount:demo-identity@$PROJECT_ID.iam.gserviceaccount.com \ | ||
--role roles/run.invoker | ||
``` | ||
```bash | ||
gcloud projects add-iam-policy-binding $PROJECT_ID \ | ||
--member serviceAccount:demo-identity@$PROJECT_ID.iam.gserviceaccount.com \ | ||
--role roles/aiplatform.user | ||
``` | ||
|
||
1. Change into the service directory: | ||
|
||
```bash | ||
cd langchain_tools-demos | ||
``` | ||
|
||
1. Deploy to Cloud Run: | ||
|
||
```bash | ||
gcloud run deploy demo-service \ | ||
--source . \ | ||
--allow-unauthenticated \ | ||
--set-env-vars=BASE_URL=$EXTENSION_URL \ | ||
--service-account demo-identity | ||
``` | ||
|
||
Note: Your organization may not allow unauthenticated requests. Deploy with `--no-allow-unauthenticated` and use the proxy to view the frontend: `gcloud run services proxy demo-service`. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Use the official lightweight Python image. | ||
# https://hub.docker.com/_/python | ||
FROM python:3.11-slim | ||
|
||
# Allow statements and log messages to immediately appear in the logs | ||
ENV PYTHONUNBUFFERED True | ||
|
||
WORKDIR /app | ||
|
||
# Install production dependencies. | ||
COPY ./requirements.txt requirements.txt | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Copy local code to the container image. | ||
COPY . ./ | ||
|
||
# Run the web service on container startup. | ||
CMD exec uvicorn main:app --host 0.0.0.0 --port $PORT |
Oops, something went wrong.