Set up Mina to use Passenger and Docker

460 views Asked by At

I am trying to set up Mina's deploy.rb file. However, I am running into several hurdles.

My Rails 5 app uses Docker for the database (PostgreSQL) and Redis for background jobs. I am also using Phusion Passenger (Nginx) for the webserver.

This is what my deploy.rb file looks like at the moment:

require 'mina/rails'
require 'mina/git'
require 'mina/rvm'

set :application_name, 'App'
set :domain, 'my_app.com'
set :deploy_to, '/var/www/my_app.com'
set :repository, '[email protected]:MyUser/my_app.git'
set :branch, 'master'

# Username in the server to SSH to.
set :user, 'myuser'

# shared dirs and files will be symlinked into the app-folder by the 
# Not sure if this is necessary
'deploy:link_shared_paths' step.
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'tmp/pids', 'tmp/sockets', 'public/uploads')
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml', 'config/puma.rb')

task :environment do
  invoke :'rvm:use', 'ruby-2.4.1@default'
end

task :setup do
  %w(database.yml secrets.yml puma.rb).each { |f| command %[touch "#{fetch(:shared_path)}/config/#{f}"] }
  comment "Be sure to edit #{fetch(:shared_path)}/config/database.yml, secrets.yml and puma.rb."
end

desc "Deploys the current version to the server."
task :deploy do
  deploy do
    comment "Deploying #{fetch(:application_name)} to #{fetch(:domain)}:#{fetch(:deploy_to)}"
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    comment 'Cleaning up Docker builds'
    command 'docker stop $(docker ps -qa)'
    command 'docker rm $(docker ps -qa)'
    comment 'Stopping Docker'
    command 'docker-compose stop'
    comment 'Starting Docker'
    command 'docker-compose up -d; sleep 5'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'
  end
end

I came up with this file looking a bit here a bit there. It seems to run properly. However, here are the problems I am facing:

  1. I am not able to run passenger-config restart-app $(pwd) or passenger-config restart-app $(#{fetch(:current_path)}) so I am having to restart Passenger by logging into the server and run the command manually for some reason. This kind of defeats the purpose of using Mina, which should automate the deploy process.

  2. Once I start Passenger, I am seeing a database error like:

    F, [2017-08-21T08:42:40.145292 #29048] FATAL -- : [28d9fb0f-f187-4d16-b3bc-f947c4ec726f] F, [2017-08-21T08:42:40.145378 #29048] FATAL -- : [28d9fb0f-f187-4d16-b3bc-f947c4ec726f] ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "subscriptions" does not exist LINE 8: WHERE a.attrelid = '"subscriptions"'::regclas...

But I am sure that this is not erring in dev so I think it might have to do with how I am deploying Docker in production.

Does anyone have an idea of how I can get a proper Docker + Passenger setup with Mina?

Just for the extra info, my docker-compose.yml file looks like this:

version: "2"
services:
  postgres:
    image: postgres:9.6
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: "${DATABASE_NAME}"
      POSTGRES_PASSWORD: "${DATABASE_PASSWORD}"
    volumes:
      - postgres-data:/var/lib/postgresql/data
  redis:
    image: redis:latest
    ports:
      - "6379:6379"
volumes:
  postgres-data:
    driver: local

Thanks in advance!

0

There are 0 answers