Google Cloud Run is a service that allows you to run containerized applications in a serverless environment. This means that you don’t have to care about servers. Billing is done for what you use in terms of memory and processor for time (Google provides a free tier you can check here).
In this post, I will describe how you deploy your Buffalo application to Cloud Run.
In order for us to be able to send the app to Google Cloud Run, you need:
- Docker installed
- Gcloud CLI tool installed with the beta components
- Gcloud logged into your google account
- Docker setup with your GCR account
I’ll continue with this post assuming you have all that, if you need instructions for these you can go here and take a look at how to install or setup these tools.
Building container image
After ensuring you have all the permissions and given Buffalo ships with a valid (and very nice) multistage Dockerfile. You can now build your image with the following command:
docker build . -t gcr.io/buffalo/buffalo-app:v1.0.0
Notice that you added -t gcr.io/buffalo/buffalo-app, which is: - gcr.io (base for GCR) - buffalo is the project name - buffalo-app is the name of the image you’re sending to GCR - v1.0.0 is the tag you’re using for that image
This will build your image and tag it locally.
Pushing container image
Given you’ve already set permissions on the GCR docker repo you can now just push the container image there with the following command:
docker push gcr.io/buffalo/buffalo-app:v1.0.0
That will take the container image from your local docker repo and push it to GCR. By the time I’m writing this, Cloud Run doesn’t support images from other repositories apart from GCR.
Creating and running service
Once you have your image pushed to GCR you can tell Cloud Run to run your app with the following command. It will take care of service creation and deployment.
gcloud beta run deploy buffalo-app --region us-central1 --platform managed --allow-unauthenticated --image gcr.io/buffalo/buffalo-app:v1.0.0
With this you’re telling
- To deploy a service called
- To deploy it in the
- To deploy it in a
managed(full serverless) way
- To allow
unauthenticatedaccess to it
- With the image tag (
gcr.io/buffalo/buffalo-app:v1.0.0) that will be pushed to GCR
After this command has completed you will get a message saying:
Service [buffalo-app] revision [buffalo-app-00001] has been deployed and is serving traffic at https://blog-5zw4ak7zjq-uc.a.run.app.
Which is our signal that the deployment has been completed. That’s all, Your app is running in Google Cloud Run.
I have to admit that as you may have noticed this post is more about Google Cloud Run than Buffalo, but I’m mostly doing Buffalo lately. I named this post “Deploying Buffalo to Google Cloud Run” with the hope that in the future I could continue sharing those lessons. My team and I are learning about Buffalo on Google Cloud Run for now; all I can tell is we’re loving that mix.
Thanks for reading until here! If you have questions or comments about this post, you can find me on twitter at @paganotoni, or find my company there at @wawandco, I would love to hear your opinions on this and other posts.