A Ruby gem for writing installation scripts that set up an app on Convox in your customer's (or your own) AWS account. DocSpring uses it to install DocSpring Enterprise.
Your script describes the installation with a small DSL. The gem asks for the settings it needs, installs a Convox v3 rack, creates the app, adds a private Docker registry, and adds an S3 bucket, an RDS Postgres database and an ElastiCache Redis cluster to the rack's Terraform configuration. Each step checks what already exists first, so you can run the script again after a failure and it carries on where it stopped.
Scripts run interactively for a person at a terminal, or non-interactively for CI and coding agents, with JSON output and exit codes.
- macOS or Linux
- Ruby 3.2 or later
- Convox v3 CLI (tested with 3.26.0)
- AWS CLI v2, version 2.9 or later
- Terraform 1.6 or later, or OpenTofu
- AWS credentials for the account you're installing into, with permission to create VPCs, EKS clusters, IAM roles, RDS, ElastiCache and S3 resources
On macOS: brew install awscli hashicorp/tap/terraform (or brew install awscli opentofu), then install the Convox CLI from the link above. ensure_requirements! checks all of these and prints install instructions for your system.
For Convox v2 racks, use convox_installer 1.0.9.
An installation creates AWS resources that cost money for as long as they exist: an EKS cluster and its EC2 nodes, NAT gateways, an RDS database, an ElastiCache cluster and an S3 bucket. If an install fails part way and you decide not to continue, check your AWS account and remove what was created. convox rack uninstall <stack_name> runs terraform destroy in the rack's directory, which also removes the database, Redis cluster and bucket the installer added there. Turn off the database's deletion protection and empty the bucket first, or the destroy stops part way. The software is provided without warranty (see the licence).
Create install.rb in a new repository for your installer:
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'convox_installer', '~> 4.0'
end
require 'convox_installer'
include ConvoxInstaller
@prompts = ConvoxInstaller::Config::DEFAULT_PROMPTS + [
{ key: :convox_app_name, title: 'Convox App Name', value: 'myapp' },
{ key: :docker_registry_url, title: 'Docker Registry URL', value: '123456789012.dkr.ecr.us-east-1.amazonaws.com' },
{ key: :docker_registry_username, title: 'Docker Registry Username' },
{ key: :docker_registry_password, title: 'Docker Registry Password' },
{ key: :s3_bucket_name, title: 'S3 Bucket', value: -> { "myapp-uploads-#{SecureRandom.hex(4)}" } }
]
ensure_requirements!
prompt_for_config
backup_convox_host_and_rack
install_convox
validate_convox_rack_and_write_current!
validate_convox_rack_api!
create_convox_app!
set_default_app_for_directory!
add_docker_registry!
add_s3_bucket
add_rds_database
add_elasticache_cluster
apply_terraform_update!
set_convox_env!(
'DATABASE_URL' => rds_details[:postgres_url],
'REDIS_URL' => elasticache_details[:redis_url],
'AWS_S3_BUCKET' => s3_bucket_details[:name]
)
step 'deploy', 'Deploy the app', check: -> { convox_processes.any? } do
run_convox_command! 'deploy --wait'
endSign in to AWS (for example aws sso login --profile prod), then:
AWS_PROFILE=prod ruby install.rb # install, asking for anything missing
AWS_PROFILE=prod ruby install.rb plan # what would change, without changing anythingYour installer repository also needs the app's convox.yml. examples/full_installation.rb is a complete script.
ruby install.rb [install|apply|plan|status] [options]
| Command | What it does |
|---|---|
install (default) |
Sets everything up. Run it again to resume; finished steps are skipped. apply is the same. |
plan |
Runs every step's checks and reports which steps would make changes. Changes nothing. |
status |
The same checks as plan, to see what exists. Changes nothing. |
| Option | |
|---|---|
-y, --yes, --non-interactive |
Never prompt, and start without asking for confirmation. Missing settings are an error. |
--json |
One JSON event per line on stdout; human-readable logs go to stderr. |
--config FILE |
Config file to use (default ./.installer_config.json). |
--set KEY=VALUE |
Set any setting. Repeatable. |
--<setting-name> VALUE |
Set one setting, for example --stack-name prod or --docker-registry-password .... |
--log-level LEVEL, --debug |
debug, info, warn or error. |
-h, --help |
List every option and setting. |
plan stops early, with exit code 0, when a later step needs something that doesn't exist yet (for example the database URL before the database is created). Everything after that point is pending.
| Code | Meaning |
|---|---|
| 0 | Success. For plan and status, the checks ran (whether or not changes are pending). |
| 1 | Unexpected error: a bug in the gem or the script. |
| 2 | A setting is missing or invalid, or the command line couldn't be parsed. |
| 3 | A precondition failed: a tool is missing or too old, there are no AWS credentials, or they belong to a different account. |
| 4 | A step failed (a convox, aws or terraform command returned an error). |
| 5 | The input ended at a prompt before an answer. |
| 130 | Interrupted (Ctrl-C). |
When a run fails, the last lines say what went wrong and what to do next. Fix it and run the same command again.
Each setting comes from, highest precedence first:
- Command-line flags:
--stack-name prodor--set stack_name=prod. - Environment variables:
CONVOX_INSTALLER_STACK_NAME. The keys in your script's@promptsalso read the bare name (STACK_NAME), as in 3.x. A few settings read their usual names (AWS_REGION,AWS_DEFAULT_REGION,AWS_PROFILE). - The config file,
./.installer_config.json. - The prompt's
value:(generated, never asked) ordefault:(offered at the prompt, used as is with--yes).
Interactive runs ask for anything still missing, show a summary with secrets masked, and ask before starting. The installer saves every value to the config file (mode 0600) as soon as it's known, so generated names and passwords stay the same on the next run. Keep that file safe: it holds the generated passwords. AWS credentials given in the environment or on the command line are never saved.
ConvoxInstaller::Config::DEFAULT_PROMPTS asks for stack_name (the rack name, default convox), aws_region (default us-east-1) and instance_type (default t3.medium), and generates random_id, a short suffix that keeps resource names unique.
@prompts is an array of hashes. A section heading:
{ section: 'Docker Registry', info: 'You should have received these details by email.' }A setting:
{
key: :admin_email,
title: 'Admin Email', # shown in the prompt and the summary
prompt: 'Email for the admin user: ', # optional question text
default: 'admin@example.com', # optional default
validate: /@/, # optional Regexp, or a Proc returning true, false or an error message
secret: true # optional; keys containing password, secret, token, license and similar are secret anyway
}A generated value that's never asked for, and a hidden setting that isn't shown in the summary:
{ key: :admin_password, title: 'Admin Password', value: -> { SecureRandom.hex(8) } }
{ key: :database_username, value: 'myapp', hidden: true }These change what the gem creates. Set them like any other setting (--database-instance-class db.t4g.medium or CONVOX_INSTALLER_DATABASE_INSTANCE_CLASS=db.t4g.medium), or add them to @prompts. ruby install.rb --help lists them all.
| Setting | Default |
|---|---|
aws_profile |
The default AWS credential chain |
aws_account_id |
Saved after the first run; later runs stop if the credentials belong to another account |
terraform_binary |
terraform, or tofu when Terraform isn't installed |
convox_rack_version |
The latest Convox release |
convox_rack_params |
Extra convox rack install parameters, key=value pairs separated by spaces |
convox_proxy_protocol |
true (passes client IPs to the app) |
availability_zones |
Chosen by AWS, except in us-east-1, where us-east-1c is left out |
database_engine_version |
17 for new databases; existing databases keep theirs |
database_instance_class |
db.t3.small |
database_allocated_storage |
30 (GiB) |
database_storage_type, database_storage_encrypted |
gp3, true for new databases |
database_multi_az, database_deletion_protection |
true |
database_backup_retention_period |
7 days for new databases |
database_allow_major_version_upgrade |
false; set it to true when you raise database_engine_version to a new major version |
database_username, database_password |
app, generated |
elasticache_engine, elasticache_engine_version |
redis, 7.1 (valkey defaults to 8.0) |
elasticache_node_type, elasticache_num_cache_nodes |
cache.t3.medium, 1 (2 or more turns on failover and Multi-AZ) |
elasticache_auth_token |
Generated |
elasticache_legacy_cluster |
true when the 3.x cluster already exists |
s3_bucket_versioning |
Enabled for new buckets; existing buckets keep theirs |
s3_bucket_noncurrent_version_expiration_days |
30 |
s3_bucket_cors_rule |
None |
default_service |
web |
convox_api_timeout |
360 seconds |
The installer uses the standard AWS credential chain: AWS_PROFILE (or the aws_profile setting), SSO, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, or an instance role. It never asks for keys. Before it starts, it shows the account and principal from aws sts get-caller-identity and the region, so you can check you're installing into the right place.
The Convox CLI only reads keys from environment variables, so the installer resolves the chain with aws configure export-credentials and passes short-lived keys to convox and terraform. They're refreshed before they expire, and never printed or saved.
AWS_PROFILE=prod \
CONVOX_INSTALLER_DOCKER_REGISTRY_PASSWORD="$REGISTRY_PASSWORD" \
ruby install.rb --yes --json --stack-name prod --aws-region eu-west-1 --docker-registry-username ci--yesnever prompts. If settings are missing, the run exits with code 2 and lists them, with the flag and environment variable for each.- Without a terminal and without
--yes, the installer stops before it changes anything and asks you to check the settings and add--yes. - Run
plan --jsonfirst to see what would change.
With --json, stdout carries only JSON events, one per line. Everything else, including output from convox and terraform and anything your script prints, goes to stderr.
{"event":"start","time":"2026-11-18T09:00:00Z","version":"4.0.0","command":"install","dry_run":false}
{"event":"config","time":"...","file":"/path/.installer_config.json","settings":{"stack_name":"prod","docker_registry_password":"[hidden]"},"sources":{"stack_name":"flag","docker_registry_password":"env:CONVOX_INSTALLER_DOCKER_REGISTRY_PASSWORD"}}
{"event":"step","time":"...","step":"convox_rack","status":"started","description":"Install the Convox rack prod"}
{"event":"step","time":"...","step":"convox_rack","description":"Install the Convox rack prod","status":"done","rack_dir":"..."}
{"event":"step","time":"...","step":"convox_app","description":"Create the myapp app","status":"skipped","state":"present","reason":"myapp already exists"}
{"event":"result","time":"...","command":"install","status":"succeeded","exit_code":0,"steps":[{"step":"convox_rack","status":"done"}],"outputs":{"domain":"web.myapp.0a1b2c.convox.cloud"},"config_file":"/path/.installer_config.json"}AGENTS.md describes every event and field.
Every DSL method that changes something is a named step. Before it changes anything, a step checks the current state; when there's nothing to do it's skipped. The names are stable, so you can refer to them in logs and runbooks.
| Step | Method | What it does |
|---|---|---|
requirements |
ensure_requirements! |
Checks for convox (v3), aws (v2.9+) and terraform (1.6+) or tofu |
config |
prompt_for_config |
Loads and checks the settings and AWS credentials, shows the summary and asks to start; returns the settings hash |
backup_convox_host_and_rack |
Before a new install, moves the Convox CLI's current-rack file to current.bak |
|
convox_rack |
install_convox |
Runs convox rack install aws <stack_name> ..., or resumes an unfinished install |
convox_current_rack |
validate_convox_rack_and_write_current! |
Makes the rack the CLI's current rack (convox switch) |
convox_rack_api |
validate_convox_rack_api! |
Waits for the rack API and checks it's the right rack |
convox_app |
create_convox_app! |
Creates the app (convox_app_name) |
convox_app_directory |
set_default_app_for_directory! |
Writes ./.convox/app, so convox commands here don't need --app |
docker_registry |
add_docker_registry! |
Adds docker_registry_url with its username and password |
terraform_s3_bucket |
add_s3_bucket |
Writes s3_bucket.tf: the bucket <stack_name>-<s3_bucket_name>, a KMS key and an IAM user for the app |
terraform_rds_database |
add_rds_database |
Writes rds.tf: an RDS Postgres database in the rack's VPC |
terraform_elasticache |
add_elasticache_cluster |
Writes elasticache.tf: a Redis replication group with TLS and AUTH |
terraform_apply |
apply_terraform_update! |
Runs terraform plan and applies the plan when there are changes |
convox_env |
set_convox_env!(values, promote: false) |
Sets the app environment variables that changed |
The Terraform files go in the rack's directory, next to Convox's own main.tf: ~/Library/Preferences/convox/racks/<stack_name> on macOS, ~/.config/convox/racks/<stack_name> on Linux (or $CONVOX_CONFIG/racks/<stack_name>). The add_* methods only write files; apply_terraform_update! creates the resources.
Methods that read state:
rds_details:{ postgres_url:, host:, port:, username: }elasticache_details:{ redis_url:, host:, port: }s3_bucket_details:{ name:, access_key_id:, secret_access_key: }(the IAM user's key, for the app)default_service_domain_name: the*.convox.clouddomain ofdefault_service, such asweb.myapp.0a1b2c.convox.cloudconvox_rack_data,convox_env_vars,convox_processes,convox_api_get(path),terraform_state,terraform_outputsaws_env(environment for your ownawscommands),aws_identity,installer_command,dry_run?,config,logger
run_convox_command!(cmd) runs a convox command with --rack <stack_name> and the installer's credentials, and raises when it fails. In plan and status it prints the command instead of running it. capture_convox_command!(cmd) does the same and returns the command's output, as in capture_convox_command!('build --id').strip; in plan and status it returns nil.
step 'database_setup', 'Set up the database', check: -> { config[:database_setup_done] } do
run_convox_command! 'run web rake db:prepare'
config[:database_setup_done] = 'true' # saved to the config file
endIn install the block runs unless check returns true. In plan and status the block doesn't run: the step is reported as done when check returns true, and pending otherwise. If your block can check for itself, pass plan_aware: true and call s.skip!('reason') or s.plan!(action: 'create') before changing anything:
step 'seed_data', plan_aware: true do |s|
s.skip!('already seeded') if convox_env_vars['SEEDED'] == 'true'
s.plan!(action: 'run')
run_convox_command! 'run web rake db:seed'
run_convox_command! 'env set SEEDED=true'
endresult_output(:domain, domain) adds a value to the final result event.
s3_bucket_cors_rule takes a Terraform cors_rule block, or a list of rule hashes in the config file:
{
key: :s3_bucket_cors_rule,
hidden: true,
value: <<~TERRAFORM
cors_rule {
allowed_headers = ["Authorization", "cache-control", "x-requested-with"]
allowed_methods = ["PUT", "POST", "GET"]
allowed_origins = ["*"]
max_age_seconds = 3000
}
TERRAFORM
}See CHANGELOG.md. Existing installs keep their database version, storage settings, bucket versioning and Redis cluster. Run ruby install.rb plan before install to see what would change.
bundle install
bundle exec rspec
bundle exec rubocopThe specs never call AWS or Convox. AGENTS.md explains how the code fits together.