Skip to content

Instantly share code, notes, and snippets.

@jayshreeanand
Forked from abhionlyone/Capfile
Created August 19, 2020 19:02
Show Gist options
  • Select an option

  • Save jayshreeanand/ab8a3837adcd7e7461e1c0759685501c to your computer and use it in GitHub Desktop.

Select an option

Save jayshreeanand/ab8a3837adcd7e7461e1c0759685501c to your computer and use it in GitHub Desktop.
create-react-app with capistrano for automated deployments
require "capistrano/setup"
require "capistrano/deploy"
require "capistrano/scm/git"
require 'capistrano/npm'
install_plugin Capistrano::SCM::Git
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
# config/deploy.rb
# config valid for current version and patch releases of Capistrano
lock "~> 3.10.2"
set :application, "app-name"
set :repo_url, "[email protected]:username/app-name.git"
set :ssh_options, { :forward_agent => true }
set :npm_flags, '--silent --no-progress'
namespace :deploy do
desc 'Restart application'
task :restart do
invoke 'react:build'
end
end
after 'deploy:publishing', 'deploy:restart'
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'capistrano', '~> 3.10', '>= 3.10.2'
gem 'capistrano-npm'
# lib/capistrano/tasks/react.rake
namespace :react do
desc 'RUN NPM BUILD'
task :build do
on roles(:app) do
execute "sh -c \"cd #{deploy_to}/current/ && #{fetch(:build_command)}\""
end
end
end
# config/deploy/staging.rb
set :branch, 'staging'
set :deploy_to, 'path_to_staging'
server 'your-server-ip-here', user: 'user', port: 22, roles: %w{web app db}
set :build_command, 'npm run build'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment