Skip to content

Instantly share code, notes, and snippets.

@sjlu
Created October 19, 2015 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjlu/c483fcbbe7e911548c69 to your computer and use it in GitHub Desktop.
Save sjlu/c483fcbbe7e911548c69 to your computer and use it in GitHub Desktop.
CircleCI with automated Docker builds

CircleCI Docker Integration

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment