Commit Graph

32 Commits

Author SHA1 Message Date
Javi Martín
e077c7e890 Rotate log files on production and staging
The code based on the logger Rails uses by default; as mentioned in the
Rails configuration guide:

> [the logger] defaults to an instance of ActiveSupport::TaggedLogging
> that wraps an instance of ActiveSupport::Logger which outputs a log to
> the log/ directory. You can supply a custom logger, to get full
> compatibility you must follow these guidelines:
>
> * To support a formatter, you must manually assign a formatter from
>   the config.log_formatter value to the logger.
> * To support tagged logs, the log instance must be wrapped with
>   ActiveSupport::TaggedLogging.
> * To support silencing, the logger must include
>   ActiveSupport::LoggerSilence module. The ActiveSupport::Logger class
>   already includes these modules.
2023-09-07 15:58:16 +02:00
Javi Martín
e93b693f71 Use different cache namespaces for different tenants
Since records in different tenants can have the same ID, they can share
the same `cache_key`, and so we need a namespace to differentiate them.
Without them, records from one tenant could expire the cache of a record
from another tenant.
2022-11-09 18:19:20 +01:00
Javi Martín
9812757332 Set the asset host based on default_url_options
We were duplicating the asset host and the URL host in all environments,
but we can make it so the asset host uses the URL host unless we
specifically set it.

Note that, inside the `ApplicationMailer`, the `root_url` method already
uses `default_url_options` to generate the URL.

In the rare case of CONSUL installations who have changed the asset
host, this change has no effect since they'll get a conflict in the
environment files when upgrading and they'll choose to use their own
asset host.
2022-10-06 15:28:29 +02:00
Javi Martín
b7e116b53f Allow adding per-environment custom settings
Until now, when editing a specific environment, other CONSUL
installations had to edit the original file, which made it harder to
upgrade.

Now it's possible to change the default CONSUL settings using custom
files, making it easier to upgrade to versions of CONSUL which change
the original environment files (which is very common when upgrading
versions of Rails).
2022-10-05 17:25:47 +02:00
Javi Martín
ffc14e499a Upgrade to Rails 6.0
All the code in the `bin/` and the `config/` folders has been generated
running `rake app:update`. The only exception is the code in
`config/application.rb` where we've excluded the engines that Rails 6.0
has added, since we don't use them.

There are a few changes in Active Storage which aren't compatible with
the code we were using until now.

Since the method to assign an attachment in ActiveStorage has changed
and is incompatible with the hack we used to allow assigning `nil`
attachments, and since ActiveStorage now supports assigning `nil`
attachments, we're removing the mentioned hack. This makes the
HasAttachment module redundant, so we're removing it.

Another change in ActiveStorage is files are no longer saved before
saving the `ActiveStorage::Attachment` record. This means we need to
manually upload the file when using direct uploads. We also have to
change the width and height validations we used for images; however,
doing so results in very complex code, and we currently have to write
that code for both images and site customization images.

So, for now, we're just uploading the file before checking its
dimensions. Not ideal, though. We might use active_storage_validations
in the future to fix this issue (when they support a proc/lambda, as
mentioned in commit 600f5c35e).

We also need to update a couple of tests due to a small change in
response headers. Now the content disposition returns something like:

```
attachment; filename="budget_investments.csv"; filename*=UTF-8''budget_investments.csv
```

So we're updating regular expression we use to check the filename.

Finally, Rails 6.0.1 changed the way the host is set in integration
tests [1] and so both `Capybara.app_host` and `Capybara.default_host`
were ignored when generating URLs in the relationable examples. The only
way I've found to make it work is to explicitely assign the host to the
integration session. Rails 6.1 will change this setup again, so maybe
then we can remove this hack.

[1] https://github.com/rails/rails/pull/36283/commits/fe00711e9
2022-08-24 14:33:02 +02:00
Javi Martín
dbc988f3e4 Unify production and staging environment files
We changed the structure of the production environment file in commit
eb36b7e2e, but forgot to do so for staging and preproduction.

We're also changing the comments in the production environment file so
they use double quotes, like we do everywhere else.

After these changes, the staging and production environments are mostly
identical, and we could simply require the production environment
configuration in the `staging.rb` file. We aren't doing so because we've
just done changes affecting the preproduction environment and, since
Consul installations might have customized these files, it might be hard
for them to deal with all these changes at once.
2022-07-19 23:13:42 +02:00
Javi Martín
e7b271fb47 Remove obsolete comment in environment files
We removed the assets initializer in commit 91cd1ce1b.
2022-07-19 23:13:35 +02:00
Javi Martín
e01a94d7bd Use mem_cache_store instead of dalli_store
`dalli_store` is deprecated since dalli 2.7.11.

We can now enable cache_versioning. We didn't enable it when upgrading
to Rails 5.2 because of possible incompatibility with `dalli_store` [1],
even though apparently some the issues were fixed in dalli 2.7.9 and
dalli 2.7.10 [2].

Since using cache versioning makes cache expiration more efficient, and
I'm not sure whether the options we were passing to the dalli store are
valid with memcache store (documentation here is a bit lacking), I'm
just removing the option we used to double the default cache size on
production.

[1] https://www.schneems.com/2018/10/17/cache-invalidation-complexity-rails-52-and-dalli-cache-store
[2] https://github.com/petergoldstein/dalli/blob/master/History.md
2021-08-15 19:42:22 +02:00
Javi Martín
5442ca7c54 Remove redundant configuration option
This option was added by Rails 4 new application generator. However, the
`assets.digest` option is set to true by default, and recent Rails
versions don't even add this option to the environment files.
2020-10-04 15:47:20 +02:00
Javi Martín
4bb1b3a6c3 Use Harmony mode in uglifier for ES2015+ support
Recent versions of graphql-rails updated React to a version which
requires this mode so it can be compiled on production.

So we enable this mode is described in the Uglifier README [2].

[1] https://github.com/lautis/uglifier/tree/v4.2.0#es6--es2015--harmony-mode
2020-10-02 14:07:05 +02:00
Pierre Mesure
40ecbe0348 Remove fallbacks = true from staging, preprod and prod 2020-02-20 11:09:55 +01:00
Julian Herrero
df4f8810c5 Define force_ssl configuration in secrets file
this is usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
2019-11-12 14:47:28 +01:00
Javi Martín
bc9471b49e Define SMTP configuration in the secrets file
Since SMTP passwords should not be in a file under version control, and
they're usually configured in the production.rb file (which is under
version control), the natural place to configure it is the secrets.yml
file.

Until now we were using the capistrano shared folder, but that's a bit
inconvenient since changes we've done to the production.rb file (like
changing eager_load_paths when we upgraded to Rails 5) won't take effect
after a deployment.
2019-11-11 12:11:20 +01:00
Julian Herrero
2ba7355b00 Add lib folder path to eager_load_paths
Because autoloading is disabled in production with Rails 5,
using autoload_paths will not load needed classes from
specified paths. The solution to this, is to ask Rails
to eager load classes.

https://sipsandbits.com/2017/02/14/upgrading-a-ruby-on-rails-application/
2019-04-29 17:45:58 -05:00
Julian Herrero
b36fdb5604 Add lib folder path to eager_load_paths
Because autoloading is disabled in production with Rails 5,
using autoload_paths will not load needed classes from
specified paths. The solution to this, is to ask Rails
to eager load classes.

https://sipsandbits.com/2017/02/14/upgrading-a-ruby-on-rails-application/
2019-04-17 17:40:56 +02:00
Juanjo Bazán
eb36b7e2e5 updates config files 2019-04-16 17:28:06 +02:00
Julian Herrero
c9cdc72537 Use double quotes in config/ 2019-03-15 10:29:07 +01:00
voodoorai2000
2892d0e1d5 Add placeholder configuration for SMTP 2018-09-13 20:38:42 +02:00
rgarcia
0fc51bee60 adds mailer asset host for staging and production envs 2015-09-01 17:31:28 +02:00
Juanjo Bazán
574133a50b updates environments files to use dalli store 2015-08-31 20:38:52 +02:00
rgarcia
e219e5be4d adds force ssl to staging 2015-08-26 12:22:58 +02:00
rgarcia
c13aea5f1d removes force ssl from staging 2015-08-26 12:03:28 +02:00
rgarcia
30d996da84 force ssl in staging 2015-08-26 12:00:34 +02:00
rgarcia
98c6f6561c removes force ssl in staging env 2015-08-26 11:37:41 +02:00
rgarcia
65a91ae821 configures ssl for staging and production environments 2015-08-25 16:01:43 +02:00
Juanjo Bazán
7edb45b0d7 configures the null cache store in all environments
This commit allows us to use caching and Rails.cache.
Temporarily we configure the null store in all environments,
but those will probably be memcached in the future.

References #235
2015-08-24 18:51:28 +02:00
rgarcia
0e6afa941d removes ssl from staging and production envs 2015-08-21 19:27:50 +02:00
rgarcia
24d3342af2 uses server_name from secrets 2015-08-21 19:18:30 +02:00
rgarcia
8e0c2c27da uses https for staging and production envs 2015-08-21 18:54:03 +02:00
rgarcia
6d14d07e5a adds deploy secrets to staging and production envs 2015-08-21 18:52:52 +02:00
rgarcia
dbc3a6596e adds mail host for staging and production 2015-08-21 17:06:51 +02:00
rgarcia
839314868c adding staging.rb 2015-08-20 12:50:36 +02:00