Image for post
Image for post
Grant holds a Cloud Run sticker in front of a container yard

Google Cloud’s Buildpacks are an easy way to create secure, production ready container images without a Dockerfile.

They’re open sourced and are used in production with Cloud Functions and App Engine.

In this article, I’ll walk through how to build a a Cloud Functions in a container with the Functions Framework so you can test your function as a locally or host your code in other container environments (like Cloud Run).

Note: The Cloud Functions CLI/API builds containers this way in the background.

1. Download the pack CLI

Install the CLI 🔗:

brew install buildpacks/tap/pack

2. Build Your Container

Build the current directory with :

This assume’s your current directory has the source code for Cloud Function. If you don’t have a function, here’s an example for Node. …


Image for post
Image for post
7 programming languages

Google Cloud Functions is a scalable pay-as-you-go functions as a service (FaaS) to run your code with zero server management. In the last year, the serverless team has open sourced 7 function frameworks (libraries) that power Cloud Functions in 7 languages.

Stephanie Wong introduces the Functions Framework in each language and shows 7 demos.

Let’s give a brief overview of them:

Node 🔗

  • Uses Express’ pattern
  • Supports Promises, great for non-blocking I/O

Python 🔗

  • Uses Flask, Gunicorn as an HTTP server

Go 🔗

  • Uses Go’s native HTTP package
  • Support CloudEvents via the CloudEvent SDK

Java 🔗


Image for post
Image for post
Google Sheets + Cloud Run

In 5 minutes, we’re going to quickly and securely integrate the Google Sheets API to your Cloud Run app. Just copy & paste the documented scripts below.

TL;DR

  1. Download service account credentials
  2. Share Google Sheet with the service account email
  3. Enable the Google Sheets API
  4. Write some Node
  5. Deploy to Cloud Run

Step 1: Download Credentials 🤖

Create a service account and download a key in a new file called .

Create a service account, download a service account key, and copy the service account’s email. Or use the UI.

This credential has the unique id:

2. Share Google Sheet with Service Account 🔗

Create a new Google Sheet if you don’t have one already: sheets.new


Image for post
Image for post
R Logo + Cloud Run

🅡 is a programming language and environment commonly used for statistical computing, data analytics and scientific research.

The R Functions Framework allows you to write portable R functions that can be easily deployed to Cloud Run.

In this blogpost, we’ll walk through deploying an R service to Cloud Run!

Install R

Install the precompiled binary distribution of R for your operating system at https://cloud.r-project.org/.

This will install the R language and CLI.

Install the R extension in VS Code

For easy local testing of R in our IDE, install the R extension from the VS Marketplace:

Test locally

Open the VS Code command palette (⌘⇧P) and type:


Image for post
Image for post
Swift™ + Cloud Run.

The Swift logo is a trademark of Apple Inc. Use of the Swift Logo is used according to this technical publication related to teaching the Swift programming language.

Swift (🔗) is an innovative, open source programming language developed by Apple to make software everywhere safer, faster, and more fun to create.

Vapor (vapor.codes) is a non-blocking, event-driven architecture built on top of Apple’s SwiftNIO, written in Swift with a focus on type-safety.

Together, you can build powerful web services that can be hosted on top of Cloud Run. This blogpost will give you a quick start for doing just that.

Prerequisites

To use Swift, you need one tool, Xcode. …


Image for post
Image for post

The Cloud SDK includes a set of tools and libraries for interacting with Google Cloud products and services, with the CLI tool being the primary command.

Here are a few commands/tricks that I use frequently:

1. Prevent Prompts. Set Defaults.

Setting default configurations for your CLI prevents the prompt:

gcloud config set compute/region us-west1
gcloud config set run/platform managed

See your existing configs with or see all configs 📄.

2. Getting / Change Project IDs

When using , most commands make API requests using the currently configured project. Some commands require the project name in the command arguments.

I like to keep the current project in an environment variable like…


Image for post
Image for post
.NET Core + Cloud Run

Introducing the .NET Functions Framework.

In this blogpost, we’ll give an introduction to the .NET Functions Framework and show you how to easily deploy a secure function on Google Cloud.

Setup

Install the .NET Core SDK 3.1.

After installing, you should have access to the CLI, including handy .NET templates to quickly get started.

Quickstart

Install the Google Cloud Functions template package into the .NET tooling:

dotnet new -i Google.Cloud.Functions.Templates::1.0.0-alpha07

Then create a new HTTP function using the .NET template:

mkdir HelloFunctions
cd HelloFunctions
dotnet new gcf-http

This will create and in the current directory.

Test Locally

Run the function locally:

dotnet…


Image for post
Image for post
Deno + Cloud Run

🦕 Deno (deno.land) is a secure TypeScript runtime built on V8 and Rust, created by Ryan Dahl, the creator of Node.js.

🏃 Cloud Run (cloud.run) is a fully managed compute platform that automatically scales your stateless containers.

In this blogpost, we’ll show you how to containerize and deploy a simple Deno application on Cloud Run, running a serverless, HTTPS, TypeScript service.

Create a Deno App

Let’s create a web application in TypeScript for Deno:

Install Deno

Install Deno on your system using the instructions on the official site:

curl -fsSL https://deno.land/x/install/install.sh | sh

Create a main.ts file

Create a simple HTTP server using Deno’s standard library:

main.ts

You’ll notice non-Node features like and top-level . …


Image for post
Image for post
Ruby + Cloud Run

Introducing the Ruby Functions Framework. This gem allow you to easily write ruby services with a simple functions as a service developer experience. In this blogpost, we’ll walk through how use the Ruby Functions Framework to containerize and deploy a Ruby method to Cloud Run.

Setup

Ensure Ruby 2.4+ is installed with . 🔗

Create a with the following contents:

source "https://rubygems.org"
gem "functions_framework", "~> 0.1"

Create a Function

Create a file called with the following function called :

A “Hello, world!” app.

Test your Function

Test your function by installing dependencies and starting your web server:

Install dependencies and start the Functions Framework.

Go to to see your function response! …


Image for post
Image for post
Cloud Pub/Sub ⟷ Cloud Functions

EDIT: This article may contain technical issues. Read with a grain of salt.

Google Cloud Functions come in 2 flavors: HTTP & background functions.

You use background functions when you want to have your Cloud Function invoked indirectly in response to an event, such as:

  • ✉️ A message on a Pub/Sub topic
  • 📦 A change in a Cloud Storage bucket
  • 🔥 A Firebase event

In this blogpost, we’ll talk about Pub/Sub and teach you how you can test your code using the Node Function Framework and Pub/Sub Emulator.

But before we begin, let’s level set.

What is Cloud Pub/Sub and Pub/Sub triggers?

Cloud Pub/Sub is a fully-managed scalable event ingestion and delivery system for asynchronous independent serverless applications. It’s the backbone for communication between many event-driven programs. …

About

Grant Timmerman

Google • Explorer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store