Replace Tasks::Deploy::Remote
This commit is contained in:
parent
a475109b4d
commit
060cc9919f
5 changed files with 27 additions and 79 deletions
32
Rakefile.rb
32
Rakefile.rb
|
@ -41,38 +41,6 @@ namespace :watch do
|
|||
end
|
||||
end
|
||||
|
||||
namespace :deploy do
|
||||
desc "Deploy to production"
|
||||
task remote: ["env:verify-production-branch",
|
||||
"env:set-production-vars",
|
||||
"nanoc:clean",
|
||||
"nanoc:compile"] do
|
||||
Tasks::Deploy::Remote.call
|
||||
end
|
||||
end
|
||||
|
||||
namespace :env do
|
||||
desc "Verify the production branch is being used"
|
||||
task :"verify-production-branch" do
|
||||
git_branch = `git branch --show-current`.chomp
|
||||
if git_branch != "production"
|
||||
warn "This task can only be run on the 'production' branch."
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
desc "Set environment variables for the production environment"
|
||||
task :"set-production-vars" do
|
||||
require "dotenv"
|
||||
Dotenv.load
|
||||
end
|
||||
|
||||
desc "Set environment variables for the development environment"
|
||||
task :"set-development-vars" do
|
||||
ENV["NODE_ENV"] ||= "development"
|
||||
end
|
||||
end
|
||||
|
||||
namespace :lint do
|
||||
desc "Run rubocop (Ruby)"
|
||||
task :rubocop do
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
rc:
|
||||
hostname: <hostname>
|
||||
|
||||
##
|
||||
# deploy
|
||||
deploy:
|
||||
uri: user@hostname:/path/
|
||||
|
||||
##
|
||||
# nginx
|
||||
nginx:
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Tasks::Deploy
|
||||
require_relative "deploy/remote"
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Tasks::Deploy::Remote
|
||||
attr_reader :hostname, :user, :path
|
||||
|
||||
def self.call
|
||||
new.call
|
||||
end
|
||||
|
||||
def initialize
|
||||
@hostname = ENV["DEPLOY_HOSTNAME"]
|
||||
@user = ENV["DEPLOY_USERNAME"]
|
||||
@path = ENV["DEPLOY_PATH"]
|
||||
@build_dir = File.join(Dir.getwd, "build", "al-quran", ".")
|
||||
end
|
||||
|
||||
def call
|
||||
rsync!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rsync!
|
||||
print "Wait...", "\n"
|
||||
system(
|
||||
"rsync",
|
||||
"--delete",
|
||||
"-rvah",
|
||||
"--chmod=Fu=rw,Fg=r,Du=rwx,Dg=rx",
|
||||
"--rsync-path='/home/0x1eef/rsync.sh'",
|
||||
@build_dir, "#{@user}@#{@hostname}:#{@path}"
|
||||
)
|
||||
if $?.success?
|
||||
print "\n", Paint["OK", :green, :bold]
|
||||
else
|
||||
print Paint["ERROR", :red, :bold]
|
||||
exit!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -7,12 +7,16 @@ read_options = ->(env:) do
|
|||
end
|
||||
|
||||
desc "Deploy the website"
|
||||
task "deploy", [:env] => %i[nanoc:compile] do |task, args|
|
||||
task "deploy", [:env] do |task, args|
|
||||
env = args[:env]
|
||||
case env
|
||||
when "remote"
|
||||
# TODO
|
||||
ENV["NODE_ENV"] = "production"
|
||||
Rake::Task["nanoc:clean"].invoke
|
||||
Rake::Task["nanoc:compile"].invoke
|
||||
Rake::Task["deploy:remote"].invoke
|
||||
when "local"
|
||||
Rake::Task["nanoc:compile"].invoke
|
||||
if Process.euid != 0
|
||||
sh "doas -u root bundle exec rake deploy:local"
|
||||
exit $?.exitstatus
|
||||
|
@ -34,3 +38,19 @@ task "deploy:local" do
|
|||
sh "chmod -R og-rwx #{dest_dir}"
|
||||
sh "chmod -R u+rwX #{dest_dir}"
|
||||
end
|
||||
|
||||
task "deploy:remote" do
|
||||
git_branch = `git branch --show-current`.chomp
|
||||
options = read_options.call(env: "remote")
|
||||
if git_branch != "production"
|
||||
warn "This task can only be run on the 'production' branch."
|
||||
exit(1)
|
||||
end
|
||||
print "Wait...", "\n"
|
||||
sh(
|
||||
"rsync", "--delete", "-rvah",
|
||||
"--chmod=Fu=rw,Fg=r,Du=rwx,Dg=rx",
|
||||
"--rsync-path='/home/0x1eef/rsync.sh'",
|
||||
"build/al-quran", options.deploy.uri
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue