Merge pull request #82 from LucasCioffi/patch-2
Add instructions for SendGrid + Heroku
This commit is contained in:
@@ -107,6 +107,26 @@ This tutorial assumes that you have already managed to clone CONSUL on your mach
|
|||||||
|
|
||||||
See [our S3 guide](./using-aws-s3-as-storage.md) for more details about configuring Paperclip with S3.
|
See [our S3 guide](./using-aws-s3-as-storage.md) for more details about configuring Paperclip with S3.
|
||||||
|
|
||||||
|
### Configure Sendgrid
|
||||||
|
|
||||||
|
Add the SendGrid add-on in Heroku. It will create a SendGrid account for you with `ENV["SENDGRID_USERNAME"]` and `ENV["SENDGRID_PASSWORD"]`.
|
||||||
|
|
||||||
|
Add this to `config/secrets.yml`, under the `production:` section:
|
||||||
|
|
||||||
|
```
|
||||||
|
mailer_delivery_method: :smtp
|
||||||
|
smtp_settings:
|
||||||
|
:address: "smtp.sendgrid.net"
|
||||||
|
:port: 587
|
||||||
|
:domain: "heroku.com"
|
||||||
|
:user_name: ENV["SENDGRID_USERNAME"]
|
||||||
|
:password: ENV["SENDGRID_PASSWORD"]
|
||||||
|
:authentication: "plain"
|
||||||
|
:enable_starttls_auto: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Important: Turn on one worker dyno so that emails get sent.
|
||||||
|
|
||||||
## Optional but recommended:
|
## Optional but recommended:
|
||||||
|
|
||||||
### Install rails\_12factor and specify the Ruby version
|
### Install rails\_12factor and specify the Ruby version
|
||||||
|
|||||||
@@ -1,36 +1,36 @@
|
|||||||
# Deploying on Heroku
|
# Instalación en Heroku
|
||||||
|
|
||||||
## Manual deployment
|
## Instalación manual
|
||||||
|
|
||||||
This tutorial assumes that you have already managed to clone CONSUL on your machine and gotten it to work.
|
Este tutorial asume que ya has conseguido clonar CONSUL en tu máquina y conseguir que funcione.
|
||||||
|
|
||||||
1. First, create a [Heroku](https://www.heroku.com) account if it isn't already done.
|
1. En primer lugar, necesitas crear una cuenta en [Heroku](https://www.heroku.com) si no lo has hecho ya.
|
||||||
2. Install the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) and sign in using
|
2. Instala [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) e inicia sesión con:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku login
|
heroku login
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Go to your CONSUL repository and instantiate the process
|
3. Accede a tu repositorio de CONSUL y crea una instancia
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd consul
|
cd consul
|
||||||
heroku create your-app-name
|
heroku create your-app-name
|
||||||
```
|
```
|
||||||
|
|
||||||
You can add the flag `--region eu` if you want to use their European servers instead of the US ones.
|
Puedes añadir `--region eu` si quieres utilizar servidores europeos en lugar de los estadounidenses.
|
||||||
|
|
||||||
If _your-app-name_ is not already taken, Heroku should now create your app.
|
Si _your-app-name_ no existe aún, Heroku creará tu aplicación.
|
||||||
|
|
||||||
4. Create a database using
|
4. Crea la base de datos con
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku addons:create heroku-postgresql
|
heroku addons:create heroku-postgresql
|
||||||
```
|
```
|
||||||
|
|
||||||
You should now have access to an empty Postgres database whose address was automatically saved as an environment variable named _DATABASE\_URL_. CONSUL will automatically connect to it when deployed.
|
Ahora deberías tener acceso a una base de datos Postgres vacía cuya dirección se guardó automáticamente como una variable de entorno llamada _DATABASE\_URL_. CONSUL se conectará automáticamente a ella durante la instalación.
|
||||||
|
|
||||||
5. **(Not needed)** Add a file name _heroku.yml_ at the root of your project and paste the following in it
|
5. **(No es necesario)** Crea un archivo con el nombre _heroku.yml_ en la raíz del proyecto y añade el siguiente código
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
build:
|
build:
|
||||||
@@ -42,19 +42,19 @@ This tutorial assumes that you have already managed to clone CONSUL on your mach
|
|||||||
web: bundle exec rails server -e ${RAILS_ENV:-production}
|
web: bundle exec rails server -e ${RAILS_ENV:-production}
|
||||||
```
|
```
|
||||||
|
|
||||||
6. Now, generate a secret key and save it to an ENV variable named SECRET\_KEY\_BASE using
|
6. Ahora, genera una clave secreta y guárdala en la variable de entorno SECRET\_KEY\_BASE de la siguinte manera
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku config:set SECRET_KEY_BASE=$(rails secret)
|
heroku config:set SECRET_KEY_BASE=$(rails secret)
|
||||||
```
|
```
|
||||||
|
|
||||||
Also add your server address:
|
Añade también la dirección de tu servidor:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku config:set SERVER_NAME=myserver.address.com
|
heroku config:set SERVER_NAME=myserver.address.com
|
||||||
```
|
```
|
||||||
|
|
||||||
You need to let the app know where the configuration variables are stored by adding a link to the ENV variables in _config/secrets.yml_
|
Es necesario que la aplicación sepa dónde se almacenan las variables de configuración añadiendo un enlace a las variables de entorno en _config/secrets.yml_
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
production:
|
production:
|
||||||
@@ -62,28 +62,28 @@ This tutorial assumes that you have already managed to clone CONSUL on your mach
|
|||||||
server_name: <%= ENV["SERVER_NAME"] %>
|
server_name: <%= ENV["SERVER_NAME"] %>
|
||||||
```
|
```
|
||||||
|
|
||||||
and commit this file in the repo by commenting out the corresponding line in the _.gitignore_.
|
y añade este archivo en el repositorio comentando la línea correspondiente en el _.gitignore_.
|
||||||
|
|
||||||
```gitignore
|
```gitignore
|
||||||
#/config/secrets.yml
|
#/config/secrets.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
**Remember not to commit the file if you have any sensitive information in it!**
|
**¡Recuerda no añadir el archivo si tienes información sensible en él!**
|
||||||
|
|
||||||
7. You can now push your app using
|
7. Ahora ya puedes subir tu aplicación utilizando:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git push heroku your-branch:master
|
git push heroku your-branch:master
|
||||||
```
|
```
|
||||||
|
|
||||||
8. It won't work straight away because the database doesn't contain the tables needed. To create them, run
|
8. No funcionará de inmediato porque la base de datos no contiene las tablas necesarias. Para crearlas, ejecuta
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku run rake db:migrate
|
heroku run rake db:migrate
|
||||||
heroku run rake db:seed
|
heroku run rake db:seed
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to add the test data in the database, move `gem 'faker', '~> 1.8.7'` outside of `group :development` and run
|
Si quieres añadir los datos de prueba en la base de datos, mueve `gem 'faker', '~> 1.8.7'` fuera del `group :development` y ejecuta:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku config:set DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
|
heroku config:set DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
|
||||||
@@ -91,29 +91,49 @@ This tutorial assumes that you have already managed to clone CONSUL on your mach
|
|||||||
heroku run rake db:dev_seed
|
heroku run rake db:dev_seed
|
||||||
```
|
```
|
||||||
|
|
||||||
9. Your app should now be ready to use. You can open it with
|
9. Ahora tu aplicación debería estar ya opertaiva. Puedes abrirla con
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku open
|
heroku open
|
||||||
```
|
```
|
||||||
|
|
||||||
You also can run the console on heroku using
|
También puedes arrancar la consola en heroku utilizando
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku console --app your-app-name
|
heroku console --app your-app-name
|
||||||
```
|
```
|
||||||
|
|
||||||
10. Heroku doesn't allow to save images or documents in its servers, so it's necessary to setup a permanent storage space.
|
10. Heroku no permite guardar imágenes o documentos en sus servidores, por lo que es necesario configurar un nuevo espacio de almacenamiento.
|
||||||
|
|
||||||
See [our S3 guide](./using-aws-s3-as-storage.md) for more details about configuring Paperclip with S3.
|
Consulta [nuestra guía de S3](./using-aws-s3-as-storage.md) para más detalles sobre la configuración de Paperclip con S3.
|
||||||
|
|
||||||
## Optional but recommended:
|
### Configurar Sendgrid
|
||||||
|
|
||||||
### Install rails\_12factor and specify the Ruby version
|
Añade el complemento (add-on) de SendGrid en Heroku. Esto creará una cuenta de SendGrid para la aplicación con `ENV["SENDGRID_USERNAME"]` y `ENV["SENDGRID_PASSWORD"]`.
|
||||||
|
|
||||||
**The rails\_12factor is only useful if you use a version of CONSUL older than 1.0.0. The latter uses Rails 5 which includes the changes.**
|
Añade el siguiente código a `config/secrets.yml`, en la sección `production:`:
|
||||||
|
|
||||||
As recommended by Heroku, you can add the gem rails\_12factor and specify the version of Ruby you want to use. You can do so by adding
|
```
|
||||||
|
mailer_delivery_method: :smtp
|
||||||
|
smtp_settings:
|
||||||
|
:address: "smtp.sendgrid.net"
|
||||||
|
:port: 587
|
||||||
|
:domain: "heroku.com"
|
||||||
|
:user_name: ENV["SENDGRID_USERNAME"]
|
||||||
|
:password: ENV["SENDGRID_PASSWORD"]
|
||||||
|
:authentication: "plain"
|
||||||
|
:enable_starttls_auto: true
|
||||||
|
```
|
||||||
|
|
||||||
|
Importante: Activa un "worker dyno" para que se envíen los correos electrónicos.
|
||||||
|
|
||||||
|
### Opcional (pero recomendado):
|
||||||
|
|
||||||
|
### Instalar rails\_12factor y especificar la versión de Ruby
|
||||||
|
|
||||||
|
**Instalar rails\_12factor sólo es útil si utilizas una versión de CONSUL anterior a la 1.0.0. La última versión utiliza Rails 5 que ya incluye los cambios.**
|
||||||
|
|
||||||
|
Como nos recomienda Heroku, puedes añadir la gema rails\_12factor y especificar la versión de Ruby a utilizar. Puedes hacerlo añadiendo:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
gem 'rails_12factor'
|
gem 'rails_12factor'
|
||||||
@@ -121,44 +141,44 @@ gem 'rails_12factor'
|
|||||||
ruby 'x.y.z'
|
ruby 'x.y.z'
|
||||||
```
|
```
|
||||||
|
|
||||||
in the file _Gemfile\_custom_, where `x.y.z` is the version defined in the `.ruby-version` file in the CONSUL repository. Don't forget to run
|
en el archivo _Gemfile\_custom_, donde `x.y.z` es la versión definida en el fichero `.ruby-version` del repositorio de CONSUL. No olvides ejecutar
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bundle install
|
bundle install
|
||||||
```
|
```
|
||||||
|
|
||||||
to generate _Gemfile.lock_ before commiting and pushing to the server.
|
para generar el _Gemfile.lock_ antes de añadir los cambios y subirlos al servidor.
|
||||||
|
|
||||||
### Use Puma as a web server
|
### Utilizar Puma como servidor web
|
||||||
|
|
||||||
Heroku recommends to use Puma to improve the responsiveness of your app on [a number of levels](http://blog.scoutapp.com/articles/2017/02/10/which-ruby-app-server-is-right-for-you).
|
Heroku recomienda utilizar Puma para mejorar el [rendimiento](http://blog.scoutapp.com/articles/2017/02/10/which-ruby-app-server-is-right-for-you) de la aplicación.
|
||||||
|
|
||||||
If you want to allow more concurrency, uncomment the line:
|
Si quieres permitir más concurrencia, descomenta la siguiente linea:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
||||||
```
|
```
|
||||||
|
|
||||||
You can find an explanation for each of these settings in the [Heroku tutorial](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
|
Puedes encontrar una explicación para diferentes configuraciones en el siguiente [tutorial de Heroku](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server).
|
||||||
|
|
||||||
The last part is to change the _web_ task to use Puma by changing it to this in your _heroku.yml_ file:
|
Por último hay que cambiar la tarea _web_ para usar Puma cambiándola en el archivo _heroku.yml_ con el siguiente código:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
web: bundle exec puma -C config/puma.rb
|
web: bundle exec puma -C config/puma.rb
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add configuration variables to tune your app from the dashboard
|
### Añadir variables de configuración desde el panel de control
|
||||||
|
|
||||||
The free and hobby versions of Heroku are barely enough to run an app like CONSUL. To optimise the response time and make sure the app doesn't run out of memory, you can [change the number of workers and threads](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#workers) that Puma uses.
|
Las versiones gratuita y hobby de Heroku no son suficientes para ejecutar una aplicación como CONSUL. Para optimizar el tiempo de respuesta y asegurarte de que la aplicación no se quede sin memoria, puedes [cambiar el número de "workers" e hilos](https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#workers) que utiliza Puma.
|
||||||
|
|
||||||
My recommended settings are one worker and three threads. You can set it by running these two commands:
|
La configuración recomendada es un "worker" y tres hilos. Puedes configurarlo ejecutando estos dos comandos:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
heroku config:set WEB_CONCURRENCY=1
|
heroku config:set WEB_CONCURRENCY=1
|
||||||
heroku config:set RAILS_MAX_THREADS=3
|
heroku config:set RAILS_MAX_THREADS=3
|
||||||
```
|
```
|
||||||
|
|
||||||
I also recommend to set the following:
|
También es recomendable configurar las siguientes variables:
|
||||||
```bash
|
```bash
|
||||||
heroku config:set RAILS_SERVE_STATIC_FILES=enabled
|
heroku config:set RAILS_SERVE_STATIC_FILES=enabled
|
||||||
heroku config:set RAILS_ENV=production
|
heroku config:set RAILS_ENV=production
|
||||||
|
|||||||
Reference in New Issue
Block a user