Deploying Go App with GCP, CircleCI, and Spinnaker

Introducing a deployment of the Go app using Google Cloud Platform, CircleCI, and Spinnaker.

Deploying Go App with GCP, CircleCI, and Spinnaker


Example repo

Deployment Overview

Set up Go app

go run main.go
Hello, Go App!
FROM golang:1.13.3-alpineENV GO111MODULE=onWORKDIR /go/src/golang-deploy-gcp
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
CMD ["golang-deploy-gcp"]
docker build -t golang-deploy-gcp ./
docker run -it --rm --name golang-deploy-gcp -p 8081:8080 golang-deploy-gcp

Set up Cloud SDK

curl | zsh
gcloud init
$ gcloud config list[core]
account =
disable_usage_reporting = True
Your active configuration is: [default]
$ gcloud auth list

Credentialed Accounts
To set the active account, run:
$ gcloud config set account `ACCOUNT`

Create a project

gcloud projects create golang-deploy-gcp

Enable a billing account

$ gcloud beta billing accounts listACCOUNT_ID            NAME              OPEN  MASTER_ACCOUNT_ID
xxxxx-xxxxx-xxxxx xxxx True
gcloud beta billing projects link golang-deploy-gcp --billing-account {ACCOUNT_ID}
billingAccountName: billingAccounts/xxxxx-xxxxx-xxxxx
billingEnabled: true
name: projects/golang-deploy-gcp/billingInfo
projectId: golang-deploy-gcp
$ gcloud compute regions listNAME                     CPUS  DISKS_GB  ADDRESSES  RESERVED_ADDRESSES  STATUS  TURNDOWN_DATE
asia-east1 0/8 0/2048 0/8 0/1 UP
asia-east2 0/8 0/2048 0/8 0/1 UP

Push the image to GCR with CircleCI

gcloud iam service-accounts create circleci --display-name circleci
gcloud iam service-accounts list
gcloud projects add-iam-policy-binding golang-deploy-gcp --member --role roles/storage.admin
$ gcloud projects get-iam-policy golang-deploy-gcp...- members:
role: roles/storage.admin
gcloud iam  service-accounts keys create --iam-account ./key.json
Environment Variables
Add an Environment Variables
gcloud compute zones list
gcloud services enable
{hostname}/{project id}/{image name}:{tag}
CircleCI Result
gcloud container images list


Install Halyard on GCE

gcloud iam service-accounts create halyard \
--project=golang-deploy-gcp \
--display-name halyard
gcloud projects add-iam-policy-binding golang-deploy-gcp \
--role roles/iam.serviceAccountKeyAdmin \
gcloud projects add-iam-policy-binding golang-deploy-gcp \
--role roles/container.admin \
gcloud compute instances create halyard \--project=golang-deploy-gcp \--zone=asia-east1-b \--scopes=cloud-platform \ \--image-project=ubuntu-os-cloud \--image-family=ubuntu-1404-lts \--machine-type=n1-standard-1
gcloud compute ssh halyard
// at GCE instance$ curl -O$ sudo bash$ hal -v
$ . ~/.bashrc
// at GCE instanceLATEST=$(curl -s -LO$LATEST/bin/linux/amd64/kubectlchmod +x kubectlsudo mv kubectl /usr/local/bin/kubectl

Create a Kubernetes cluster

// at local machinegcloud services enable
// at local machinegcloud container clusters create golang-deploy-gcp-cluster --machine-type=n1-standard-1 --num-nodes=1
// at local machinegcloud container clusters update golang-deploy-gcp-cluster --enable-legacy-authorization

Set up credentials

// at GCE instancegcloud container clusters get-credentials golang-deploy-gcp-cluster --zone=asia-east1-b
Google Cloud Resource Manager API
// at local marchinegcloud iam service-accounts create spinnaker \--project=golang-deploy-gcp \--display-name spinnaker
// at local marchinegcloud projects add-iam-policy-binding golang-deploy-gcp \--role roles/storage.admin \--member
// at local marchinegcloud projects add-iam-policy-binding golang-deploy-gcp \--member \--role roles/browser
// at GCE instancegcloud iam service-accounts keys create ./spinnaker.key.json \--iam-account

Set Spinnaker configuration

// at GCE instance$ hal config provider docker-registry enable$ hal config provider docker-registry account add my-gcr-account \--address \--password-file ~/spinnaker.key.json \--username _json_key
// at GCE instance$ hal config provider kubernetes enable$ hal config provider kubernetes account add my-k8s-account \--docker-registries my-gcr-account \--context $(kubectl config current-context)
// at GCE instance$ hal config storage gcs edit \--project $(gcloud info --format='value(config.project)') \--json-path ~/spinnaker.key.json$ hal config storage edit --type gcs

Deploy Spinnaker

// at GCE instance$ hal config deploy edit \--account-name my-k8s-account \--type distributed
// at GCE instance$ hal config version edit --version $(hal version latest -q)
// at local machinegcloud container clusters resize golang-deploy-gcp-cluster --num-nodes=4
// at GCE instancehal deploy apply
// at GCE instancehal deploy connect
gcloud compute ssh halyard -- -L 9000:localhost:9000 -L 8084:localhost:8084

Deploy Go App with Spinnaker

Create an application

Create an application
New Application

Create a load balancer

Create Load Balancer
Create New Load Balancer
Load Balancers

Create a pipeline

Configure a new pipeline
Create New pipeline
Add Trigger
Configure Trigger
Add stage
Add stage form
Deploy stage
Add server group
Configure Deployment Cluster
After add

Deploy application

Pipeline progressing
Deploy succeed


Web Developer, TypeScript, React, React Native, Vue.js, Go, Swift, and Ruby on Rails

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