deploy: 'rake deploy' deploys to production
And remove unused tasks
This commit is contained in:
parent
3b0a0c08ab
commit
3efe5cddd3
1 changed files with 6 additions and 37 deletions
|
@ -1,45 +1,14 @@
|
||||||
##
|
##
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
read_options = ->(env:) do
|
desc "Configure environment for deployment"
|
||||||
path = File.join(Dir.getwd, "config", "#{env}.yml")
|
task "deploy:env" do
|
||||||
Ryo.from(YAML.load_file(path))
|
ENV["NODE_ENV"] = "production"
|
||||||
|
print "Set $NODE_ENV to 'production'", "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Deploy the website"
|
desc "Deploy the website"
|
||||||
task "deploy", [:env] do |task, args|
|
task "deploy" => %i[deploy:env nanoc:clean nanoc:compile] do
|
||||||
env = args[:env]
|
|
||||||
case env
|
|
||||||
when "remote"
|
|
||||||
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
|
|
||||||
end
|
|
||||||
Rake::Task["deploy:local"].invoke
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
task "deploy:local" do
|
|
||||||
options = read_options.call(env: "local")
|
|
||||||
logs_dir = File.dirname(options.nginx.logs.access)
|
|
||||||
dest_dir = options.nginx.root
|
|
||||||
chown = Array.new(2) { options.nginx.user }.join(":")
|
|
||||||
sh "mkdir -p #{logs_dir}"
|
|
||||||
sh "mkdir -p #{dest_dir}"
|
|
||||||
sh "rm -rf #{File.join(dest_dir, "*")}"
|
|
||||||
sh "cp -R build/al-quran/ #{dest_dir}"
|
|
||||||
sh "chown -R #{chown} #{dest_dir}"
|
|
||||||
sh "chmod -R og-rwx #{dest_dir}"
|
|
||||||
sh "chmod -R u+rwX #{dest_dir}"
|
|
||||||
end
|
|
||||||
|
|
||||||
task "deploy:remote" => %i[nanoc:clean] do
|
|
||||||
git_branch = `git branch --show-current`.chomp
|
git_branch = `git branch --show-current`.chomp
|
||||||
if git_branch != "production"
|
if git_branch != "production"
|
||||||
warn "This task can only be run on the 'production' branch."
|
warn "This task can only be run on the 'production' branch."
|
||||||
|
@ -49,7 +18,7 @@ task "deploy:remote" => %i[nanoc:clean] do
|
||||||
sh(
|
sh(
|
||||||
"rsync",
|
"rsync",
|
||||||
"--delete", "-rvah",
|
"--delete", "-rvah",
|
||||||
"--chmod=Fu=rw,Fg=r,Du=rwx,Dg=rx",
|
"--chmod=Fu=r,Fg=r,Du=rx,Dg=rx",
|
||||||
"--rsync-path='/home/0x1eef/rsync.sh'",
|
"--rsync-path='/home/0x1eef/rsync.sh'",
|
||||||
"--exclude=audio/",
|
"--exclude=audio/",
|
||||||
"build/al-quran/",
|
"build/al-quran/",
|
||||||
|
|
Loading…
Reference in a new issue