Serverless e-commerce: Vendure on Google Cloud Run
June 07, 2023
This post covers the steps needed to deploy Vendure on Google Cloud Run.
The step by step commands can be found here on GitHub: https://github.com/Pinelab-studio/vendure-google-cloud-run-starter/blob/main/README.md.
Prerequisites
This guide assumes you have:
Google cloud's
gcloud
cli installed locallyCreated a Google Cloud project and enabled the API's we need: https://github.com/Pinelab-studio/vendure-google-cloud-run-starter/blob/main/README.md#create-a-google-cloud-project
Setting up a MySQL database with Google Cloud SQL
Google Cloud SQL is a fully-managed relational database service that makes it easy to set up, maintain, and manage databases in the cloud. Vendure requires an SQL database to store its data, and Google Cloud SQL is a great option for this because it provides a reliable, scalable, and secure way to host our database.
You can find the gcloud
commands to create a MySQL database here: https://github.com/Pinelab-studio/vendure-google-cloud-run-starter/blob/main/README.md#create-a-mysql-database
Google Cloud Storage for assets
Vendure stores assets such as product images on file system by default. However, Google Cloud Run does not have internal file storage, so we need to use an external storage service. Google Cloud Storage is a great option for this because it provides a scalable and reliable way to store our assets in the cloud.
Use these gcloud
commands to create a storage bucket for our assets.
Google Cloud Tasks for Vendure's worker
Vendure uses a worker process to perform asynchronous tasks such as sending emails. To communicate between the main application and the worker process, we need a message queue. Google Cloud Tasks is a great option for this because it provides a fully-managed, scalable, and reliable way to send and receive messages between applications.
You don't need to do anything to enable Cloud Tasks: this plugin automatically creates task queues for you.
Running locally
Let's test out our application locally before deploying to Cloud Run. Copy this .env.example
to .env
and fill in your variables. You can skip the WORKER_HOST
variable, because we don't have it yet.
Dockerize Vendure
Google Cloud Run allows us to deploy containerized applications without worrying about the underlying infrastructure. To deploy Vendure to Google Cloud Run, we need to Dockerize it. Dockerizing Vendure means packaging the application and its dependencies into a container that can be easily deployed to Google Cloud Run.
The setup for containerizing Vendure is already done: This file and this file will build your container.
Deployment
The example repository contains GitHub action definitions to automatically deploy your app to Cloud Run when you push to the main
branch.
Follow these steps to create a service account and set your variables as repository secret in GitHub.
Keep alive
As final improvement, you can use Google Cloud Scheduler to poll your Cloud Run instance to prevent cold starts with this command.
That's it! Feel free to reach out for any questions, or create a Pull Request in the repository if you have any improvements.
Create your first commerce experience with Vendure in less than 2 minutes
Vendure is a registered trademark. Our trademark policy ensures that our brand and products are protected. Feel free to reach out if you have any questions about our trademarks.
Documentation
Newsletter
Get the latest product news and announcements delivered directly to your inbox.