From 359cba7c396feaabd5cc43a34c5531a934dc969e Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Wed, 2 Nov 2022 13:50:49 -0300 Subject: [PATCH] add Tasks::Deploy::Remote add a task for deploying the website to a remote - using rsync. --- .env.sample | 3 +++ .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 2 ++ Rakefile.rb | 6 ++++++ lib/tasks/deploy.rb | 1 + lib/tasks/deploy/remote.rb | 39 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 53 insertions(+) create mode 100644 .env.sample create mode 100644 lib/tasks/deploy/remote.rb diff --git a/.env.sample b/.env.sample new file mode 100644 index 000000000..f29b5f741 --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +DEPLOY_HOSTNAME= +DEPLOY_USERNAME= +DEPLOY_PATH= diff --git a/.gitignore b/.gitignore index 03c9b6124..484aacb3c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/ tmp/ node_modules/ *.log +.env diff --git a/Gemfile b/Gemfile index 17e071f85..ffbb04e15 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gem "sass" gem "standardrb" gem "ryo.rb" gem "paint" +gem "dotenv" diff --git a/Gemfile.lock b/Gemfile.lock index 038a9884d..e74e06f81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ GEM ddmetrics (1.0.1) ddplugin (1.0.3) diff-lcs (1.5.0) + dotenv (2.8.1) em-websocket (0.5.3) eventmachine (>= 0.12.9) http_parser.rb (~> 0) @@ -130,6 +131,7 @@ PLATFORMS x86_64-freebsd-13 DEPENDENCIES + dotenv nanoc (~> 4.12) nanoc-live (~> 1.0) paint diff --git a/Rakefile.rb b/Rakefile.rb index c202051e8..c18e986cb 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -15,6 +15,12 @@ namespace :deploy do task local: ["nanoc:compile"] do Deploy::Local.call end + + task remote: ["nanoc:compile"] do + require "dotenv" + Dotenv.load + Deploy::Remote.call + end end namespace :linter do diff --git a/lib/tasks/deploy.rb b/lib/tasks/deploy.rb index b7981cf10..4d4765f9d 100644 --- a/lib/tasks/deploy.rb +++ b/lib/tasks/deploy.rb @@ -2,4 +2,5 @@ module Tasks::Deploy require_relative "deploy/local" + require_relative "deploy/remote" end diff --git a/lib/tasks/deploy/remote.rb b/lib/tasks/deploy/remote.rb new file mode 100644 index 000000000..ae8e1deda --- /dev/null +++ b/lib/tasks/deploy/remote.rb @@ -0,0 +1,39 @@ +# 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=Du=rwx,Fu=rw", + @build_dir, "#{@user}@#{@hostname}:#{@path}" + ) + if $?.success? + print "\n", Paint["OK", :green, :bold] + else + print Paint["ERROR", :red, :bold] + exit! + end + end +end