Skip to content

Commit 7cd7929

Browse files
committed
Build Rails app for production environment
1 parent 34513b2 commit 7cd7929

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
# ruby-on-rails
88
**/ruby-on-rails/tmp
99
**/ruby-on-rails/log
10+
master.key

sample-apps/manual-instrumentation/ruby-on-rails/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@ RUN bundle install
88

99
ENV HOME=/
1010

11+
ENV RACK_ENV=production
12+
13+
# DO NOT follow this pattern of committing your master key into source code.
14+
# This is just required to run a `production` rails app.
15+
16+
ENV RAILS_MASTER_KEY=e6780fe49c28c60ed2b594459981580c
17+
1118
CMD rails server

sample-apps/manual-instrumentation/ruby-on-rails/README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,34 @@ Sending metrics to Amazon CloudWatch is not yet validated. Check out the [OpenTe
3030

3131
## Application structure
3232

33-
Although this app was created with the `ruby new ruby-on-rails --minimal` command, it has been even further stripped down to focus on the OpenTelemetry changes needed to get tracing in this ruby on rails app.
33+
This section describes the decisions made when designing this sample app structure
34+
35+
### A minimal app
36+
37+
Although this app was created with the `rails new ruby-on-rails --minimal` command, it has been even further stripped down to focus on the OpenTelemetry changes needed to get tracing in this ruby on rails app.
3438

3539
The changes needed to trace with OpenTelemetry are found in [sample-apps/manual-instrumentation/ruby-on-rails/config/initializers/opentelemetry.rb](sample-apps/manual-instrumentation/ruby-on-rails/config/initializers/opentelemetry.rb).
40+
41+
### Running the app in `production` for tests
42+
43+
We build our application for a `production` environment because of https://github.com/aws-observability/aws-otel-ruby/pull/10.
44+
45+
However, to allow for a `production` environment, the rails app requires a "secret_base_key". Otherwise it will spam the log output with warnings which is really troublesome.
46+
47+
To solve this, we added **dummy credentials** which don't do anything. Because this is an example, **we directly commit the security credentials in the Dockerfile** but this is **NOT GOOD PRACTICE FOR REAL PRODUCTION ENVIRONMENTS**. We allow it to be like this because we want this demo example to work.
48+
49+
You can confirm the credentials work and view the encoded contents of by doing the following command:
50+
51+
```bash
52+
$ cd sample-apps/manual-instrumentation/ruby-on-rails
53+
$ RAILS_MASTER_KEY=<KEY_IN_SAMPLE-APP_DOCKERFILE> bin/rails credentials:edit
54+
```
55+
56+
This will show the following contents:
57+
58+
```yaml
59+
# NOTE: DO NOT USE THIS IN PRODUCTION ENVIRONMENTS, WE ONLY SET THIS TO SIMULATE A REAL RAILS APP.
60+
61+
# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
62+
secret_key_base: DO_NOT_STORE_A_SECRET_THIS_IS_JUST_FOR_AN_EXAMPLE
63+
```

sample-apps/manual-instrumentation/ruby-on-rails/bin/rails

100644100755
File mode changed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HuW+UqYwDMY5cxouXkoD+0COlk6eGJv5s3evlSyjOzw0NT1aFarbTaDpHhxiPfB2IrZ/hD7yMg7MvcFU9S5KxlJABOSK5jBQ9eZV2BQcW6/vJsPca4dntwTuf6wDbD6YVFnsF5MJ1lDjUjNy4SGrxsxwqUhx73fZIfbllNais2lV5uGAgIpGQA6x/DPZ2QOcTYd46tMdz7TxHyv9vWIgJensUMZoQ5L2+vlXhHRJ3XVoM+Dz2AU3ubll95gglTOd33BqEbUcen5VvdYB49ugg8WE+7mayC9DTzsLkOe72Vbw7T2m5KXJzsR+ZesSFaW+oJQaeDseHRM0kHfHqdk9Nr3dpaLQXdWG93uap2rh+pw=--koERuqkTE0/631gF--1ZFLVbmAiutXQs+cTnTlAA==

sample-apps/manual-instrumentation/ruby-on-rails/config/environments/production.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Ensures that a master key has been made available in either ENV['RAILS_MASTER_KEY']
2020
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21-
# config.require_master_key = true
21+
config.require_master_key = true
2222

2323
# Disable serving static files from the `/public` folder by default since
2424
# Apache or NGINX already handles this.

0 commit comments

Comments
 (0)