Skip to content

Instantly share code, notes, and snippets.

@sebastianconcept
Created November 13, 2017 13:28
Show Gist options
  • Save sebastianconcept/57b083ad9b0d9910f63241b39c52640e to your computer and use it in GitHub Desktop.
Save sebastianconcept/57b083ad9b0d9910f63241b39c52640e to your computer and use it in GitHub Desktop.
version: 2
jobs:
build:
working_directory: /app
docker:
- image: docker:17.05.0-ce-git
auth:
#Put the contents of keyfile.json into an environment variable for the build called GCR_CREDS, which is then passed in.
username: _json_key
password: $GOOGLE_AUTH
steps:
- checkout
- setup_remote_docker:
# Requires this version to be able to use docker-compose
version: 17.05.0-ce
- run:
name: Install dependencies
command: |
apk add --no-cache \
py-pip=9.0.0-r1
pip install \
docker-compose==1.12.0
- restore_cache:
keys:
- v1-{{ .Branch }}
paths:
- /caches/application.tar
- run:
name: Load Docker image layer cache
command: |
set +o pipefail
docker load -i /caches/application.tar | true
- run:
name: Build application Docker image
command: |
# docker build --cache-from=application -t application .
docker-compose -f ./docker-compose-test.yml build
- run:
name: Save Docker image layer cache
command: |
mkdir -p /caches
docker save -o /caches/application.tar application
- save_cache:
key: v1-{{ .Branch }}-{{ epoch }}
paths:
- /caches/application.tar
- run:
name: Run tests
command: |
docker run -d -p 27017:27017 --network="bridge" app-db:latest
docker run -d -p 6379:6379 --network="bridge" app-cache:latest
docker run -p 9000:9000 --network="bridge" application:latest /opt/app/test.sh
- run:
name: Dump Google Cloud Credentials to file
command: echo ${GOOGLE_AUTH} > ${HOME}/gcp-key.json
- deploy:
name: Push application Docker image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
echo "Deploying to Google Cloud...
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}
gcloud -q app deploy --project
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment