Environments

SaturnCI jobs run in environments. If you know how to define a Docker Compose environment, you know how to define a SaturnCI environment.

Environments live in .saturnci/environments/<environment name>/. To create an environment called, for example, ruby, put a Dockerfile and a docker-compose.yml in .saturnci/environments/ruby. Below is an example of just such an environment.

# .saturnci/environments/ruby/Dockerfile

FROM ruby:4.0.1-slim

RUN apt-get update && apt-get install -y \
  git \
  && rm -rf /var/lib/apt/lists/*
# .saturnci/environments/ruby/docker-compose.yml

services:
  job:
    build:
      context: ../../..
      dockerfile: .saturnci/environments/ruby/Dockerfile
    volumes:
      - ../../../:/app
    working_dir: /app

Jobs that use the shell task adapter run in the service named job. Test suite jobs name their service with service_name: on the create call in your workflow; see Jobs.

Secrets and environment variables

The environment variables you set in your repository's Secrets section in SaturnCI are written to a .env file next to the environment's docker-compose.yml. To make a service see them, pull the file in with env_file:

services:
  job:
    env_file:
      - .env

SaturnCI also passes your app's .ruby-version in as the build argument SATURNCI_RUBY_VERSION, so a Dockerfile can track the version your app actually uses:

ARG SATURNCI_RUBY_VERSION
FROM ruby:${SATURNCI_RUBY_VERSION}-slim

Learn more