Skip to content

Instantly share code, notes, and snippets.

@anonoz
Last active July 23, 2017 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonoz/7ac15b14c95d871f7fd9c052bbd9b7e7 to your computer and use it in GitHub Desktop.
Save anonoz/7ac15b14c95d871f7fd9c052bbd9b7e7 to your computer and use it in GitHub Desktop.
Dockerfile for you to test Webpacker-enabled Rails including yarn, phantomjs on circleci v2
version: 2
jobs:
build:
docker:
- image: anonoz/ruby-2.4.1-yarn-phantomjs:0.0.2
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/postgres:9.6
environment:
- SECRET_KEY_BASE: "itdoesntmatter"
- RAILS_ENV: "test"
working_directory: /app
steps:
- checkout
- run:
name: copy database.yml template
command: |
cp config/circleci.database.yml config/database.yml
# node_modules for webpack
- restore_cache:
keys:
- yarn-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-cache-{{ .Branch }}
- yarn-cache
- run:
name: install npm dependencies with yarn
command: |
yarn
- save_cache:
key: yarn-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ./node_modules
- save_cache:
key: yarn-cache-{{ .Branch }}
paths:
- ./node_modules
- save_cache:
key: yarn-cache
paths:
- ./node_modules
# Ruby Dependencies
- restore_cache:
keys:
- gem-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- gem-cache-{{ .Branch }}
- gem-cache
- run:
name: install ruby dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
key: gem-cache-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- ./vendor/bundle
- save_cache:
key: gem-cache-{{ .Branch }}
paths:
- ./vendor/bundle
- save_cache:
key: gem-cache
paths:
- ./vendor/bundle
# Database setup
- run: bundle exec rake db:create
- run: bundle exec rake db:schema:load
# run tests!
- run:
name: run tests
command: |
mkdir /tmp/test-results
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress
- deploy:
name: deploy limo
command: |
if [ "${CIRCLE_BRANCH}" == "develop" ]; then
bundle exec cap staging deploy
fi
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
FROM ruby:2.4.1
# nodejs
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash -
# yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -\
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# finally the rest
RUN apt-get update && apt-get install -y \
apt-transport-https \
build-essential \
ca-certificates \
bzip2 \
libfontconfig \
curl \
nodejs \
yarn \
rsync \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# For feature testing
RUN mkdir /tmp/phantomjs \
&& curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 \
| tar -xj --strip-components=1 -C /tmp/phantomjs \
&& cd /tmp/phantomjs \
&& mv bin/phantomjs /usr/local/bin \
&& cd \
&& apt-get purge --auto-remove -y \
curl \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/*
RUN mkdir -p /app
WORKDIR /app
RUN gem install bundler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment