From 060cc9919fad6b6c984e91c0138e080ddab1d0d0 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 25 Mar 2023 08:53:22 -0300 Subject: [PATCH] Replace Tasks::Deploy::Remote --- Rakefile.rb | 32 ------------------------------ config/remote.yml.sample | 5 +++++ lib/tasks/deploy.rb | 5 ----- lib/tasks/deploy/remote.rb | 40 -------------------------------------- tasks/deploy.rake | 24 +++++++++++++++++++++-- 5 files changed, 27 insertions(+), 79 deletions(-) delete mode 100644 lib/tasks/deploy.rb delete mode 100644 lib/tasks/deploy/remote.rb diff --git a/Rakefile.rb b/Rakefile.rb index 7bc0b5c..2492bd1 100644 --- a/Rakefile.rb +++ b/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 diff --git a/config/remote.yml.sample b/config/remote.yml.sample index 0c7b54e..e7d1588 100644 --- a/config/remote.yml.sample +++ b/config/remote.yml.sample @@ -3,6 +3,11 @@ rc: hostname: +## +# deploy +deploy: + uri: user@hostname:/path/ + ## # nginx nginx: diff --git a/lib/tasks/deploy.rb b/lib/tasks/deploy.rb deleted file mode 100644 index 4fd4870..0000000 --- a/lib/tasks/deploy.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module Tasks::Deploy - require_relative "deploy/remote" -end diff --git a/lib/tasks/deploy/remote.rb b/lib/tasks/deploy/remote.rb deleted file mode 100644 index fcbd078..0000000 --- a/lib/tasks/deploy/remote.rb +++ /dev/null @@ -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 diff --git a/tasks/deploy.rake b/tasks/deploy.rake index c7ce3fa..cb422d6 100644 --- a/tasks/deploy.rake +++ b/tasks/deploy.rake @@ -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