struct RailsApp

Overview

The RailsApp represents the resource being specified. It is the spec in the Kubernetes YAML.

This resource comprises several different resources:

NOTE despite this being called a RailsApp, it's not only for Ruby on Rails apps. It was designed for them originally, but it quickly became useful for much more than apps built with that framework.

Example:

---
apiVersion: jgaskins.dev/v1beta1
kind: RailsApp
metadata:
  name: my-rails-app
spec:
  image: repo/image:tag
  env:
  - name: RAILS_ENV
    value: production
  - name: DATABASE_URL
    value: postgres://user:password@host/db
  - name: REDIS_URL
    value: redis://redis

  entrypoints:
  - name: web                    # Pods will be called `my-rails-app-web-*-*`
    domain: example.com          # The domain people will use to reach your app
    port: 3000                   # What port the server listens on
    command: [bin/rails, server] # Run the Rails server
  - name: worker                 # Pods will be called `my-rails-app-worker-*-*`
    command: [bin/sidekiq]       # Run the Sidekiq job processor

  before_create:
    command: [bin/rails, db:schema:load]
  before_update:
    command: [bin/rails, db:migrate]

Included Modules

Defined in:

rails_app_operator.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

def self.new(pull : JSON::PullParser) #

def self.new(*, image : String, image_pull_policy : RailsApp::ImagePullPolicy = "IfNotPresent", image_pull_secrets : Array(String) = Array(String).new, env_from : Array(RailsApp::EnvFrom) = Array(EnvFrom).new, env : Array(RailsApp::Env) = Array(Env).new, node_selector : Hash(String, JSON::Any) = {} of String => JSON::Any, directories : Array(RailsApp::Directories) = Array(Directories).new, annotations : Hash(String, JSON::Any) = {} of String => JSON::Any, entrypoints : Array(RailsApp::Entrypoints), before_create : RailsApp::BeforeCreate, before_update : RailsApp::BeforeUpdate, service_account : Nil | String = nil) #

[View source]

Instance Method Detail

def annotations : Hash(String, JSON::Any) #

def before_create : BeforeCreate #

When the RailsApp is created, this job is executed. Usually this is used to provision the database schema.


def before_update : BeforeUpdate #

When the RailsApp is updated, this job is executed. Usually this is used to run database schema and data migrations.


def directories : Array(Directories) #

Create directories on the container's filesystem

directories:
  - path: /containing/path
    name: config
    files:
      - filename: app.yml
        content: |
          production:
            database: postgres://user:password@host/db_name
            redis: redis://redis

def entrypoints : Array(Entrypoints) #

The entrypoints for your application — each type of process you run, such as a Rails server and Sidekiq, is a separate entrypoint. This is similar to entries in a Procfile.


def env : Array(Env) #

A list of Env objects representing environment variables. Either a value or value_from (in YAML: valueFrom) must be provided.

env:
  - name: REDIS_URL
    value: redis://redis
  - name: DATABASE_URL
    valueFrom:
      secretKeyRef:
        name: "postgres-app"
        value: "uri"

def env_from : Array(EnvFrom) #

The source of an environment variable, such as a ConfigMap or Secret.


def image : String #

The image tag to use by default for all entrypoints in this RailsApp


def image_pull_policy : ImagePullPolicy #

Describes how images are pulled: Always pulls a fresh container image each time and IfNotPresent will pull a container image once and keep it cached. Use Always if your container images use mutable tags, such as latest.


def image_pull_secrets : Array(String) #

The name of the secret that contains container-registry credentials, allowing Kubernetes to pull the image from its repo. For more information, see the Kubernetes documentation on pulling images from a private registry.


def node_selector : Hash(String, JSON::Any) #

A Hash(String, String) containing label/value pairs — pods for this RailsApp or Entrypoints will only be assigned to nodes that have these labels. For example, if you set kubernetes.io/arch: arm64 here, pods will only be assigned to nodes running Arm64 processors.


def service_account : String | Nil #

Use the given Kubernetes ServiceAccount to run pods for this app. This is extremely rare to need to set, so if you don't know what to set here, you almost certainly want to leave it blank.