Skip to content

Commit 271ab92

Browse files
committed
lambda wip
1 parent b0d7f4d commit 271ab92

File tree

13 files changed

+79
-24
lines changed

13 files changed

+79
-24
lines changed

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ WORKDIR /app
2727
COPY Gemfile /app/
2828
COPY Gemfile.lock /app/
2929

30-
RUN bundle install --path /gems --jobs 100 --deployment --without development:test
30+
RUN bundle config set deployment true \
31+
&& bundle config set without development:test \
32+
&& bundle config set path /gems \
33+
&& true
34+
ENV BUNDLE_JOBS=100
35+
RUN bundle install
36+
RUN bundle binstubs aws_lambda_ric --force --path /usr/local/bin
3137

3238
###
3339

@@ -41,6 +47,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,t
4147
WORKDIR /app
4248
COPY --from=builder /gems /gems
4349
COPY --from=builder /app/.bundle /app/.bundle
50+
COPY --from=builder /usr/local/bin/aws_lambda_ric /usr/local/bin/aws_lambda_ric
4451
COPY --from=nodebuilder /app/public/vite /app/public/vite
4552
COPY . /app/
4653

Gemfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gem 'commonmarker'
1212
gem 'aws-sdk-core' # STS
1313
gem 'aws-sdk-s3'
1414
gem 'aws-sdk-sqs'
15+
gem 'aws-sdk-ssm'
1516
gem 'omniauth'
1617
gem 'omniauth-github'
1718
gem 'octokit'
@@ -24,7 +25,8 @@ gem 'nokogiri', require: false
2425
gem 'rexml', require: false # letter-opener
2526
gem 'jsonnet', require: false
2627

27-
gem 'shoryuken'
28+
gem 'shoryuken', require: false
29+
gem 'lambdakiq', require: false
2830

2931
gem 'jbuilder', '~> 2.9'
3032
gem 'haml'
@@ -37,10 +39,11 @@ gem "sentry-ruby"
3739
gem "sentry-rails"
3840
gem 'rails_semantic_logger'
3941

40-
gem 'puma'
42+
gem 'puma', require: false
43+
gem 'aws_lambda_ric', require: false
44+
gem 'apigatewayv2_rack'
4145

4246
group :production do
43-
gem 'barnes'
4447
end
4548

4649
group :development, :test do

Gemfile.lock

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ GEM
7777
uri (>= 0.13.1)
7878
addressable (2.8.7)
7979
public_suffix (>= 2.0.2, < 7.0)
80+
apigatewayv2_rack (0.4.0)
81+
base64
82+
rack
83+
stringio
8084
aws-eventstream (1.4.0)
8185
aws-partitions (1.1182.0)
8286
aws-sdk-core (3.237.0)
@@ -97,11 +101,12 @@ GEM
97101
aws-sdk-sqs (1.106.0)
98102
aws-sdk-core (~> 3, >= 3.234.0)
99103
aws-sigv4 (~> 1.5)
104+
aws-sdk-ssm (1.206.0)
105+
aws-sdk-core (~> 3, >= 3.234.0)
106+
aws-sigv4 (~> 1.5)
100107
aws-sigv4 (1.12.1)
101108
aws-eventstream (~> 1, >= 1.0.2)
102-
barnes (0.0.9)
103-
multi_json (~> 1)
104-
statsd-ruby (~> 1.1)
109+
aws_lambda_ric (3.1.3)
105110
base64 (0.3.0)
106111
bigdecimal (3.3.1)
107112
builder (3.3.0)
@@ -178,6 +183,11 @@ GEM
178183
mini_portile2 (>= 2.2.0)
179184
jwt (3.1.2)
180185
base64
186+
lambdakiq (2.3.0)
187+
activejob
188+
aws-sdk-sqs
189+
concurrent-ruby
190+
railties
181191
launchy (3.1.1)
182192
addressable (~> 2.8)
183193
childprocess (~> 5.0)
@@ -206,7 +216,6 @@ GEM
206216
mini_mime (1.1.5)
207217
mini_portile2 (2.8.9)
208218
minitest (5.26.1)
209-
multi_json (1.17.0)
210219
multi_xml (0.7.2)
211220
bigdecimal (~> 3.1)
212221
multipart-post (2.4.1)
@@ -372,7 +381,6 @@ GEM
372381
snaky_hash (2.0.3)
373382
hashie (>= 0.1.0, < 6)
374383
version_gem (>= 1.1.8, < 3)
375-
statsd-ruby (1.5.0)
376384
stringio (3.1.8)
377385
temple (0.10.4)
378386
thor (1.4.0)
@@ -404,10 +412,12 @@ PLATFORMS
404412

405413
DEPENDENCIES
406414
addressable
415+
apigatewayv2_rack
407416
aws-sdk-core
408417
aws-sdk-s3
409418
aws-sdk-sqs
410-
barnes
419+
aws-sdk-ssm
420+
aws_lambda_ric
411421
commonmarker
412422
connection_pool
413423
factory_bot_rails
@@ -419,6 +429,7 @@ DEPENDENCIES
419429
jbuilder (~> 2.9)
420430
jsonnet
421431
jwt
432+
lambdakiq
422433
letter_opener_web
423434
listen
424435
nokogiri

config.ru

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# This file is used by Rack-based servers to start the application.
2-
31
require_relative "config/environment"
42

3+
if ENV['AWS_LAMBDA_FUNCTION_NAME']
4+
use Apigatewayv2Rack::Middlewares::CloudfrontVerify, ENV['CLOUDFRONT_VERIFY'] if ENV['CLOUDFRONT_VERIFY']
5+
use Apigatewayv2Rack::Middlewares::CloudfrontXff
6+
end
7+
58
run Rails.application
69
Rails.application.load_server

config/boot.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
22

33
require "bundler/setup" # Set up gems listed in the Gemfile.
4+
5+
require_relative 'lambda_boot' if ENV['AWS_LAMBDA_FUNCTION_NAME']

config/environments/development.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
# Change to :null_store to avoid any caching.
3131
config.cache_store = :memory_store
3232

33+
# see also config/initializers/active_job.rb
3334
config.active_job.queue_adapter = :inline
34-
if ENV['ENABLE_SIDEKIQ']
35-
config.active_job.queue_name_prefix = "sponsor_app"
36-
config.active_job.queue_adapter = :sidekiq
37-
end
3835

3936
if ENV['MAILGUN_SMTP_PASSWORD']
4037
config.action_mailer.smtp_settings = {

config/environments/production.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@
7575
secure: true,
7676
)
7777

78-
# Use a real queuing backend for Active Job (and separate queues per environment)
79-
config.active_job.queue_adapter = ENV.fetch('ENABLE_SHORYUKEN', '1') == '1' ? :shoryuken : :inline
80-
# config.active_job.queue_name_prefix = "sponsor_app2_production"
78+
# see also config/initializers/active_job.rb
79+
config.active_job.queue_adapter = :inline
8180

8281
# Disable caching for Action Mailer templates even if Action Controller
8382
# caching is enabled.

config/initializers/active_job.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Rails.application.configure do
2+
ENV['JOB_ADAPTER'] ||= 'shoryuken' if ENV['ENABLE_SHORYUKEN']
3+
case ENV['JOB_ADAPTER']
4+
when 'shoryuken'
5+
config.active_job.queue_adapter = :shoryuken
6+
when 'lambdakiq'
7+
config.active_job.queue_adapter = :lambdakiq
8+
end
9+
end

config/initializers/lambdakiq.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ActiveJob::Base.include Lambdakiq::Worker
2+
ActionMailer::MailDeliveryJob.include Lambdakiq::Worker
3+
ActionMailer::MailDeliveryJob.queue_as ENV['LAMBDAKIQ_QUEUE'] if ENV['LAMBDAKIQ_QUEUE']

config/lambda_boot.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ssm = Aws::SSM::Client.new
2+
r = /^SSM_SECRET__/
3+
params = ENV.keys.grep(r).map do |k, v|
4+
[v, k.sub(r, '')]
5+
end.to_h
6+
params.keys.each_slice(10) do |page|
7+
ssm.get_parameters(
8+
names: page.keys,
9+
with_decryption: true,
10+
).parameters.each do |param|
11+
ENV[page.fetch(param.name)] = param.value
12+
end
13+
end
14+
15+

0 commit comments

Comments
 (0)