What is SaturnCI?
SaturnCI is a continuous integration (CI) tool for Ruby on Rails applications. SaturnCI currently only supports RSpec (as opposed to Minitest).
Configuration
Most CI products (GitHub Actions, GitLab Pipelines, CircleCI, etc.) use custom quasi-executable YAML files for configuration, often with embedded bash scripts. SaturnCI works differently. SaturnCI simply takes advantage of the existing flexibility of Docker and Docker Compose, which many developers are already familiar with.
Docker Compose Configuration
SaturnCI uses Docker Compose to create the environment in which your tests run. Below is an example Docker Compose file.
# .saturnci/docker-compose.yml
#
# SaturnCI Docker Environment
#
# This Docker Compose file specifies the environment that SaturnCI uses to run
# your tests.
#
# Local Development Usage:
# cd .saturnci
#
# Start all services
# docker-compose up -d
#
# Get shell in app container
# docker-compose run saturn_test_app bash
#
# Run tests
# docker-compose run saturn_test_app bundle exec rspec
#
# Stop and remove containers
# docker-compose down
version: "3.8"
services:
saturn_test_app:
# This hostname is what will go in the Capybara host config.
hostname: saturn_test_app
image: ${SATURN_TEST_APP_IMAGE_URL:-saturnci-local}
build:
context: ..
dockerfile: .saturnci/Dockerfile
volumes:
- ../:/app
- ./database.yml:/app/config/database.yml:ro
depends_on:
- postgres
- chrome
# .saturnci/.env is where SaturnCI will put the environment variables
# that you set in your repository's Secrets section in Settings.
#
# Optionally, you can add a local .saturnci.env file to provide environment
# variables when you run your SaturnCI setup locally.
env_file:
- .env
environment:
DOCKER_ENV: "true"
DATABASE_USERNAME: saturn
DATABASE_PASSWORD: ""
DATABASE_HOST: postgres
DATABASE_PORT: 5432
RAILS_ENV: test
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:3000"]
interval: 10s
timeout: 5s
retries: 10
postgres:
image: postgres:17.2-alpine
volumes:
- postgresql:/var/lib/postgresql/data:delegated
- ./init.sql:/data/application/init.sql
ports:
- "127.0.0.1:5432:5432"
environment:
PSQL_HISTFILE: /usr/src/app/log/.psql_history
POSTGRES_USER: saturn
POSTGRES_HOST_AUTH_METHOD: trust
restart: on-failure
healthcheck:
test: ["CMD-SHELL", "pg_isready -U saturn"]
interval: 10s
timeout: 2s
retries: 10
logging:
driver: none
chrome:
image: seleniarm/standalone-chromium
hostname: chrome
shm_size: 2g
ports:
- "4444:4444"
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:4444/wd/hub/status"]
interval: 10s
timeout: 5s
retries: 5
volumes:
postgresql:
Dockerfile
# .saturnci/Dockerfile
FROM ruby:3.3.5-slim
WORKDIR /app
ENV RAILS_ENV=test
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
nodejs \
git \
&& rm -rf /var/lib/apt/lists/*
COPY Gemfile Gemfile.lock ./
RUN bundle install && rm -rf /usr/local/bundle/cache/*
COPY app/assets ./app/assets
COPY app/javascript ./app/javascript
COPY app/views ./app/views
COPY config/environments ./config/environments
COPY config/initializers ./config/initializers
COPY config/application.rb config/boot.rb config/environment.rb ./config/
COPY public ./public
# Dummy database environment variables required for asset precompilation.
# Rails loads the application environment during asset compilation, which
# evaluates database.yml and may trigger database connections in initializers.
# These dummy values prevent build failures when no database is available.
ENV DATABASE_NAME=dummy_database_name
ENV DATABASE_USERNAME=dummy_database_username
ENV DATABASE_PASSWORD=dummy_database_password
ENV DATABASE_HOST=localhost
ENV DATABASE_PORT=5432
RUN bundle exec rails assets:precompile && \
rm -rf tmp/cache node_modules/.cache
COPY . ./
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]