Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
78 lines (71 sloc) 2.55 KB
version: 2
jobs:
checkout_and_build:
docker:
- image: circleci/ruby:2.5.1-node-browsers
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load
- run: bundle exec rake test
deploy-production:
docker:
- image: google/cloud-sdk:latest
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
- setup_remote_docker
- run:
name: Create image and push it
command: |
echo $GCLOUD_SERVICE_KEY > ${HOME}/gcloud-service-key.json
docker login -u _json_key --password-stdin https://gcr.io < ${HOME}/gcloud-service-key.json
docker build -t gcr.io/test-d6bf8/simple:$CIRCLE_SHA1 .
docker push gcr.io/test-d6bf8/simple:$CIRCLE_SHA1
- run:
name: Auth in gcloud
command: |
gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-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: Deploy new image
command: |
kubectl patch deployment sample -p '{"spec":{"template":{"spec":{"containers":[{"name":"sample","image":"gcr.io/test-d6bf8/simple:'"$CIRCLE_SHA1"'"}]}}}}'
if ! kubectl rollout status deploy/sample; then
echo "DEPLOY FAILED, ROLLING BACK TO PREVIOUS"
kubectl rollout undo deploy/sample
# Deploy failed -> notify slack
else
echo "Deploy succeeded, current version: ${CIRCLE_SHA1}"
# Deploy succeeded -> notify slack
fi
workflows:
version: 2
build-and-deploy:
jobs:
- checkout_and_build
- deploy-production:
requires:
- checkout_and_build
filters:
branches:
only: production
You can’t perform that action at this time.