Skip to content

Commit 1d60a8a

Browse files
committed
init
0 parents  commit 1d60a8a

7 files changed

+750
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
venv/
2+
__pycache__/
3+
.DS_Store

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Dockerfile
2+
FROM python:3.13-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Set environment variables
8+
ENV PYTHONDONTWRITEBYTECODE=1 \
9+
PYTHONUNBUFFERED=1
10+
11+
# Install system dependencies
12+
RUN apt-get update && \
13+
apt-get install -y --no-install-recommends gcc && \
14+
apt-get clean && \
15+
rm -rf /var/lib/apt/lists/*
16+
17+
# Copy only the requirements file first
18+
COPY requirements.txt .
19+
20+
# Install Python dependencies
21+
RUN pip install --no-cache-dir -r requirements.txt
22+
23+
# Copy only the necessary files
24+
COPY main.py .
25+
COPY favicon.ico .
26+
27+
# Command to run the application
28+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0"]

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## setup
2+
3+
```shell
4+
# use a virt env
5+
python3 -m venv venv
6+
source venv/bin/activate
7+
8+
# install dependencies
9+
# pip install fastapi uvicorn google-genai
10+
# pip freeze > requirements.txt
11+
12+
# export API key if running locally (for AI / Gemini calls)
13+
export GOOGLE_API_KEY=<...>
14+
15+
16+
# run the app
17+
uvicorn main:app --reload
18+
# http://127.0.0.1:8000/
19+
20+
# exit
21+
deactivate
22+
23+
# /Users/jimangel/mql2promql/fastapi
24+
docker build -t mql-converter .
25+
docker run -p 8000:8000 -e GOOGLE_API_KEY=${GOOGLE_API_KEY} mql-converter
26+
```
27+
28+
```
29+
gcloud auth login
30+
gcloud config set project mql-cloudrun
31+
32+
gcloud artifacts repositories create mvp \
33+
--repository-format=docker \
34+
--location=us-south1 \
35+
--description="Docker container repository"
36+
37+
docker buildx create --name multiplatform-builder --driver docker-container --use
38+
39+
40+
docker buildx build --platform linux/amd64,linux/arm64 \
41+
-t us-south1-docker.pkg.dev/mql-cloudrun/mvp/mql-converter:latest \
42+
--push .
43+
44+
docker run -p 8080:8080 -e GOOGLE_API_KEY=${GOOGLE_API_KEY} -e UVICORN_PORT=8080 us-south1-docker.pkg.dev/mql-cloudrun/mvp/mql-converter
45+
46+
# allow default service account to read
47+
gcloud projects add-iam-policy-binding mql-cloudrun \
48+
--member="serviceAccount:$(gcloud projects describe mql-cloudrun --format='value(projectNumber)')[email protected]" \
49+
--role="roles/artifactregistry.reader"
50+
51+
# using port 8080 as set by cloudrun.
52+
gcloud run deploy mql2prom-conv-service \
53+
--project="$(gcloud projects describe mql-cloudrun --format='value(projectId)')" \
54+
--image=us-south1-docker.pkg.dev/mql-cloudrun/mvp/mql-converter:latest \
55+
--platform=managed \
56+
--region=us-south1 \
57+
--allow-unauthenticated \
58+
--set-env-vars=GOOGLE_API_KEY=${GOOGLE_API_KEY},UVICORN_PORT=8080
59+
```

favicon.ico

35.5 KB
Binary file not shown.

lb-setup-script.sh

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Set your variables
2+
REGION="us-south1" # From the Cloud Run service location
3+
CLOUD_RUN_SERVICE="mql2prom-conv-service"
4+
PROJECT_ID="623927437995" # From the namespace
5+
LB_NAME="mql-converter-lb"
6+
NETWORK_NAME="mql-network"
7+
SUBNET_NAME="mql-subnet"
8+
9+
# 2. Create VPC network and subnet
10+
gcloud compute networks create $NETWORK_NAME --subnet-mode=custom
11+
12+
gcloud compute networks subnets create $SUBNET_NAME \
13+
--network=$NETWORK_NAME \
14+
--range=10.1.2.0/24 \
15+
--region=$REGION
16+
17+
# 3. Create proxy-only subnet
18+
gcloud compute networks subnets create proxy-only-subnet \
19+
--purpose=REGIONAL_MANAGED_PROXY \
20+
--role=ACTIVE \
21+
--region=$REGION \
22+
--network=$NETWORK_NAME \
23+
--range=10.129.0.0/23
24+
25+
# 4. Create serverless NEG
26+
gcloud compute network-endpoint-groups create mql-serverless-neg \
27+
--region=$REGION \
28+
--network-endpoint-type=serverless \
29+
--cloud-run-service=$CLOUD_RUN_SERVICE
30+
31+
# 5. Create backend service
32+
gcloud compute backend-services create mql-backend-service \
33+
--load-balancing-scheme=EXTERNAL_MANAGED \
34+
--protocol=HTTP \
35+
--region=$REGION
36+
37+
# 6. Add serverless NEG to backend service
38+
gcloud compute backend-services add-backend mql-backend-service \
39+
--network-endpoint-group=mql-serverless-neg \
40+
--network-endpoint-group-region=$REGION \
41+
--region=$REGION
42+
43+
# 7. Create URL map
44+
gcloud compute url-maps create $LB_NAME \
45+
--region=$REGION \
46+
--default-service=mql-backend-service
47+
48+
# 8. Create target HTTP proxy
49+
gcloud compute target-http-proxies create $LB_NAME-proxy \
50+
--region=$REGION \
51+
--url-map=$LB_NAME
52+
53+
# 9. Create forwarding rule (the actual load balancer frontend)
54+
gcloud compute forwarding-rules create $LB_NAME-forwarding-rule \
55+
--region=$REGION \
56+
--load-balancing-scheme=EXTERNAL_MANAGED \
57+
--network=$NETWORK_NAME \
58+
--subnet=$SUBNET_NAME \
59+
--ports=80 \
60+
--target-http-proxy=$LB_NAME-proxy
61+
62+
# 10. Get the load balancer IP address
63+
gcloud compute forwarding-rules describe $LB_NAME-forwarding-rule \
64+
--region=$REGION \
65+
--format="get(IPAddress)"

0 commit comments

Comments
 (0)