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
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@
/config/master.key
.env

*.nix
*.nix

# Terraform
**/.terraform/*
*.tfstate
*.tfstate.*
crash.log
*.tfvars
*.tfvars.json
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:3.4.2-slim
FROM ruby:4.0.1-slim

# Install essential Linux packages
RUN apt-get update -qq && apt-get install -y \
Expand All @@ -8,8 +8,11 @@ RUN apt-get update -qq && apt-get install -y \
git \
curl \
libyaml-dev \
libjemalloc2 \
&& rm -rf /var/lib/apt/lists/*

ENV LD_PRELOAD=libjemalloc.so.2

# Set working directory
WORKDIR /app

Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

ruby "3.4.2"
ruby "4.0.1"

gem "rails"
gem "pg", ">= 0.18", "< 2.0"
Expand All @@ -10,6 +10,7 @@ gem "aws-sdk-s3"
gem "stripe"
gem "mailgun-ruby"
gem "typhoeus"
gem "cgi"

group :development do
gem "standard"
Expand All @@ -19,3 +20,4 @@ group :development do
end

gem "dotenv-rails", groups: [:development, :test]
gem "minitest", "< 6", groups: [:test]
18 changes: 13 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ GEM
bootsnap (1.18.4)
msgpack (~> 1.2)
builder (3.3.0)
cgi (0.5.1)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crass (1.0.6)
Expand All @@ -104,7 +105,7 @@ GEM
dotenv-rails (3.1.7)
dotenv (= 3.1.7)
railties (>= 6.1)
drb (2.2.1)
drb (2.2.3)
erubi (1.13.1)
ethon (0.16.0)
ffi (>= 1.15.0)
Expand All @@ -114,6 +115,7 @@ GEM
logger
faraday-net_http (3.4.0)
net-http (>= 0.5.0)
ffi (1.17.1)
ffi (1.17.1-aarch64-linux-gnu)
ffi (1.17.1-aarch64-linux-musl)
ffi (1.17.1-arm-linux-gnu)
Expand Down Expand Up @@ -154,7 +156,8 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2025.0304)
mini_mime (1.1.5)
minitest (5.25.5)
mini_portile2 (2.8.9)
minitest (5.27.0)
msgpack (1.8.0)
net-http (0.6.0)
uri
Expand All @@ -168,6 +171,9 @@ GEM
net-smtp (0.5.1)
net-protocol
nio4r (2.7.4)
nokogiri (1.18.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.18.3-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.3-aarch64-linux-musl)
Expand Down Expand Up @@ -276,7 +282,7 @@ GEM
standard-performance (1.7.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.24.0)
stringio (3.1.5)
stringio (3.2.0)
stripe (13.5.0)
thor (1.3.2)
timeout (0.4.3)
Expand All @@ -286,7 +292,7 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicode-emoji (4.2.0)
uri (1.0.3)
useragent (0.16.11)
websocket-driver (0.7.7)
Expand All @@ -308,9 +314,11 @@ PLATFORMS
DEPENDENCIES
aws-sdk-s3
bootsnap (>= 1.4.2)
cgi
dotenv-rails
mailgun-ruby
memory_profiler
minitest (< 6)
pg (>= 0.18, < 2.0)
puma
rack-mini-profiler
Expand All @@ -321,7 +329,7 @@ DEPENDENCIES
typhoeus

RUBY VERSION
ruby 3.4.2p28
ruby 4.0.1p0

BUNDLED WITH
2.6.5
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
This is `licensor`, the license server for the Rails Performance Workshop.

Testing requires `stripe-mock` to be running on port 12111:
## Running tests with Docker Compose

```bash
docker compose -f docker-compose.test.yml run --rm --build test
```
docker run --rm -it -p 12111-12112:12111-12112 stripemock/stripe-mock:test
```

This starts:
- Postgres for the test database
- `stripe-mock` for Stripe API calls used by tests
- the Rails test runner container
38 changes: 21 additions & 17 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,37 @@
"description": "AWS S3 bucket name",
"required": true
},
"MAILGUN_API_KEY": {
"description": "Mailgun API key",
"required": true
"ACTION_MAILER_DELIVERY_METHOD": {
"description": "Action Mailer delivery method (smtp or mailgun)",
"value": "smtp"
},
"MAILGUN_PUBLIC_KEY": {
"description": "Mailgun public key for webhook verification",
"SMTP_ADDRESS": {
"description": "SMTP server hostname (AWS SES: email-smtp.<region>.amazonaws.com)",
"required": true
},
"MAILGUN_DOMAIN": {
"description": "Mailgun domain",
"SMTP_PORT": {
"description": "SMTP server port",
"value": "587"
},
"SMTP_USERNAME": {
"description": "SMTP username",
"required": true
},
"MAILGUN_SMTP_LOGIN": {
"description": "Mailgun SMTP login username",
"SMTP_PASSWORD": {
"description": "SMTP password",
"required": true
},
"MAILGUN_SMTP_PASSWORD": {
"description": "Mailgun SMTP password",
"SMTP_DOMAIN": {
"description": "SMTP HELO domain",
"required": true
},
"MAILGUN_SMTP_PORT": {
"description": "Mailgun SMTP port (usually 587)",
"value": "587"
"SMTP_AUTHENTICATION": {
"description": "SMTP authentication mode",
"value": "plain"
},
"MAILGUN_SMTP_SERVER": {
"description": "Mailgun SMTP server hostname",
"value": "smtp.mailgun.org"
"SMTP_ENABLE_STARTTLS_AUTO": {
"description": "Enable STARTTLS",
"value": "true"
}
}
}
25 changes: 20 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@ class Application < Rails::Application
# Skip views, helpers and assets when generating a new resource.
config.api_only = true

config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
api_key: ENV["MAILGUN_API_KEY"],
domain: "mg.speedshop.co"
}
config.action_mailer.delivery_method = ENV.fetch("ACTION_MAILER_DELIVERY_METHOD", "smtp").to_sym

if config.action_mailer.delivery_method == :mailgun
config.action_mailer.mailgun_settings = {
api_key: ENV["MAILGUN_API_KEY"],
domain: ENV.fetch("MAILGUN_DOMAIN", "mg.speedshop.co")
}
end

if config.action_mailer.delivery_method == :smtp
config.action_mailer.smtp_settings = {
address: ENV["SMTP_ADDRESS"] || ENV["MAILGUN_SMTP_SERVER"] || "localhost",
port: (ENV["SMTP_PORT"] || ENV["MAILGUN_SMTP_PORT"] || "587").to_i,
user_name: ENV["SMTP_USERNAME"] || ENV["MAILGUN_SMTP_LOGIN"],
password: ENV["SMTP_PASSWORD"] || ENV["MAILGUN_SMTP_PASSWORD"],
domain: ENV["SMTP_DOMAIN"] || ENV["MAILGUN_DOMAIN"] || "mg.speedshop.co",
authentication: ENV.fetch("SMTP_AUTHENTICATION", "plain").to_sym,
enable_starttls_auto: ENV.fetch("SMTP_ENABLE_STARTTLS_AUTO", "true") == "true"
}.compact
end
end
end
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true

config.action_mailer.delivery_method = :test
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
}
Expand Down
41 changes: 41 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: licensor_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d licensor_test"]
interval: 2s
timeout: 5s
retries: 30

stripe-mock:
image: stripemock/stripe-mock:latest

test:
build: .
command: sh -lc "bundle exec rails db:prepare && bundle exec rails test"
environment:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:postgres@db:5432/licensor_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
SECRET_KEY_BASE: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
STRIPE_API_KEY: sk_test_123
STRIPE_WEBHOOK_SECRET: whsec_test
STRIPE_API_BASE: http://stripe-mock:12111
ADMIN_API_KEY: admin
ZAPIER_HOOK_URL: http://example.test/zapier
AWS_REGION: us-east-1
AWS_ACCESS_KEY_ID: testing
AWS_SECRET_ACCESS_KEY: testing
AWS_BUCKET: test-bucket
volumes:
- .:/app
depends_on:
db:
condition: service_healthy
stripe-mock:
condition: service_started
Loading