summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile82
1 files changed, 82 insertions, 0 deletions
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..2164645
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,82 @@
+require 'erb'
+require 'rake'
+require 'rexml/document'
+
+# ERB processing template.
+class Template
+ def name
+ @name ||= 0
+ @name += 1
+ "name_a#{@name}"
+ end
+
+ def erb(file)
+ ERB.new(File.read(file), nil, '-', name).result(binding)
+ end
+end
+
+GCLOUD_PROJECT = 'responsive-task-141123'
+IMAGE_NAME = 'blog'
+
+SOURCE_FILES = Rake::FileList['**/*.adoc']
+IGNORABLE = Rake::FileList[
+ '_site/Rakefile',
+ '_site/build/**',
+ '_site/node_modules/**',
+ '_site/firebase.json',
+]
+TEMPLATES = Rake::FileList['build/*.erb']
+
+task :s => [:serve]
+task :b => [:build]
+
+task :serve do
+ sh 'jekyll serve'
+end
+
+task :jekyll do
+ sh 'jekyll build'
+end
+
+task :all => [:build]
+
+task :build => [:jekyll] do
+ files = Rake::FileList['_site/**/*.html']
+ files.each do |f|
+ Rake::Task[f.gsub(/\.html$/, '.xhtml')].invoke
+ end
+ rm files
+ rm_r IGNORABLE
+end
+
+task :templates do
+ TEMPLATES.each do |f|
+ fp = File.open(f.sub(/\.erb$/, ''), 'w')
+ fp.print Template.new.erb(f)
+ fp.close
+ end
+end
+
+task :deploy => [:templates] do
+ image = "gcr.io/#{GCLOUD_PROJECT}/#{IMAGE_NAME}"
+ sh "docker build -t #{image} -f build/Dockerfile.deploy ."
+ sh "docker push #{image}"
+ sh "gcloud beta run deploy --project #{GCLOUD_PROJECT} --allow-unauthenticated --region us-central1 --image #{image} #{IMAGE_NAME}"
+ # Note that "npm install --no-package-lock firebase-tools" must have been run.
+ sh "node_modules/.bin/firebase deploy --project #{GCLOUD_PROJECT}"
+ sh "gcloud container images delete #{image}:latest"
+end
+
+task :check => [:build] do
+ Rake::FileList['_site/**/*.html', '_site/**/*.xhtml'].each do |f|
+ begin
+ REXML::Document.new(File.read(f))
+ rescue StandardError => e
+ raise "Failed well-formedness check for #{f}: #{e}"
+ end
+ end
+end
+
+rule '.xhtml' => ['.html'] do |t|
+ cp t.source, t.name
+end