setup-gcloud/example-workflows/gce
2020-02-13 16:52:47 -08:00
..
.github Add placeholders for VM name and zone 2020-02-13 13:54:24 -08:00
Dockerfile Add GCE workflow and instructions 2020-02-13 13:41:27 -08:00
README.md Improve formatting 2020-02-13 16:52:47 -08:00

Google Compute Engine - GitHub Actions

An example workflow that uses GitHub Actions to deploy a container to an existing Google Compute Engine (GCE) instance.

Workflow

For pushes to the default branch, master, the workflow will:

  1. Verify the Google Cloud Platform credentials are correct.
  2. Build, tag, and push the image to Google Container Registry.
  3. Deploy the container image to a Google Compute Engine instance. Note that a GCE deployment requires an existing container-optimized VM.

Setup

  1. Create or reuse a Github repository for the example workflow:
  • Create a repository.
  • Move into your repository directory.
  • Copy the example into the repository:
cp -r <path_to>/github-actions/example-workflows/gce/ ./
  1. Add your Project ID to the repository's secret, named GCE_PROJECT.
  2. Create a container-optimized GCE VM or use an existing container-optimized VM.
  3. Update gce.yml with the following values:
  • GCE_INSTANCE: the instance name of the VM.
  • GCE_INSTANCE_ZONE: the zone your VM resides.

Note: You can find the VM name and the zone on the Cloud Console.

  1. Add the the following roles to your service account:
  • Compute Instance Admin
  • Storage Admin

Run the workflow

  1. Add and commit your changes:
git add .
git commit -m "Set up Github workflow"
  1. Push to the master branch:
git push origin master
  1. View the workflow by selecting the Actions tab at the top of your repository. Then click on the Build and Deploy to GCE workflow to see the details.