Skip to content

Instantly share code, notes, and snippets.

@abhionlyone
Last active April 20, 2022 19:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save abhionlyone/d8053ed27303df3c8e6b0e6e760ad9f2 to your computer and use it in GitHub Desktop.
Save abhionlyone/d8053ed27303df3c8e6b0e6e760ad9f2 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, "git@bitbucket.org: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