Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ gem "benchmark"
gem "sqlite3"
gem "redis", "~> 5.4"

# Caching
gem "solid_cache", "~> 1.0.10"

# Deployment
gem "puma", "~> 8.0"

Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ GEM
rack-protection (= 4.2.1)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
solid_cache (1.0.10)
activejob (>= 7.2)
activerecord (>= 7.2)
railties (>= 7.2)
sqlite3 (2.10.2-aarch64-linux-gnu)
sqlite3 (2.10.2-arm64-darwin)
sqlite3 (2.10.2-x86_64-darwin)
Expand Down Expand Up @@ -463,6 +467,7 @@ DEPENDENCIES
selenium-webdriver
sentry-rails
sentry-ruby
solid_cache (~> 1.0.10)
sqlite3
stimulus-rails
surfguard!
Expand Down
2 changes: 1 addition & 1 deletion bench/compare_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
command.concat environment(RAILS_ENV: "production", SECRET_KEY_BASE: "isolated-benchmark-fixture-key", DISABLE_SSL: true,
SKIP_TELEMETRY: true, RAILS_LOG_LEVEL: "fatal", WEB_CONCURRENCY: 1, JOB_CONCURRENCY: 1, RAILS_MAX_THREADS: 5,
REDIS_URL: "redis://#{redis}:6379/0")
command.concat [ options[:image], "bundle", "exec", "puma", "-C", "config/puma.rb" ]
command.concat [ options[:image], "sh", "-c", "bin/rails db:prepare && exec bundle exec puma -C config/puma.rb" ]
run(*command)
deadline = clock + 45
until client.ready?
Expand Down
18 changes: 18 additions & 0 deletions config/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
default: &default
store_options:
max_size: <%= 256.megabytes %>
namespace: <%= Rails.env %>

development:
<<: *default

test:
<<: *default

performance:
database: cache
<<: *default

production:
database: cache
<<: *default
13 changes: 13 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,21 @@ performance:
primary:
<<: *default
database: storage/db/performance.sqlite3
cache:
<<: *default
database: storage/db/performance_cache.sqlite3
migrations_paths: db/cache_migrate
pragmas:
wal_autocheckpoint: 1000

production:
primary:
<<: *default
database: storage/db/production.sqlite3
cache:
<<: *default
database: storage/db/production_cache.sqlite3
migrations_paths: db/cache_migrate
# The checkpoint contender only checkpoints the primary database.
pragmas:
wal_autocheckpoint: 1000
3 changes: 1 addition & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
# Don't log any deprecations.
config.active_support.report_deprecations = false

# Cache in memory for now
config.cache_store = :redis_cache_store
config.cache_store = :solid_cache_store

# Assets are cacheable
config.public_file_server.headers = {
Expand Down
12 changes: 12 additions & 0 deletions db/cache_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ActiveRecord::Schema[7.2].define(version: 1) do
create_table "solid_cache_entries", force: :cascade do |t|
t.binary "key", limit: 1024, null: false
t.binary "value", limit: 536870912, null: false
t.datetime "created_at", null: false
t.integer "key_hash", limit: 8, null: false
t.integer "byte_size", limit: 4, null: false
t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size"
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
end
end
5 changes: 2 additions & 3 deletions docs/self-hosting.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ docker run --rm \
This gives you a `campfire-backup.tar.gz` in your current directory containing the database snapshot and all uploaded files.
Copy it somewhere safe, ideally off the machine.

To restore, extract the archive back into a (stopped) instance's volume, and replace the live database with the snapshot:
To restore, extract the archive back into a (stopped) instance's volume, and run the restore hook, which replaces the live database with the snapshot:

```sh
docker run --rm \
Expand All @@ -205,8 +205,7 @@ docker run --rm \
--volume "$PWD":/backup \
ghcr.io/basecamp/once-campfire:latest \
bash -c "tar xzf /backup/campfire-backup.tar.gz -C /rails &&
cp /rails/storage/backups/production.sqlite3 /rails/storage/db/production.sqlite3 &&
rm -f /rails/storage/db/production.sqlite3-wal /rails/storage/db/production.sqlite3-shm &&
/hooks/post-restore &&
chown -R rails:rails /rails/storage"
```

Expand Down
3 changes: 3 additions & 0 deletions hooks/post-restore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ set -euo pipefail
db_name="${RAILS_ENV:-production}.sqlite3"
snapshot="/rails/storage/backups/$db_name"
db="/rails/storage/db/$db_name"
cache_db="/rails/storage/db/${RAILS_ENV:-production}_cache.sqlite3"

if [ -f "$snapshot" ]; then
mkdir -p "$(dirname "$db")"
cp "$snapshot" "$db"
rm -f "$db-wal" "$db-shm"
fi

rm -f "$cache_db" "$cache_db-wal" "$cache_db-shm"
Loading