Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
upload-cloud

GitHub Action

Google Cloud Compute Engine Deploy

v3.0.0

Google Cloud Compute Engine Deploy

upload-cloud

Google Cloud Compute Engine Deploy

Deploy to Google Cloud Compute Engine

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Google Cloud Compute Engine Deploy

uses: mattes/[email protected]

Learn more about this action in mattes/gce-deploy-action

Choose a version

Deploy to Google Compute Engine

Github action to simplify deploys to Google Compute Engine.

This action will...

  1. Clone an existing instance template (using it as a base).
  2. Update metadata config of the newly created instance template to run a startup script.
  3. Tell the instance group manager to perform a rolling update with the new instance template.

Prerequisites

Set up the following resources manually in the Cloud Console or use a tool like Terraform.

  • Create a base instance template to be cloned by this action.
  • Create a managed instance group. Please note that currently only regional instance groups are supported.
  • Create Service Account with Roles Compute Admin and Service Account User and export a new JSON key.

deploy.yml

By default this action expects a deploy.yml in the root directory of the repository. Here is an example:

deploys:
  - name: my-app-deploy
    region: us-central1
    instance_group: my-app-instance-group
    instance_template_base: my-app-instance-template-base
    instance_template: my-app-$GITHUB_RUN_NUMBER-$GITHUB_SHA
    cloud_init: cloud-init.yml # see example dir
    labels:
      github-sha: $GITHUB_SHA
    tags:
      - my-tag123

delete_instance_templates_after: false

Config Reference

Variable Description
deploys.*.name Required Name of the deploy
deploys.*.project Name of the Google Cloud project
deploys.*.creds Either a path or the contents of a Service Account JSON Key. Required, if not specified in Github action.
deploys.*.region Required Region of the instance group.
deploys.*.instance_group Required Name of the instance group.
deploys.*.instance_template_base Required Instance template to be used as base.
deploys.*.instance_template Required Name of the newly created instance template.
deploys.*.startup_script Path to script to run when VM boots. Read more
deploys.*.shutdown_script Path to script to run when VM shuts down. Read more
deploys.*.cloud_init Path to cloud-init file. Read more
deploys.*.labels A set of key/value label pairs to assign to instances.
deploys.*.metadata A set of key/value metadata pairs to make available from within instances.
deploys.*.tags A list of tags to assign to instances.
deploys.*.vars A set of additional key/value variables which will be available in either startup_script, shutdown_script or cloud_init. They take precedence over ENV vars.
delete_instance_templates_after Delete old instance templates after duration, default '336h' (14 days). Set to 'false' to disable.

Variables

Environment variables can be used in deploy.yml, see example above. The syntax is $FOO or ${FOO}.

Environment variables or deploys.*.vars can be used in the startup_script, shutdown_script or cloud_init, see example. The syntax is $(FOO) to not replace actual ENV vars.

Github sets a bunch of default environment variables.

Github Action Inputs

Variable Description
creds Either a path or the contents of a Service Account JSON Key.
config Path to config file. Default deploy.yml or deploy.yaml.

Example Usage

uses: mattes/gce-deploy-action@v3
with:
  creds: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
  config: production.yml

References