Skip to content

Instantly share code, notes, and snippets.

@tiagopog
Last active February 20, 2018 07:03
Show Gist options
  • Save tiagopog/0bb397864dccb52a1253afd57812471d to your computer and use it in GitHub Desktop.
Save tiagopog/0bb397864dccb52a1253afd57812471d to your computer and use it in GitHub Desktop.
CircleCI's config by examples
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.2-stretch-browsers
environment:
FLASK_CONFIG: testing
TEST_DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.5-alpine-ram
environment:
POSTGRES_USER: ubuntu
POSTGRES_DB: circle_test
POSTGRES_PASSWORD: ""
steps:
- checkout
- restore_cache:
key: deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }}
- run:
name: Install Python deps in a venv
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements/dev.txt
- save_cache:
key: deps1-{{ .Branch }}-{{ checksum "requirements/dev.txt" }}
paths:
- "venv"
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.3
steps:
- checkout
- run: echo "hello world"
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.2-stretch-browsers
environment:
FLASK_CONFIG: testing
TEST_DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.5-alpine-ram
environment:
POSTGRES_USER: ubuntu
POSTGRES_DB: circle_test
POSTGRES_PASSWORD: ""
steps:
- checkout
- run:
name: Install Python deps in a venv
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements/dev.txt
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.2-stretch-browsers
steps:
- checkout
- run: pip install -r requirements/dev.txt
version 2
jobs:
build:
docker:
- image: circleci/python:3.6.2-stretch-browsers
environment:
FLASK_CONFIG: testing
TEST_DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.5-alpine-ram
environment:
POSTGRES_USER: root
POSTGRES_DB: circle_test
POSTGRES_PASSWORD: ""
version: 2
jobs:
build:
working_directory: ~/mern-starter
# The primary container is an instance of the first list image listed. Your build commands run in this container.
docker:
- image: circleci/node:4.8.2
# The secondary container is an instance of the second listed image which is run in a common network where ports exposed on the primary container are available on localhost.
- image: mongo:3.4.4
steps:
- checkout
- run:
name: Update npm
command: 'sudo npm install -g npm@latest'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Install npm wee
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
test:
docker:
- image: circleci/node:4.8.2
- image: mongo:3.4.4
steps:
- checkout
- run:
name: Test
command: npm test
- run:
name: Generate code coverage
command: './node_modules/.bin/nyc report --reporter=text-lcov'
- store_artifacts:
path: test-results.xml
prefix: tests
- store_artifacts:
path: coverage
prefix: coverage
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build
filters:
branches:
only: master
version: 2.0
jobs:
checkout_code:
docker:
- image: circleci/ruby:2.4-node
- image: circleci/postgres:9.4.12-alpine
working_directory: ~/circleci-demo-workflows
steps:
- checkout
- run:
name: save SHA to a file
command: echo $CIRCLE_SHA1 > .circle-sha
- save_cache:
key: v1-repo-{{ checksum ".circle-sha" }}
paths:
- ~/circleci-demo-workflows
bundle_dependencies:
docker:
- image: circleci/ruby:2.4-node
- image: circleci/postgres:9.4.12-alpine
working_directory: ~/circleci-demo-workflows
steps:
- run:
name: save SHA to a file
command: echo $CIRCLE_SHA1 > .circle-sha
- restore_cache:
keys:
- v1-repo-{{ checksum ".circle-sha" }}
- restore_cache:
keys:
- v1-bundle-{{ checksum "Gemfile.lock" }}
- run: bundle install --path vendor/bundle
- save_cache:
key: v1-bundle-{{ checksum "Gemfile.lock" }}
paths:
- ~/circleci-demo-workflows/vendor/bundle
rake_test:
docker:
- image: circleci/ruby:2.4-node
- image: circleci/postgres:9.4.12-alpine
working_directory: ~/circleci-demo-workflows
steps:
- run:
name: save SHA to a file
command: echo $CIRCLE_SHA1 > .circle-sha
- restore_cache:
keys:
- v1-repo-{{ checksum ".circle-sha" }}
- restore_cache:
keys:
- v1-bundle-{{ checksum "Gemfile.lock" }}
- run: bundle --path vendor/bundle
- run: bundle exec rake db:create db:schema:load
- run:
name: Run tests
command: bundle exec rake
precompile_assets:
docker:
- image: circleci/ruby:2.4-node
- image: circleci/postgres:9.4.12-alpine
working_directory: ~/circleci-demo-workflows
steps:
- run:
name: save SHA to a file
command: echo $CIRCLE_SHA1 > .circle-sha
- restore_cache:
keys:
- v1-repo-{{ checksum ".circle-sha" }}
- restore_cache:
keys:
- v1-bundle-{{ checksum "Gemfile.lock" }}
- run: bundle --path vendor/bundle
- run:
name: Precompile assets
command: bundle exec rake assets:precompile
- save_cache:
key: v1-assets-{{ checksum ".circle-sha" }}
paths:
- ~/circleci-demo-workflows/public/assets
deploy:
machine:
enabled: true
working_directory: ~/circleci-demo-workflows
environment:
- HEROKU_APP: still-shelf-38337
steps:
- run:
name: save SHA to a file
command: echo $CIRCLE_SHA1 > .circle-sha
- restore_cache:
keys:
- v1-repo-{{ checksum ".circle-sha" }}
- restore_cache:
keys:
- v1-bundle-{{ checksum "Gemfile.lock" }}
- restore_cache:
keys:
- v1-assets-{{ checksum ".circle-sha" }}
- run:
name: Setup Heroku
command: bash .circleci/setup-heroku.sh
- run:
command: |
git push heroku fan-in-fan-out:master
heroku run rake db:migrate
sleep 5 # sleep for 5 seconds to wait for dynos
heroku restart
workflows:
version: 2
build-and-deploy:
jobs:
- checkout_code
- bundle_dependencies:
requires:
- checkout_code
- rake_test:
requires:
- bundle_dependencies
- precompile_assets:
requires:
- bundle_dependencies
- deploy:
requires:
- rake_test
- precompile_assets
version: 2
jobs:
build:
docker:
- image: golang:1.6.4 # (1)
working_directory: /go/src/github.com/CircleCI-Public/circleci-demo-docker
steps:
- checkout
# ... steps for building/testing app ...
- setup_remote_docker # (2)
docker_layer_caching: true # (3)
# use a primary image that already has Docker (recommended)
# or install it during a build like we do here
- run:
name: Install Docker client
command: |
set -x
VER="17.03.0-ce"
curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv /tmp/docker/* /usr/bin
# build and push Docker image
- run: |
TAG=0.1.$CIRCLE_BUILD_NUM
docker build -t CircleCI-Public/circleci-demo-docker:$TAG . # (4)
docker login -u $DOCKER_USER -p $DOCKER_PASS # (5)
docker push CircleCI-Public/circleci-demo-docker:$TAG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment