# Sure on an exe.dev VM: https://exe.dev/deploy/sure # Based on Sure's compose.example.yml (v0.7.6-hotfix.1), with: # - Sure pinned to a release (SURE_IMAGE_TAG in .env), Redis pinned to 8 # - the web app on port 8000 (PORT in .env), which exe.dev's HTTPS # proxy serves privately at https://.exe.xyz/ # - RAILS_ASSUME_SSL on, because the proxy terminates HTTPS # - free Yahoo Finance prices and exchange rates (no API key) # - AI through exe.dev's LLM gateway (no API key), off until you turn it on # - backups owned by exedev instead of root # - sign-in through exe.dev's login (exedev_login at the end) # - reasoning_effort for newer OpenAI models (openai_reasoning at the end) # Secrets live in .env next to this file. name: sure x-db-env: &db_env POSTGRES_USER: ${POSTGRES_USER:-sure_user} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} POSTGRES_DB: ${POSTGRES_DB:-sure_production} x-rails-env: &rails_env <<: *db_env SECRET_KEY_BASE: ${SECRET_KEY_BASE:?Set SECRET_KEY_BASE in .env} ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: ${ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY:-} ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: ${ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY:-} ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: ${ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT:-} SELF_HOSTED: "true" APP_DOMAIN: ${APP_DOMAIN:-} # exe.dev's proxy speaks HTTPS to the browser and plain HTTP to the VM. RAILS_FORCE_SSL: "false" RAILS_ASSUME_SSL: "true" DB_HOST: db DB_PORT: 5432 REDIS_URL: redis://redis:6379/1 EXCHANGE_RATE_PROVIDER: ${EXCHANGE_RATE_PROVIDER:-yahoo_finance} SECURITIES_PROVIDER: ${SECURITIES_PROVIDER:-yahoo_finance} TWELVE_DATA_API_KEY: ${TWELVE_DATA_API_KEY:-} # AI: an OpenAI-compatible endpoint. The recipe points it at exe.dev's # LLM gateway, which needs no real key. Each user still has to turn AI on. # Sure talks Chat Completions to a custom endpoint; leave Responses mode off, # because it chains turns with previous_response_id, which the gateway # (zero data retention) rejects. Leave LLM_MAX_RESPONSE_TOKENS unset with # newer OpenAI models: setting it makes Sure send max_tokens, which they refuse. # OPENAI_REASONING_EFFORT is ours, not Sure's: see openai_reasoning below. OPENAI_ACCESS_TOKEN: ${OPENAI_ACCESS_TOKEN:-} OPENAI_URI_BASE: ${OPENAI_URI_BASE:-} OPENAI_MODEL: ${OPENAI_MODEL:-} OPENAI_REASONING_EFFORT: ${OPENAI_REASONING_EFFORT:-} LLM_CONTEXT_WINDOW: ${LLM_CONTEXT_WINDOW:-} LLM_MAX_RESPONSE_TOKENS: ${LLM_MAX_RESPONSE_TOKENS:-} OPENAI_REQUEST_TIMEOUT: ${OPENAI_REQUEST_TIMEOUT:-60} AI_RESPONSE_TIMEOUT: ${AI_RESPONSE_TIMEOUT:-90} services: web: image: ghcr.io/we-promise/sure:${SURE_IMAGE_TAG:?Set SURE_IMAGE_TAG in .env} restart: unless-stopped ports: - "${PORT:-8000}:3000" volumes: - app-storage:/rails/storage environment: <<: *rails_env # Two small Rails initializers, at the end of this file. Drop the # exedev_login line to use Sure's own sign-in instead of exe.dev's. configs: - { source: exedev_login, target: /rails/config/initializers/exedev_login.rb } - { source: openai_reasoning, target: /rails/config/initializers/openai_reasoning.rb } depends_on: db: condition: service_healthy redis: condition: service_healthy dns: - 8.8.8.8 - 1.1.1.1 networks: - sure_net worker: image: ghcr.io/we-promise/sure:${SURE_IMAGE_TAG:?Set SURE_IMAGE_TAG in .env} command: bundle exec sidekiq restart: unless-stopped volumes: - app-storage:/rails/storage environment: <<: *rails_env # The worker runs the AI assistant's chats. configs: - { source: openai_reasoning, target: /rails/config/initializers/openai_reasoning.rb } depends_on: db: condition: service_healthy redis: condition: service_healthy dns: - 8.8.8.8 - 1.1.1.1 networks: - sure_net db: image: postgres:16 restart: unless-stopped volumes: - postgres-data:/var/lib/postgresql/data environment: <<: *db_env healthcheck: test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] interval: 5s timeout: 5s retries: 5 networks: - sure_net redis: image: redis:8 restart: unless-stopped volumes: - redis-data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 5s retries: 5 networks: - sure_net # Sure's own full-instance backups (database, uploaded files, .env and # this file), in ./backups//-/. # Right now: docker compose run --rm backup create # Every day: docker compose --profile backup up -d backup backup: profiles: - backup image: ghcr.io/we-promise/sure:${SURE_IMAGE_TAG:?Set SURE_IMAGE_TAG in .env} # Sure's image runs as uid 1000, the same as exedev on the VM, so the # bundles in ./backups belong to you. Create ./backups before first use. user: "1000:1000" entrypoint: ["bin/sure-backup"] restart: unless-stopped volumes: - ${BACKUP_DIR:-./backups}:/backups - app-storage:/rails/storage - .:/config:ro environment: <<: *db_env POSTGRES_HOST: db BACKUP_SCHEDULE: ${BACKUP_SCHEDULE:-30 3 * * *} BACKUP_KEEP_DAYS: ${BACKUP_KEEP_DAYS:-14} INSTANCE_ID: ${INSTANCE_ID:-default} depends_on: db: condition: service_healthy networks: - sure_net volumes: app-storage: postgres-data: redis-data: networks: sure_net: driver: bridge configs: openai_reasoning: content: | # Newer OpenAI models (such as gpt-5.6-luna and gpt-6-luna) refuse tools # on Chat Completions unless reasoning_effort is "none", and Sure, on a # custom OPENAI_URI_BASE, uses Chat Completions without sending it. # Add OPENAI_REASONING_EFFORT to every request. Leave it empty for models # without reasoning, such as gpt-4.1, which refuse the parameter. OpenAI::Client.prepend(Module.new do def chat(parameters: {}) effort = ENV["OPENAI_REASONING_EFFORT"].presence if effort && !parameters.key?(:reasoning_effort) parameters = parameters.merge(reasoning_effort: effort) end super(parameters: parameters) end end) exedev_login: content: | # Sign in to Sure with your exe.dev login. # # exe.dev's proxy adds X-ExeDev-Email to every request from someone signed # in to exe.dev who can reach the VM. This initializer turns that header # into a Sure session, so nobody needs a Sure password: # # - The first person to open Sure gets a new household and becomes its # admin (Sure's first user is also its super admin). # - Anyone else you share the VM with joins that household as a member. # # Only use it while the VM is private: then every request comes through # exe.dev's proxy, which sets the header itself. Compose mounts this # into the web container as a Rails initializer. module ExedevLogin HEADER = "X-ExeDev-Email" def self.email(request) request.headers[HEADER].to_s.strip.downcase.presence end def self.user_for(email) User.find_by(email: email) || create_user(email) end def self.create_user(email) User.transaction do User.lock_first_user_role! family = Family.order(:created_at).first user = User.new(email: email, skip_password_validation: true) if family user.family = family user.role = :member else user.family = Family.new user.role = User.role_for_new_family_creator end user.save! family&.auto_share_existing_accounts_with(user) Rails.logger.info("[exedev_login] created #{user.role} #{email}") user end rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid User.find_by(email: email) end # Mixed into ApplicationController: with no Sure session cookie, sign in # the exe.dev user instead of showing Sure's sign-in page. module Session private def find_session_by_cookie super || exedev_session end def exedev_session email = ExedevLogin.email(request) or return user = ExedevLogin.user_for(email) or return create_session_for(user) || nil rescue => e Rails.logger.error("[exedev_login] #{e.class}: #{e.message}") nil end end # Mixed into the sign-in and sign-up pages: send exe.dev users to the app, # which signs them in. Sure's Sign out lands here and comes straight back; # sign out of exe.dev at /__exe.dev/logout instead. module SkipSignIn def self.prepended(base) base.before_action :exedev_skip_sign_in, only: :new end private def exedev_skip_sign_in email = ExedevLogin.email(request) or return user = User.find_by(email: email) redirect_to root_path if user.nil? || user.active? end end end Rails.application.config.to_prepare do ApplicationController.prepend(ExedevLogin::Session) SessionsController.prepend(ExedevLogin::SkipSignIn) RegistrationsController.prepend(ExedevLogin::SkipSignIn) end