DockerfileAt project root (same level as app/):
FROM python:3.11-slim # Workdir WORKDIR /app # Copy files COPY app/ /app/ COPY requirements.txt /app/requirements.txt # Install deps RUN pip install --no-cache-dir -r requirements.txt # Expose port ENV PORT=8080 EXPOSE 8080 # Flask needs host 0.0.0.0 in container ENV GUNICORN_CMD_ARGS="--bind=0.0.0.0:8080 --workers=2 --threads=4" CMD ["python", "main.py"]
Update the last line if you prefer Gunicorn:
CMD ["python","-m","gunicorn","main:app"]
requirements.txt exists (from Lesson 3).# in app/main.py end:
if __name__ == "__main__":
import os
port = int(os.getenv("PORT", "8080"))
app.run(host="0.0.0.0", port=port, debug=False)
Enable services (first time only):
gcloud services enable run.googleapis.com artifactregistry.googleapis.com
Create an Artifact Registry repo (once):
gcloud artifacts repositories create chat-repo --repository-format=docker --location=us --description="Chatbot images"
Build & push:
gcloud builds submit --tag us-docker.pkg.dev/PROJECT_ID/chat-repo/vertex-chat:latest
Deploy to Cloud Run (public URL):
gcloud run deploy vertex-chat \ --image us-docker.pkg.dev/PROJECT_ID/chat-repo/vertex-chat:latest \ --platform managed --region us-central1 \ --allow-unauthenticated \ --service-account vertex-chatbot-sa@PROJECT_ID.iam.gserviceaccount.com
Output includes a URL like: https://vertex-chat-xxxxx-uc.a.run.app.
Option 1: Link/Embed — Add a menu link or embed via <iframe>:
<iframe src="https://vertex-chat-xxxxx-uc.a.run.app" width="100%" height="700" style="border:0"></iframe>
Option 2: Host UI on your domain, call Cloud Run API — Keep your static site on your hosting and POST to the Cloud Run service (enable CORS in Flask if needed).
# simple CORS in Flask from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app)