Jump to Content
Developers & Practitioners

Deploying to serverless platforms with GitHub Actions

December 14, 2020
https://storage.googleapis.com/gweb-cloudblog-publish/images/github_actions_hero_image_resized.max-1100x1100.jpg
Averi Kitsch

Senior Software Engineer, Google Cloud Databases

Join us on December 16, 2020, 11am PT / 2pm ET to learn more about Automating CI/CD pipelines with GitHub Actions and Google Cloud.

Serverless computing hides away infrastructure allowing for developers to focus on building great applications. Google Cloud Platform offers 3 serverless compute platforms—Cloud Functions, App Engine, and Cloud Run—with the benefits of zero server management, no up-front provisioning, auto-scaling, and only paying for the resources used. 

Serverless applications are quick and easy to spin up, but a system for continuous integration and continuous delivery (CI/CD) is key for long-term operability. However, CI/CD systems tend to be known for their complexity, so GitHub Actions aim to reduce the overhead by abstracting away the test infrastructure and creating a developer-centric CI/CD system. You can get started quickly by adding a configuration file to your repo to automate your builds, testing, and deployments. Google wants to meet you on GitHub and provides Google Cloud Platform integrated GitHub actions.

Let’s walk through how to deploy to Google Cloud Platform's serverless options using the integrated GitHub actions. Learn more about Google’s serverless hosting options or Google Cloud Platform full range of hosting options to find which platform is right for you.

Cloud Functions

Cloud Functions is Google Cloud’s Function-as-a-Service platform that allows users to create single-purpose, stand-alone functions that respond to events and HTTP requests. Cloud Functions are great for pieces of code like sending notification emails, performing database sanitization and maintenance, integrating with webhooks, and processing background tasks.

Use the google-github-actions/deploy-cloud-functions to deploy an HTTP function by specifying the function name and runtime:

Loading...

Or deploy a background function that can be triggered by events, such as Pub/Sub messages, Firebase events, or changes in a Cloud Storage bucket, by specifying trigger type and resource:

Loading...

A function triggered when a new object is created in Cloud Storage would be deployed with inputs like:

Loading...

Learn more about specifying event triggers.

App Engine

App Engine is the original serverless platform for hosting modern web applications. App Engine allows you to deploy from source by selecting a runtime from a set of popular programming languages.

Deploy your source code with the google-github-actions/deploy-appengine action by specifying a service account key with permissions to deploy and the path to App Engine app's settings file, app.yaml which sits next to your application to define the service for the deployment.

Loading...

The project ID is also set to ensure deployment to the correct project, since service accounts can be given permissions to separate projects.

Cloud Run

Cloud Run hosts stateless containers with any choice of language, library, or binary. Cloud Run is a great choice for REST API backends, lightweight data processing, and automated services like webhooks and scheduled tasks.

Use the google-github-actions/deploy-cloudrun action to deploy a container image hosted in Google Container Registry or Artifact Registry to Cloud Run to create a new service or a revision.

Loading...

Need to build your image too? Use the built-in Docker tool to build and push your image or utilize the setup-gcloud action (below) to submit a Cloud Build using the gcloud CLI tool.

Setup Cloud SDK

The Cloud SDK, also known as the gcloud CLI tool, is commonly used to interact with Google Cloud Platform. Use the setup-gcloud action to add the gcloud CLI tool to the path to interact with many Google Cloud services. This action can be used to authenticate other Google Cloud Platform actions by utilizing export_default_credentials. This exports the path to Default Application Credentials as the environment variable GOOGLE_APPLICATION_CREDENTIALS for services to be automatically authenticated in later steps. The credentials input in the other actions, then can be omitted.

Loading...

Try it for yourself!

Google and GitHub are excited to make it easier for you to set up CI/CD pipelines. Try Google Cloud GitHub actions today:

Join us on December 16, 2020, 11am PT / 2pm ET to learn more about Automating CI/CD pipelines with GitHub Actions and Google Cloud. Save your seat!

Posted in