This task runs bin/regen_screenshots, which automates the generation of screenshots used on the documentation site. The screenshot generation code is similar to the route testing code, but instead of using rack-test as the capybara driver, cuprite is used. Cuprite is a capybara driver that uses the ferrum Ruby library to automate Chrome using the Chrome DevTools Protocol, which is substantially more reliable than Selenium/WebDriver/ChromeDriver. Using an actual browser (Chrome) for the screenshot generation code requires using an actual server to handle the brower's requests. So this starts Puma as a separate thread in the screenshot generation process. To avoid permanent database modification, this uses a transaction around the screenshot generation code. As the server runs in a separate thread than the screenshot generation code, this uses the Sequel temporarily_release_connection extension to share a single connection between server and the main thread, so the main thread can open the transaction, all server actions use the same connection inside the transaction, and the main thread can rollback the transaction after generating all screenshots. For this to work correctly, it requires PR #7 in the documentation repository be merged, to rename the screenshot png files. The screenshots generated by this program have significant advantages over the existing screenshots: * Consistency: Uses "Demo" as the user, instead of different users depending on who generated the screenshot. It also consistently shows the layout (the layout was omitted in some existing screenshots), and shows the same options in the layout (existing screenshots showed Billing, Access Policy, or both). * Accuracy: Shows current layout, and makes it easy to stay up to date with layout changes. The existing screenshots have the following issues: * Show Provider in the title bar * Show different layout for the PostgreSQL page when no databases have been created. * Quickstart screenshot shows no existing accounts (how it will look for new users), unlike existing screenshot, which shows an existing account. * Show Full Page: Each screenshot shows the enter page, instead of cropping it. This makes the image larger, but should make it more pleasing to the user.
42 lines
1.9 KiB
Ruby
42 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "netaddr"
|
|
require "sequel/core"
|
|
require_relative "config"
|
|
require_relative "lib/util"
|
|
|
|
db_ca_bundle_filename = File.join(Dir.pwd, "var", "ca_bundles", "db_ca_bundle.crt")
|
|
Util.safe_write_to_file(db_ca_bundle_filename, Config.clover_database_root_certs)
|
|
max_connections = Config.db_pool - 1
|
|
max_connections = 1 if ENV["SHARED_CONNECTION"] == "1"
|
|
DB = Sequel.connect(Config.clover_database_url, max_connections:, pool_timeout: Config.database_timeout).tap do |db|
|
|
# Replace dangerous (for cidrs) Ruby IPAddr type that is otherwise
|
|
# used by sequel_pg. Has come up more than once in the bug tracker:
|
|
#
|
|
# https://github.com/jeremyevans/sequel_pg/issues?q=inet
|
|
# https://github.com/jeremyevans/sequel_pg/issues/30
|
|
# https://github.com/jeremyevans/sequel_pg/pull/37
|
|
db.add_conversion_proc(650, NetAddr.method(:parse_net))
|
|
db.add_conversion_proc(869, NetAddr.method(:parse_ip))
|
|
end
|
|
|
|
postgres_monitor_db_ca_bundle_filename = File.join(Dir.pwd, "var", "ca_bundles", "postgres_monitor_db.crt")
|
|
Util.safe_write_to_file(postgres_monitor_db_ca_bundle_filename, Config.postgres_monitor_database_root_certs)
|
|
begin
|
|
POSTGRES_MONITOR_DB = Sequel.connect(Config.postgres_monitor_database_url, max_connections: Config.db_pool, pool_timeout: Config.database_timeout) if Config.postgres_monitor_database_url
|
|
rescue Sequel::DatabaseConnectionError => ex
|
|
Clog.emit("Failed to connect to Postgres Monitor database") { {database_connection_failed: {exception: Util.exception_to_hash(ex)}} }
|
|
end
|
|
|
|
# Load Sequel Database/Global extensions here
|
|
# DB.extension :date_arithmetic
|
|
DB.extension :pg_json, :pg_auto_parameterize, :pg_timestamptz, :pg_range, :pg_array
|
|
Sequel.extension :pg_range_ops
|
|
|
|
DB.extension :schema_caching
|
|
DB.extension :index_caching
|
|
DB.load_schema_cache?("cache/schema.cache")
|
|
DB.load_index_cache?("cache/index.cache")
|
|
|
|
DB.extension :temporarily_release_connection if ENV["SHARED_CONNECTION"] == "1"
|