Skip to content

dummy rails 6 project with capistrano setup and deployed to ubuntu 18.04

Notifications You must be signed in to change notification settings

suncrud/rails6_capistrano_setup

Repository files navigation

Rails 6 capistrano setup for staging environment

specification

  • Ruby 2.6.5
  • Rails 6.0.0
  • capistrano
  • ubuntu 18.04
  • nginx / passenger

documents

employed environment variables

# .env

PEM_DIRECTORY=
REPO_URL=
APP_NAME=
STAGING_DEPLOY_DIRECTORY=
STAGING_SERVER_IP=
STAGING_SERVER_USER=

# Double check requirement of these for variables below in the staging environment .env file

STAGING_DB_DATABASE=
STAGING_DB_USERNAME=
STAGING_DB_PASSWORD=
STAGING_SECRET_KEY_BASE=
# not sure if the last STAGING_SECRET_KEY_BASE can be dealt by rails credentials rather than here.

potential issues/setbacks

$ irb
>> require 'securerandom'
=> true
>> SecureRandom.hex(64)
=> "3fe397575565365108556c3e5549f139e8078a8ec8fd2675a83de96289b30550a266ac04488d7086322efbe573738e7b3ae005b2e3d9afd718aa337fa5e329cf"
>> exit
  • nginx setup
# /etc/nginx/sites-enabled/myapp
server {
  listen 80;
  listen [::]:80;

  server_name _;
  root /home/deploy/myapp/current/public;

  passenger_enabled on;
  passenger_app_env production;

  location /cable {
    passenger_app_group_name myapp_websocket;
    passenger_force_max_concurrent_requests_per_process 0;
  }

  # Allow uploads up to 100MB in size
  client_max_body_size 100m;

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  }
}

# double check to match  passenger_app_env to staging or your specific environment
ii. Define staging environment for Webpacker — Rails 6 also requires setting environment for webpacker.
You need to add staging section in config/webpacker.yml file.
You can simply copy the production block from the same file and edit for staging.
Also you need to create config/webpack/staging.js file.
You can copy the contents from config/webpack/production.js into staging.js file.
  • employing .env variables with the right syntax
## pay attention to the syntax
# config/database.yml
staging:
  adapter: mysql2
  database: <%= ENV["STAGING_DB_DATABASE"] %>
  username: <%= ENV["STAGING_DB_USERNAME"] %>
  password: <%= ENV["STAGING_DB_PASSWORD"] %>
  encoding: utf8
  host: localhost
  timeout: 5000
  encoding: utf8mb4
  collation: utf8mb4_unicode_ci
  • adding '.env' into linked file in capistrano setup for staging environment
# config/deploy.rb
append :linked_files, ".env"

## this creates sym link in the server under myapp/shared/

About

dummy rails 6 project with capistrano setup and deployed to ubuntu 18.04

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published