
This blog post provides a comprehensive guide on deploying a Gemini powered Mesop application to Google Cloud Run, covering local environment setup, Docker image deployment, and tips for future updates.
In the previous video, we discussed building your first Gemini powered Mesop application. If you haven't watched it yet, you can find the link in the description below. In this post, we will focus on deploying your application to Cloud Run, making it accessible to users worldwide. This guide will walk you through the deployment process, including setting up your local development environment, building, and deploying the Docker image to Cloud Run.
Before we begin, ensure you have the following:
You can find detailed instructions for these steps in the description below.
Clone the Repository
Start by cloning the repository containing the sample application. The link can be found in the description of this video.
The README.md file includes all the necessary instructions, but let’s go through them step by step.
Install Required Packages
Open your favorite IDE and set up your local environment. Run the following commands:
requirements.txt file.Set Environment Variables
You need to set environment variables for Vertex SDK initialization. Specifically, set the following:
GOOGLE_CLOUD_PROJECT: Your Google Cloud project ID.GOOGLE_CLOUD_REGION: The region for your project (e.g., us-central1). Choose a region closer to your users if desired.Run the Application Locally
After setting the environment variables, you should be able to run misop main.py. If everything starts successfully, you will see a summary in the terminal. You can explore the application via the Local Host link.
Note that by default, Mesop runs with hot reloading, meaning any changes you make in your code will be visible on the site without needing to restart the application.
Once you have a working local version of the app, it’s time to build and deploy it.
Set Additional Environment Variables
You need to set an additional environment variable for deployment:
SERVICE_NAME: This is the name used to identify your new service in Cloud Run (e.g., mis-app).Deploy the Application
Run the deploy command with the --source parameter. This command will build the Docker container from the source code, upload it to the Artifact Registry, and deploy it to Cloud Run, all in one go. Execute the following command:
gcloud run deploy
You may be prompted to enable several APIs if you haven't done this before. Please answer "yes" to continue. If this is your first build in this project, you might also see a question about creating a new Artifact Registry. Again, answer "yes".
The deployment process will take a few minutes. After a successful deployment, you will receive a URL that you can visit in your browser. Congratulations! You have successfully deployed your first Gemini powered Mesop application to Cloud Run.
Sharing Your Application
You can now share the URL with your users, allowing them to explore the app. Remember, whenever you make changes to the application, you will need to repeat the last deployment step to update it on Cloud Run.
For future updates, consider exploring build triggers, which can automate the deployment process whenever you push changes to your code repository. More information about this can be found in the links below.
In this guide, you learned how to set up your local environment for coding and experimenting with your Gemini powered Mesop application. You also learned how to build and deploy your application to Cloud Run, making it available to users worldwide. Now, you can dive in and start creating your own Gemini applications on Cloud Run. Experiment with different Gemini models, get creative with your prompts, and build something amazing. We can't wait to see what you create! Feel free to share your Gemini powered apps in the comments below. Happy coding!