This repository provides a template for building and deploying Flask applications with Bazel. It includes pre-configured Bazel rules for Python dependencies, image creation, linting, formatting, and automated testing. The template is designed for scalability and ease of use, making it a great starting point for Flask-based projects.
- Familiarity with Git and code review processes, if you are not familiar go to go/review
- Ensure the following tools are installed on your system:
- Python 3.x
- Bazel (for building and pushing images)
Clone the repository to your local environment:
git clone "http://review.circlecat.org/flask-bazel-template"
To run the Flask application locally:
bazel run //:app
To run the unit tests for the Flask application:
bazel test //:app_test
To build and push the OCI image, follow these steps:
- Clean Bazel Cache (if needed):
bazel clean
2.Build the OCI Image:
bazel build //:flask_image
-
Push the Image: -Choice 1: Push to (non-existent) Default Repository:
bazel run //:flask_image_push_dynamic
-Choice 2: Push to a Specified Repository:
bazel run //:flask_image_push_dynamic --action_env=REPO=xxxx --action_env=TAG=xxxx
Before submitting your code (pushing a CL), you are recommended to make sure that the code meets the required formatting and linting standards to maintain code quality.
-
Run Lint Checks:
bash lint.sh all_files
-
Format the Code:
bazel run //tools/format:format
After ensuring the code is formatted and linted, follow these steps to submit your changes for review:
-
Commit your changes:
git commit -m "<Your commit message>"
-
Submit the code for review:
git review
-
If you need to amend your changes, use:
git commit --amend
BUILD
: Contains Bazel build rules for the Flask app, tests, and the OCI image.MODULE.bazel
: Defines external dependencies and Bazel modules.app.py
: The main Flask application file.app_test.py
: Unit tests for the Flask application.py_layer.bzl
: Custom Bazel rules for Python OCI image layers.lint.sh
: Script for running lint checks..gitreview
: Configuration for Gerrit code review.tools/
: Contains Bazel rules for linting and formatting.
The Flask application (app.py
) includes a simple endpoint:
@app.route("/")
def sample():
return "Welcome to Bazel built Flask!"
This project is licensed under the MIT License. See the [LICENSE] file for details.