This repository was archived by the owner on Jun 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile.rb
More file actions
132 lines (114 loc) · 4.37 KB
/
Copy pathRakefile.rb
File metadata and controls
132 lines (114 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# frozen_string_literal: true
## Deployment settings
gemspec = File.absolute_path(File.basename(File.dirname(__FILE__)) + ".gemspec")
artefact = Gem::Specification::load(gemspec).name
version = Gem::Specification::load(gemspec).version
domain = "#{artefact}.michaelnordmeyer.com"
log_path = '/var/log/nginx'
nginx_user = 'nginx'
nginx_group = 'adm'
ssh_host = 'michaelnordmeyer.com'
ssh_port = 1111
ssh_user = 'root'
ssh_path = "/srv/http/#{domain}/"
task :default => ["build"]
desc 'Builds the robots.txt'
task :robots do
puts "==> Building #{domain} robots.txt..."
sh "printf 'Sitemap: https://#{domain}/sitemap.xml\\n\\n' > robots.txt"
sh "printf 'User-agent: *\\nDisallow: /\\n' >> robots.txt"
end
desc 'Beautifies kramdown output'
task :beautify do
puts "==> Beautifying #{domain} kramdown output..."
sh "for file in _site/*.html _site/**/*.html; do sed -i '' -E 's,<((br|hr|img|link|meta).*) />,<\\1>,g' ${file}; done"
sh "for file in _site/*.html _site/**/*.html; do sed -i '' -E 's/ class=\"footnotes?\"//g' ${file}; done"
sh "for file in _site/*.html _site/**/*.html; do sed -i '' -E 's/ class=\"reversefootnote\"//g' ${file}; done"
end
desc 'Builds the site for deployment'
task :build do
Rake::Task[:robots].invoke
puts "==> Building #{domain}..."
sh 'JEKYLL_ENV="production" bundle exec jekyll build'
Rake::Task[:beautify].invoke
end
desc 'Serves the site locally'
task :serve do
Rake::Task[:robots].invoke
puts "==> Building and serving #{domain} locally..."
sh 'bundle exec jekyll serve'
end
desc 'Syncs the content of ./_site to the server via rsync'
task :rsync do
puts "==> Rsyncing #{domain}'s content to SSH host #{ssh_host}"
sh "ssh -p #{ssh_port} #{ssh_user}@#{ssh_host} 'touch #{log_path}/#{domain}.log && chown #{nginx_user}:#{nginx_group} #{log_path}/#{domain}.log'"
sh "rsync -e 'ssh -p #{ssh_port}' -vcrlptDShP --delete \
--rsync-path 'sudo -u #{ssh_user} rsync' --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r \
--exclude=.DS_Store \
--exclude=._* \
--exclude=.git \
--exclude=.gitignore \
--exclude=.github \
_site/ \
#{ssh_user}@#{ssh_host}:#{ssh_path}"
end
desc 'Copies robots.txt to the server via scp'
task :scprobots do
puts "==> Scp'ing #{domain} robots.txt to SSH host #{ssh_host}"
sh "scp -P #{ssh_port} robots.txt #{ssh_user}@#{ssh_host}:#{ssh_path}"
end
desc 'Compresses the site via SSH'
task :compress do
puts "==> Compressing #{domain} via SSH..."
sh "ssh -p #{ssh_port} #{ssh_user}@#{ssh_host} 'for file in $(find #{ssh_path} -type f -size +1100c -regex \".*\\.\\(css\\|map\\|html\\|js\\|json\\|svg\\|txt\\|xml\\)$\"); do printf . && gzip -kf -9 \"${file}\" && brotli -kf -q 9 \"${file}\"; done; echo'"
end
desc 'Compresses robots.txt via SSH'
task :compressrobots do
puts "==> Compressing #{domain} robots.txt via SSH..."
sh "ssh -p #{ssh_port} #{ssh_user}@#{ssh_host} 'gzip -kf -9 #{ssh_path}robots.txt && brotli -kf -q 9 #{ssh_path}robots.txt'"
end
desc 'Builds and deploys the site'
task :deploy do
puts "==> Building and deploying #{domain}..."
Rake::Task[:build].invoke
Rake::Task[:rsync].invoke
Rake::Task[:compress].invoke
Rake::Task[:clean].invoke
end
desc 'Builds and deploys the robots.txt'
task :deployrobots do
puts "==> Building and deploying #{domain} robots.txt..."
Rake::Task[:robots].invoke
Rake::Task[:scprobots].invoke
Rake::Task[:compressrobots].invoke
end
desc 'Cleans the source dir'
task :clean do
puts "==> Cleaning #{domain}..."
sh 'bundle exec jekyll clean'
end
desc 'Builds the gem'
task :gembuild do
puts "==> Building #{artefact} gem..."
sh "gem build #{artefact}.gemspec"
end
desc 'Installs the gem locally according to the gemspec\'s version'
task :geminstall do
puts "==> Installing #{artefact} gem locally..."
sh "gem install --local #{artefact}-#{version}.gem"
end
desc 'Uninstalls the gem according to the gemspec\'s version'
task :gemuninstall do
puts "==> Uninstalling #{artefact} gem..."
sh "gem uninstall #{artefact} --version #{version}"
end
desc 'Pushes the gem to rubygems.org according to the gemspec\'s version'
task :gempush do
puts "==> Pushing #{artefact} to rubygems.org..."
sh "gem push #{artefact}-#{version}.gem"
end
desc 'Pushes the gem to rubygems.org, needs version number like `rake gempush\[1.0.0\]`'
task :gempushversioned, [:version] do |task, args|
puts "==> Pushing #{artefact} to rubygems.org..."
sh "gem push #{artefact}-#{args[:version]}.gem"
end