GCP – Deploying to serverless platforms with GitHub Actions
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 orGoogle 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:
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:
A function triggered when a new object is created in Cloud Storage would be deployed with inputs like:
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.
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.
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.
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:
- Explore Google’s GitHub actions and give us feedback on your experience.
- Try out one of the example workflows.
- If you need control of your test environment, try setting up GitHub Actions self-hosted runners on Google Cloud.
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!
Read More for the details.