-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
123 lines (96 loc) · 3.17 KB
/
Rakefile
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
require 'rake/clean'
require 'json'
require 'yaml'
load 'test/pkg/Rakefile'
CURRENT_VERSION = "0.2.0"
PC_USER = "appcanary"
PC_REPO = "agent"
PC_STAGING_REPO = "appcanary-stg"
@built_packages = []
def production?
@isproduction ||= (ENV["CANARY_ENV"] == "production")
end
# gets result of shell command
def shell(str)
puts str
`#{str}`.strip
end
# execute a shell command and print stderr
def exec(str)
puts str
system str
end
task :default => :build
task :build_all => [:setup, :build]
desc "Build the program into ./bin/appcanary"
task :build do
@ldflags = %{"-X main.CanaryVersion=#{@release_version || "unreleased"}"}
# actually, do we need to run this every time? let's not for now.
# shell "go-bindata -pkg detect -o agent/detect/bindata.go agent/resources/"
shell "go build -ldflags #{@ldflags} -o ./bin/appcanary"
end
desc "Build and run all go tests"
task :test => :build_all do
sh "go test -v ./... -race -timeout 100s"
end
desc "Build and run a specific go test"
task :testr => :build_all do
sh "go test -v ./... -race -timeout 100s -run #{ENV["t"]}"
end
desc "Generate release version from date"
task :release_prep do
if production?
if `git diff --shortstat` != ""
puts "Whoa there, partner. Dirty trees can't deploy. Git yourself clean"
exit 1
end
end
@date = `date -u +"%Y.%m.%d-%H%M%S-%Z"`.strip
@release_version = "#{CURRENT_VERSION}-#{@date}"
end
desc "Cross compile a binary for every architecture"
task :cross_compile => :release_prep do
puts "\n\n\n#################################"
puts "Cross compiling packages."
puts "#################################\n\n\n"
@ldflags = %{-X main.CanaryVersion=#{@release_version}}
shell %{env GOARCH=386 GOOS=linux go build -ldflags "#{@ldflags}" -o dist/#{@release_version}/linux_i386/appcanary github.com/appcanary/agent}
shell %{env GOARCH=amd64 GOOS=linux go build -ldflags "#{@ldflags}" -o dist/#{@release_version}/linux_amd64/appcanary github.com/appcanary/agent}
end
desc "Generate a package archive for every operating system we support"
task :package => :cross_compile do
load 'package/packager.rb'
puts "\n\n\n#################################"
puts "Building packages."
puts "#################################\n\n\n"
[UbuntuRecipe, CentosRecipe, DebianRecipe, MintRecipe, FedoraRecipe].each do |rcp|
puts "#######"
puts "#{rcp.distro}"
puts "#######\n\n"
@built_packages = @built_packages + rcp.new(@release_version).build_packages
end
end
desc "Cross compile, package and deploy packages to package cloud"
task :deploy => :package do # "integration:test" do
publisher = nil
if production?
publisher = PackagePublisher.new(PC_USER, PC_REPO)
else
publisher = PackagePublisher.new(PC_USER, PC_STAGING_REPO)
end
@built_packages.each do |pkg|
publisher.publish!(pkg)
end
sha = shell %{git rev-parse --short HEAD}
user = `whoami`.strip
commit_message = "#{user} deployed #{sha}"
if production?
shell %{git tag -a #{@release_version} -m "#{commit_message}"}
shell %{git push origin #{@release_version}}
end
end
task :release => [:release_prep, :default, :package]
task :setup do
`mkdir -p ./bin`
`rm -f ./bin/*`
end