Heroku Deployment
Relevant source files
The following files were used as context for generating this wiki page:
Heroku Deployment for the Actionmap application involves configuring a Ruby on Rails environment optimized for production hosting. The application serves as a platform for users to learn about representatives and local political events, utilizing a PostgreSQL backend and Webpacker for asset management.
The deployment infrastructure is designed to handle production-grade traffic by enforcing SSL, managing assets through precompilation, and utilizing environment variables for sensitive configuration like database credentials.
Sources: README.md:1-13, config/environments/production.rb:1-82
Production Environment Configuration
The production environment on Heroku is configured to maximize performance and security. Unlike development, code is not reloaded between requests, and classes are eager-loaded to allow threaded web servers to perform better.
Key Production Settings
| Setting | Value | Description |
|---|---|---|
cache_classes | true | Prevents reloading of code for every request. |
eager_load | true | Loads the application into memory on boot. |
consider_all_requests_local | false | Disables detailed error reports for end-users. |
force_ssl | true | Redirects all HTTP traffic to HTTPS and uses secure cookies. |
log_level | :debug | Sets the verbosity of system logs. |
Sources: config/environments/production.rb:7-46
Log Management
In the Heroku environment, logs are typically routed to standard output (STDOUT). The application checks for the presence of the RAILS_LOG_TO_STDOUT environment variable to initialize the logger accordingly.
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
Sources: config/environments/production.rb:73-77
Database Architecture
The application transitions from SQLite3 (used in development and testing) to PostgreSQL for production deployment on Heroku. The connection is managed via the DATABASE_URL environment variable or specific credential variables.
Database Connection Flow
This diagram illustrates how the application selects the database adapter based on the environment.
Sources: config/database.yml:25-60
Configuration Parameters
The production database configuration uses the following parameters:
- Adapter:
postgresql - Encoding:
unicode - Pool Size: Determined by
RAILS_MAX_THREADS(defaulting to 5). - Password: Provided via
ACTIONMAP_DATABASE_PASSWORD.
Sources: config/database.yml:19-75
Asset Pipeline and Javascript Compilation
Actionmap utilizes Webpacker to compile and serve JavaScript and specialized assets like Topojson files. In the production environment, the application relies on precompiled packs.
Webpacker Production Configuration
The production build is optimized for performance by disabling on-the-fly compilation and enabling manifest caching.
production:
<<: *default
compile: false
extract_css: false
cache_manifest: true
Sources: config/webpacker.yml:85-94
Build Environment Validation
The babel.config.js ensures that the build process is aware of the environment, throwing an error if the NODE_ENV is not set to one of the valid values: development, test, or production.
Sources: babel.config.js:1-17
Node and Yarn Engines
The application specifies version requirements for the runtime environment to ensure compatibility during the Heroku build process:
- Node:
12.x || 14.x - Yarn:
1.22.x
Sources: package.json:7-10
External Dependencies and Integrations
The deployment depends on several frontend and mapping libraries that are bundled during the build phase.
Core Dependencies
| Dependency | Purpose |
|---|---|
d3 / topojson | Used for rendering interactive maps. |
bootstrap | Provides the UI framework. |
turbolinks | Optimizes page navigation. |
jquery | Required for various UI interactions and plugins like select2. |
Sources: package.json:12-28
Conclusion
Heroku deployment for Actionmap is centered around a standard Rails production stack. It prioritizes security through SSL enforcement and performance through PostgreSQL and precompiled Webpacker assets. Configuration is primarily driven by environment variables, ensuring that sensitive data is kept out of the source code while allowing for flexible deployment across different Heroku environments.