Skip to content

Instantly share code, notes, and snippets.

@dja
Last active August 7, 2023 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dja/e8fa053c4b8c5893fcdd7a65d43941e3 to your computer and use it in GitHub Desktop.
Save dja/e8fa053c4b8c5893fcdd7a65d43941e3 to your computer and use it in GitHub Desktop.
Codeship Rails on Jet
#!/bin/bash
# Usage: script/ci [command]
# Run the test suite on a Codeship build machine.
# This makes sure the script fails on the first failing command
set -e
# Adding a check so an argument has to be passed to the container
COMMAND=${1:?'You need to pass a command as the first parameter!'}
sleep 10
# Create and init the database
bundle exec rake db:create db:migrate
case $COMMAND in
specs)
bin/rspec
;;
features)
bundle exec cucumber features
;;
brakeman)
bundle exec brakeman
;;
seed)
bundle exec rake db:seed
;;
audit)
bundle-audit
;;
esac
app:
build:
image: naritiv/naritiv-api
dockerfile_path: Dockerfile.ci
cached: true
# Run bin/deploy to encrypt .env file
encrypted_env_file: env.encrypted
# Linking Redis and Postgres into the container
links:
- postgres
- redis
- ffmpeg
# Set environment variables to connect to the service you need for your build. Those environment variables can overwrite settings from your configuration files (e.g. database.yml) if configured. Make sure that your environment variables and configuration files work work together as expected. Read more about Rails and database configuration in their Documentation: http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database
environment:
- DATABASE_URL=postgres://postgres@postgres/naritiv_test
- REDIS_URL=redis://redis
# Service definition that specify a version of the service through container tags
redis:
image: redis:2.8
postgres:
image: postgres:9.5.3
ffmpeg:
image: jrottenberg/ffmpeg:ubuntu
- name: ci
type: parallel
steps:
- name: specs
service: app
command: script/ci specs
- name: brakeman
service: app
command: script/ci brakeman
- name: seeds
service: app
command: script/ci seed
- name: bundler-audit
service: app
command: script/ci audit
# Article for Dockerfile at ADD_URL_FOR_THIS
# We're using the Ruby 2.3.1 base container and extend it
FROM ruby:2.3.1
# We install certain OS packages necessary for running our build
# Node.js needs to be installed for compiling assets
# libpq-dev is necessary for installing the pg gem
# libmysqlclient-dev is necessary for installing the mysql2 gem
RUN apt-get update && \
apt-get install -yq \
libmysqlclient-dev \
libpq-dev \
nodejs
# INSTALL any further tools you need here so they are cached in the docker build
# Create a directory for your application code and set it as the WORKDIR. All following commands will be run in this directory.
RUN mkdir /app
WORKDIR /app
# Set the Rails Environment to test
ENV RAILS_ENV test
# COPY Gemfile and Gemfile.lock and install dependencies before adding the full code so the cache only
# gets invalidated when dependencies are changed
COPY Gemfile Gemfile.lock ./
RUN gem install bundler
RUN gem install bundler-audit
RUN bundle install -j20
# Copy the whole repository into the container
COPY . ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment