Google Kubernetes Engine (GKE) image builder is an Alpine Linux based image for building and deploying Docker images from a CI environmnet (such as CircleCI). Based off google/cloud-sdk:alpine.
Contains the following command-line tools:
gke-builder has been tested with CircleCI 2.0. The following CircleCI configuration shows building a Docker image and pushing it to the Google Container Registry.
This example assumes you have setup the following environment variables:
GOOGLE_AUTH
- GCP service account JSON keyGOOGLE_PROJECT_ID
- the ID of your GCP projectGOOGLE_COMPUTE_ZONE
- which compute zone to use by default, e.g. us-central1-aGOOGLE_CLUSTER_NAME
- the cluster to which deployments will occurGOOGLE_GCR_HOST
- GCR hostname, e.g. us.gcr.io
For more configuration details read the following resources:
- CircleCI - Running Docker Commands
- CircleCI - Using Google Container Engine
- Gooogle Cloud Platform - Getting Started with Authentication
Example .circleci/config.yaml
config:
version: 2
jobs:
build:
docker:
- image: dtcristo/gke-builder:latest
working_directory: ~/repo
steps:
- checkout
- setup_remote_docker
- run:
name: Authenticate with Google Cloud
command: |
echo ${GOOGLE_AUTH} > ${HOME}/gcp-key.json
gcloud auth activate-service-account --key-file ${HOME}/gcp-key.json
gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
gcloud --quiet container clusters get-credentials ${GOOGLE_CLUSTER_NAME}
- run:
name: Pull latest image
command: |
IMAGE=${GOOGLE_GCR_HOST}/${GOOGLE_PROJECT_ID}/${CIRCLE_PROJECT_REPONAME}
gcloud docker -- pull ${IMAGE}:latest
- run:
name: Build image
command: |
IMAGE=${GOOGLE_GCR_HOST}/${GOOGLE_PROJECT_ID}/${CIRCLE_PROJECT_REPONAME}
TAG=$CIRCLE_BUILD_NUM
docker build \
--cache-from=${IMAGE}:latest \
-t ${IMAGE}:${TAG} \
-t ${IMAGE}:latest \
.
- run:
name: Push image
command: |
IMAGE=${GOOGLE_GCR_HOST}/${GOOGLE_PROJECT_ID}/${CIRCLE_PROJECT_REPONAME}
gcloud docker -- push ${IMAGE}