-
Notifications
You must be signed in to change notification settings - Fork 10
/
buildkite-agent.rb
133 lines (107 loc) · 3.66 KB
/
buildkite-agent.rb
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
133
class BuildkiteAgent < Formula
desc "Build runner for use with Buildkite"
homepage "https://buildkite.com/docs/agent"
stable do
version "3.88.0"
if Hardware::CPU.arm?
url "https://github.com/buildkite/agent/releases/download/v3.88.0/buildkite-agent-darwin-arm64-3.88.0.tar.gz"
sha256 "c695ce4dcfc19203ecb7c414c28dd7d661e871b6b39c8220e4f0d3a69243e8af"
else
url "https://github.com/buildkite/agent/releases/download/v3.88.0/buildkite-agent-darwin-amd64-3.88.0.tar.gz"
sha256 "734366fe233bc19c49928064e3bba8879b4b0db4f5f93eb940fd6e89b94ad7c4"
end
end
def agent_etc
etc/"buildkite-agent"
end
def agent_var
var/"buildkite-agent"
end
def agent_hooks_path
agent_etc/"hooks"
end
def agent_builds_path
agent_var/"builds"
end
def agent_plugins_path
agent_var/"plugins"
end
def agent_bootstrap_path
if stable?
agent_etc/"bootstrap.sh"
else
opt_bin/"buildkite-agent bootstrap"
end
end
def agent_config_path
agent_etc/"buildkite-agent.cfg"
end
def agent_config_dist_path
pkgshare/"buildkite-agent.dist.cfg"
end
def install
agent_etc.mkpath
agent_var.mkpath
pkgshare.mkpath
agent_hooks_path.mkpath
agent_builds_path.mkpath
agent_hooks_path.install Dir["hooks/*"]
if stable?
agent_etc.install "bootstrap.sh"
end
agent_config_dist_path.write(default_config_file)
if agent_config_path.exist?
puts "\033[35mIgnoring existing config file at #{agent_config_path}\033[0m"
puts "\033[35mFor changes see the updated dist copy at #{agent_config_dist_path}\033[0m"
else
agent_config_path.write(default_config_file)
end
bin.install "buildkite-agent"
end
def default_config_file
File.read("buildkite-agent.cfg")
.gsub(/bootstrap-script=.+/, "bootstrap-script=\"#{agent_bootstrap_path}\"")
.gsub(/build-path=.+/, "build-path=\"#{agent_builds_path}\"")
.gsub(/hooks-path=.+/, "hooks-path=\"#{agent_hooks_path}\"")
.gsub(/plugins-path=.+/, "plugins-path=\"#{agent_plugins_path}\"")
end
def caveats
<<~EOS
\033[32mbuildkite-agent is now installed!\033[0m
\033[31mDon't forget to update your configuration file with your agent token\033[0m
Configuration file (to configure agent token, meta-data, priority, name, etc):
#{agent_config_path}
Hooks directory (for customising the agent):
#{agent_hooks_path}
Builds directory:
#{agent_builds_path}
Log paths:
#{var}/log/buildkite-agent.log
#{var}/log/buildkite-agent.error.log
If you set up the LaunchAgent, set your machine to auto-login as
your current user.
To prevent your machine from sleeping or logging out, use `caffeinate`. For
example, running `caffeinate -i buildkite-agent start` runs buildkite-agent
and prevents the system from idling until it exits. Run `man caffeinate` for
details.
To run multiple agents simply run the buildkite-agent start command
multiple times, or duplicate the LaunchAgent plist to create another
that starts on login.
EOS
end
service do
run [
HOMEBREW_PREFIX/"bin/buildkite-agent", "start",
"--config", etc/"buildkite-agent/buildkite-agent.cfg"
]
working_dir HOMEBREW_PREFIX/"bin" # Why?
keep_alive successful_exit: false
environment_variables PATH: HOMEBREW_PREFIX/"bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
process_type :interactive
log_path var/"log/buildkite-agent.log"
error_log_path var/"log/buildkite-agent.log"
end
test do
system "#{bin}/buildkite-agent", "--help"
end
end