Grab a service account API credential as a JSON file
cat .json | base64 | pbcopy
Add the following environment variables
GCE_URL
GCE_EMAIL
GCE_KEY
Add the following circle.yml file
machine:
environment:
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
CLOUDSDK_PYTHON_SITEPACKAGES: 1
python:
version: 2.7.3
services:
- docker
dependencies:
cache_directories:
- ~/google-cloud-sdk
- ~/docker
override:
- pip install pyopenssl
- if [ ! -d ~/google-cloud-sdk ]; then curl https://sdk.cloud.google.com | bash; ~/google-cloud-sdk/bin/gcloud components update preview; fi
- if [[ -e ~/docker/image.tar ]]; then docker load -i ~/docker/image.tar; fi
- docker build -t $GCE_URL:$CIRCLE_SHA1 .
- mkdir -p ~/docker; docker save $GCE_URL:$CIRCLE_SHA1 > ~/docker/image.tar
deployment:
prod:
branch: master
commands:
- echo $GCE_KEY | base64 --decode > gcloud.p12
- gcloud auth activate-service-account $GCE_EMAIL --key-file gcloud.p12
- ssh-keygen -f ~/.ssh/google_compute_engine -N ""
- gcloud docker push $GCE_URL > /dev/null