summaryrefslogtreecommitdiff
path: root/Rakefile
blob: 21646453824550a60794b9fe71abe43e0fc50bba (plain)
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
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