Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created December 6, 2018 06:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huacnlee/890a8a1e6ce85f62b2958016e71f3d95 to your computer and use it in GitHub Desktop.
Save huacnlee/890a8a1e6ce85f62b2958016e71f3d95 to your computer and use it in GitHub Desktop.
CircleCI with Ruby 2.5, Rails 5.2, Yarn, Webpacker, Sass, PostgreSQL, Redis, ElasticSearch full example.
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.5.3-node-browsers
environment:
RAILS_ENV: test
DATABASE_URL: postgres://postgres@127.0.0.1:5432/rails-test
- image: circleci/postgres:9.6
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: ""
POSTGRES_DB: "rails-test"
- image: circleci/redis:4-alpine3.8
- image: docker.elastic.co/elasticsearch/elasticsearch:6.2.2
environment:
- xpack.security.enabled: false
working_directory: ~/repo
steps:
- checkout
- run:
name: Dockerize v0.6.0
command: |
wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz
sudo rm -rf /usr/local/bin/dockerize
sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.0.tar.gz
rm dockerize-linux-amd64-v0.6.0.tar.gz
- run:
name: Wait for PG
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Wait for Redis
command: |
dockerize -wait tcp://localhost:6379 -timeout 1m
- run:
name: Wait for ElasticSearch
command: |
dockerize -wait tcp://localhost:9200 -timeout 1m
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install dependencies
command: |
curl -o- -L https://yarnpkg.com/install.sh | bash
yarn global add sass
bundle install --jobs=4 --retry=3 --path vendor/bundle
yarn
- save_cache:
paths:
- ./vendor/bundle
- ~/.cache/yarn
key: v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "yarn.lock" }}
# Database setup
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load
- run:
name: Rubocop
command: bundle exec rubocop
- run:
name: Rails Test
command: bundle exec rails test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment