-
Notifications
You must be signed in to change notification settings - Fork 31
[Deployment] Dynamic Versioning, Release Workflow Split, and CI/CD Hardening #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @gmechali, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a Dockerfile to containerize the application, making it easily deployable and manageable in containerized environments. The Dockerfile sets up a Python 3.11 slim environment, installs the necessary package, configures logging and port exposure, and includes a health check to ensure the application's readiness. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a Dockerfile to containerize the application. While this is a great addition, the current implementation has several areas for improvement regarding security, correctness, and Docker best practices. My review provides suggestions to build the image from local source code instead of PyPI, fix a critical issue with the HEALTHCHECK command, run the container as a non-root user for better security, and ensure the application port is configurable via environment variables as is standard for containerized applications.
…y. Note version.py will be updated locally before the pypi push.
… opening PR to update version.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive CI/CD pipeline for Google Cloud Build, establishing autopush, staging, and production deployment tiers. The changes include new Cloud Build configurations (autopush.yaml, staging.yaml, release.yaml) that automate publishing to PyPI (TestPyPI for dev/RC, official for production), building and pushing Docker images, and deploying to Cloud Run. A new Dockerfile is added to define the build environment, including pre-installing fastapi and installing the main package. Helper scripts (create_staging_tag.py, get_next_version.py, setup_apigee_sa.sh, setup_iam.sh) are introduced to manage versioning, tag creation, and IAM setup for deployment. The pyproject.toml is updated to specify a minimum fastapi version and remove uv from build requirements. Review comments highlight critical security concerns regarding disabled SSL verification in get_next_version.py, suggest optimizing the Dockerfile by using --no-install-recommends for apt-get and combining pip install commands to reduce image layers, recommend using a custom Cloud Build builder image with pre-installed tools for the release pipeline, and advise against hardcoding the Cloud Build service account email in setup_iam.sh for better reusability.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive CI/CD setup using Google Cloud Build and Docker, along with several helper scripts to automate development, staging, and production release workflows. The changes are extensive and well-structured, moving towards a more robust and automated deployment process. My review focuses on ensuring the correctness and security of the new Dockerfile and CI/CD pipelines. I've identified a couple of critical issues in the production release pipeline that need to be addressed, as well as several medium-severity suggestions to improve maintainability and security best practices across the new files.
scripts/setup_iam.sh
Outdated
|
|
||
| set -e | ||
|
|
||
| # TODO(gmechali): Decide whether we want to delete this as it is for a one time setup only. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script appears to be for a one-time setup. Once it has been used to configure the necessary environments, consider whether it should be removed from the repository to avoid clutter and prevent accidental re-execution. If it's intended for repeated use, adding more guards or making it fully idempotent would be beneficial.
| # 1. Pre-install fastapi from PyPI to avoid TestPyPI squatting | ||
| # 2. Install main package | ||
| # Note: We must explicitly unset PIP_EXTRA_INDEX_URL for the first command to force PyPI usage. | ||
| RUN PIP_EXTRA_INDEX_URL="" pip install --no-cache-dir "fastapi>=0.115.0" --index-url https://pypi.org/simple/ && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fastapi change here is because for autopush and staging, it ended up finding a fastapi build in TestPyPi that was broken.
I can look for a better long term solution as a follow up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked gemini about this and this is what it suggested:
Use --index-url for the official PyPI and only use --extra-index-url for your specific private/test index. To be even safer, use the --only-binary flag or specify the index per-package in a requirements.txt if you are using a tool like pip-compile.
Have you tried using --index-url only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah basically without this override here on fastapi it kept finding some broken fastapi packages in testpypi
https://pantheon.corp.google.com/cloud-build/builds;region=global/4c87aff2-af83-45f8-a285-3e951cc2fd8a;step=2?e=13803378&invt=AcGOtQ&mods=-monitoring_api_staging&project=datcom-ci
So it required this explicit override. I couldnt find another way to circumvent it...
keyurva
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Gabe! I've partially reviewed the PR but sending comments now so you can see them sooner.
| # 1. Pre-install fastapi from PyPI to avoid TestPyPI squatting | ||
| # 2. Install main package | ||
| # Note: We must explicitly unset PIP_EXTRA_INDEX_URL for the first command to force PyPI usage. | ||
| RUN PIP_EXTRA_INDEX_URL="" pip install --no-cache-dir "fastapi>=0.115.0" --index-url https://pypi.org/simple/ && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked gemini about this and this is what it suggested:
Use --index-url for the official PyPI and only use --extra-index-url for your specific private/test index. To be even safer, use the --only-binary flag or specify the index per-package in a requirements.txt if you are using a tool like pip-compile.
Have you tried using --index-url only?
|
Thanks Keyur, responded to your comments! I noticed there was one major change I had to add (see bottom of the server.py file) but now I've also confirmed the server is responding with all the MCP tools so far more confident in the successful deployment! |
|
|
||
| steps: | ||
| # 1. Verify and Publish | ||
| - name: python:3.12-slim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a fair amount of duplication between the 3 release yamls. Not sure if this is possible, but is there a way the common parts can be shared / reused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I already extracted out the wait_for_pypi script to avoid duplication there.
I could possibly extract out step 1 but also i think it's nice to see the code in the cloudbuild directly. I dont think that duplication is severe enough to warrant more breaking out.
Steps 3 and 4 are very straightforward. just docker build + push + cloud run deploy.
I think that extracting it into a more shared state will just lead to hyper-parameterized scripts that make it hard to read. I'd recommend sticking like this but lmk if you have something else in mind!
keyurva
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
This PR refactors the versioning strategy and release workflow to be automated and maintainable.
🚀 Key Changes
Dynamic Versioning (Single Source of Truth)
Release Workflow Overhaul
CI/CD Hardening & Security
Documentation