overman 0.0.1 → 0.87.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +52 -0
  3. data/bin/foreman-runner +41 -0
  4. data/bin/overman +7 -0
  5. data/data/example/Procfile +4 -0
  6. data/data/example/Procfile.without_colon +2 -0
  7. data/data/example/error +7 -0
  8. data/data/example/log/neverdie.log +4 -0
  9. data/data/example/spawnee +14 -0
  10. data/data/example/spawner +7 -0
  11. data/data/example/ticker +14 -0
  12. data/data/example/utf8 +11 -0
  13. data/data/export/bluepill/master.pill.erb +28 -0
  14. data/data/export/daemon/master.conf.erb +14 -0
  15. data/data/export/daemon/process.conf.erb +8 -0
  16. data/data/export/daemon/process_master.conf.erb +2 -0
  17. data/data/export/launchd/launchd.plist.erb +33 -0
  18. data/data/export/runit/log/run.erb +7 -0
  19. data/data/export/runit/run.erb +4 -0
  20. data/data/export/supervisord/app.conf.erb +31 -0
  21. data/data/export/systemd/master.target.erb +5 -0
  22. data/data/export/systemd/process.service.erb +21 -0
  23. data/data/export/upstart/master.conf.erb +2 -0
  24. data/data/export/upstart/process.conf.erb +15 -0
  25. data/data/export/upstart/process_master.conf.erb +2 -0
  26. data/lib/foreman/cli.rb +162 -0
  27. data/lib/foreman/distribution.rb +9 -0
  28. data/lib/foreman/engine/cli.rb +105 -0
  29. data/lib/foreman/engine.rb +494 -0
  30. data/lib/foreman/env.rb +29 -0
  31. data/lib/foreman/export/base.rb +171 -0
  32. data/lib/foreman/export/bluepill.rb +12 -0
  33. data/lib/foreman/export/daemon.rb +28 -0
  34. data/lib/foreman/export/inittab.rb +42 -0
  35. data/lib/foreman/export/launchd.rb +22 -0
  36. data/lib/foreman/export/runit.rb +34 -0
  37. data/lib/foreman/export/supervisord.rb +16 -0
  38. data/lib/foreman/export/systemd.rb +34 -0
  39. data/lib/foreman/export/upstart.rb +46 -0
  40. data/lib/foreman/export.rb +36 -0
  41. data/lib/foreman/helpers.rb +45 -0
  42. data/lib/foreman/process.rb +81 -0
  43. data/lib/foreman/procfile.rb +94 -0
  44. data/lib/foreman/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  45. data/lib/foreman/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  46. data/lib/foreman/vendor/thor/lib/thor/actions/directory.rb +118 -0
  47. data/lib/foreman/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  48. data/lib/foreman/vendor/thor/lib/thor/actions/file_manipulation.rb +327 -0
  49. data/lib/foreman/vendor/thor/lib/thor/actions/inject_into_file.rb +103 -0
  50. data/lib/foreman/vendor/thor/lib/thor/actions.rb +318 -0
  51. data/lib/foreman/vendor/thor/lib/thor/base.rb +656 -0
  52. data/lib/foreman/vendor/thor/lib/thor/command.rb +133 -0
  53. data/lib/foreman/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +85 -0
  54. data/lib/foreman/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  55. data/lib/foreman/vendor/thor/lib/thor/core_ext/ordered_hash.rb +129 -0
  56. data/lib/foreman/vendor/thor/lib/thor/error.rb +32 -0
  57. data/lib/foreman/vendor/thor/lib/thor/group.rb +281 -0
  58. data/lib/foreman/vendor/thor/lib/thor/invocation.rb +177 -0
  59. data/lib/foreman/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  60. data/lib/foreman/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  61. data/lib/foreman/vendor/thor/lib/thor/line_editor.rb +17 -0
  62. data/lib/foreman/vendor/thor/lib/thor/parser/argument.rb +70 -0
  63. data/lib/foreman/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  64. data/lib/foreman/vendor/thor/lib/thor/parser/option.rb +146 -0
  65. data/lib/foreman/vendor/thor/lib/thor/parser/options.rb +220 -0
  66. data/lib/foreman/vendor/thor/lib/thor/parser.rb +4 -0
  67. data/lib/foreman/vendor/thor/lib/thor/rake_compat.rb +71 -0
  68. data/lib/foreman/vendor/thor/lib/thor/runner.rb +322 -0
  69. data/lib/foreman/vendor/thor/lib/thor/shell/basic.rb +436 -0
  70. data/lib/foreman/vendor/thor/lib/thor/shell/color.rb +149 -0
  71. data/lib/foreman/vendor/thor/lib/thor/shell/html.rb +126 -0
  72. data/lib/foreman/vendor/thor/lib/thor/shell.rb +81 -0
  73. data/lib/foreman/vendor/thor/lib/thor/util.rb +268 -0
  74. data/lib/foreman/vendor/thor/lib/thor/version.rb +3 -0
  75. data/lib/foreman/vendor/thor/lib/thor.rb +492 -0
  76. data/lib/foreman/version.rb +5 -0
  77. data/lib/foreman.rb +17 -0
  78. data/man/overman.1 +284 -0
  79. data/spec/foreman/cli_spec.rb +111 -0
  80. data/spec/foreman/engine_spec.rb +114 -0
  81. data/spec/foreman/export/base_spec.rb +19 -0
  82. data/spec/foreman/export/bluepill_spec.rb +37 -0
  83. data/spec/foreman/export/daemon_spec.rb +97 -0
  84. data/spec/foreman/export/inittab_spec.rb +40 -0
  85. data/spec/foreman/export/launchd_spec.rb +31 -0
  86. data/spec/foreman/export/runit_spec.rb +36 -0
  87. data/spec/foreman/export/supervisord_spec.rb +38 -0
  88. data/spec/foreman/export/systemd_spec.rb +155 -0
  89. data/spec/foreman/export/upstart_spec.rb +118 -0
  90. data/spec/foreman/export_spec.rb +24 -0
  91. data/spec/foreman/helpers_spec.rb +26 -0
  92. data/spec/foreman/process_spec.rb +71 -0
  93. data/spec/foreman/procfile_spec.rb +57 -0
  94. data/spec/foreman_spec.rb +16 -0
  95. data/spec/helper_spec.rb +19 -0
  96. data/spec/resources/Procfile +5 -0
  97. data/spec/resources/Procfile.bad +2 -0
  98. data/spec/resources/bin/echo +2 -0
  99. data/spec/resources/bin/env +2 -0
  100. data/spec/resources/bin/test +2 -0
  101. data/spec/resources/bin/utf8 +2 -0
  102. data/spec/resources/export/bluepill/app-concurrency.pill +49 -0
  103. data/spec/resources/export/bluepill/app.pill +81 -0
  104. data/spec/resources/export/daemon/app-alpha-1.conf +7 -0
  105. data/spec/resources/export/daemon/app-alpha-2.conf +7 -0
  106. data/spec/resources/export/daemon/app-alpha.conf +2 -0
  107. data/spec/resources/export/daemon/app-bravo-1.conf +7 -0
  108. data/spec/resources/export/daemon/app-bravo.conf +2 -0
  109. data/spec/resources/export/daemon/app.conf +14 -0
  110. data/spec/resources/export/inittab/inittab.concurrency +4 -0
  111. data/spec/resources/export/inittab/inittab.default +6 -0
  112. data/spec/resources/export/launchd/launchd-a.default +29 -0
  113. data/spec/resources/export/launchd/launchd-b.default +29 -0
  114. data/spec/resources/export/launchd/launchd-c.default +30 -0
  115. data/spec/resources/export/runit/app-alpha-1/log/run +7 -0
  116. data/spec/resources/export/runit/app-alpha-1/run +4 -0
  117. data/spec/resources/export/runit/app-alpha-2/log/run +7 -0
  118. data/spec/resources/export/runit/app-alpha-2/run +4 -0
  119. data/spec/resources/export/runit/app-bravo-1/log/run +7 -0
  120. data/spec/resources/export/runit/app-bravo-1/run +4 -0
  121. data/spec/resources/export/supervisord/app-alpha-1.conf +42 -0
  122. data/spec/resources/export/supervisord/app-alpha-2.conf +22 -0
  123. data/spec/resources/export/systemd/app-alpha.1.service +18 -0
  124. data/spec/resources/export/systemd/app-alpha.2.service +18 -0
  125. data/spec/resources/export/systemd/app-alpha.target +2 -0
  126. data/spec/resources/export/systemd/app-bravo.1.service +18 -0
  127. data/spec/resources/export/systemd/app-bravo.target +2 -0
  128. data/spec/resources/export/systemd/app.target +5 -0
  129. data/spec/resources/export/upstart/app-alpha-1.conf +11 -0
  130. data/spec/resources/export/upstart/app-alpha-2.conf +11 -0
  131. data/spec/resources/export/upstart/app-alpha.conf +2 -0
  132. data/spec/resources/export/upstart/app-bravo-1.conf +11 -0
  133. data/spec/resources/export/upstart/app-bravo.conf +2 -0
  134. data/spec/resources/export/upstart/app.conf +2 -0
  135. data/spec/spec_helper.rb +177 -0
  136. metadata +147 -16
  137. data/lib/overman/version.rb +0 -5
  138. data/lib/overman.rb +0 -1
data/man/overman.1 ADDED
@@ -0,0 +1,284 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "FOREMAN" "1" "April 2020" "Foreman 0.87.2" "Foreman Manual"
5
+ .
6
+ .SH "NAME"
7
+ \fBforeman\fR \- manage Procfile\-based applications
8
+ .
9
+ .SH "SYNOPSIS"
10
+ \fBforeman start [process]\fR
11
+ .
12
+ .br
13
+ \fBforeman run <command>\fR
14
+ .
15
+ .br
16
+ \fBforeman export <format> [location]\fR
17
+ .
18
+ .SH "DESCRIPTION"
19
+ Foreman is a manager for Procfile\-based applications\. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format\.
20
+ .
21
+ .SH "RUNNING"
22
+ \fBforeman start\fR is used to run your application directly from the command line\.
23
+ .
24
+ .P
25
+ If no additional parameters are passed, foreman will run one instance of each type of process defined in your Procfile\.
26
+ .
27
+ .P
28
+ If a parameter is passed, foreman will run one instance of the specified application type\.
29
+ .
30
+ .P
31
+ The following options control how the application is run:
32
+ .
33
+ .TP
34
+ \fB\-m\fR, \fB\-\-formation\fR
35
+ Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
36
+ .
37
+ .TP
38
+ \fB\-e\fR, \fB\-\-env\fR
39
+ Specify one or more \.env files to load
40
+ .
41
+ .TP
42
+ \fB\-f\fR, \fB\-\-procfile\fR
43
+ Specify an alternate Procfile to load, implies \fB\-d\fR at the Procfile root\.
44
+ .
45
+ .TP
46
+ \fB\-p\fR, \fB\-\-port\fR
47
+ Specify which port to use as the base for this application\. Should be a multiple of 1000\.
48
+ .
49
+ .TP
50
+ \fB\-t\fR, \fB\-\-timeout\fR
51
+ Specify the amount of time (in seconds) processes have to shutdown gracefully before receiving a SIGKILL, defaults to 5\.
52
+ .
53
+ .P
54
+ \fBforeman run\fR is used to run one\-off commands using the same environment as your defined processes\.
55
+ .
56
+ .SH "EXPORTING"
57
+ \fBforeman export\fR is used to export your application to another process management format\.
58
+ .
59
+ .P
60
+ A location to export can be passed as an argument\. This argument may be either required or optional depending on the export format\.
61
+ .
62
+ .P
63
+ The following options control how the application is run:
64
+ .
65
+ .TP
66
+ \fB\-a\fR, \fB\-\-app\fR
67
+ Use this name rather than the application\'s root directory name as the name of the application when exporting\.
68
+ .
69
+ .TP
70
+ \fB\-m\fR, \fB\-\-formation\fR
71
+ Specify the number of each process type to run\. The value passed in should be in the format \fBprocess=num,process=num\fR
72
+ .
73
+ .TP
74
+ \fB\-l\fR, \fB\-\-log\fR
75
+ Specify the directory to place process logs in\.
76
+ .
77
+ .TP
78
+ \fB\-p\fR, \fB\-\-port\fR
79
+ Specify which port to use as the base for this application\. Should be a multiple of 1000\.
80
+ .
81
+ .TP
82
+ \fB\-t\fR, \fB\-\-template\fR
83
+ Specify an alternate template to use for creating export files\. See \fIhttps://github\.com/ddollar/foreman/tree/master/data/export\fR for examples\.
84
+ .
85
+ .TP
86
+ \fB\-u\fR, \fB\-\-user\fR
87
+ Specify the user the application should be run as\. Defaults to the app name
88
+ .
89
+ .SH "GLOBAL OPTIONS"
90
+ These options control all modes of foreman\'s operation\.
91
+ .
92
+ .TP
93
+ \fB\-d\fR, \fB\-\-root\fR
94
+ Specify an alternate application root\. This defaults to the directory containing the Procfile\.
95
+ .
96
+ .TP
97
+ \fB\-e\fR, \fB\-\-env\fR
98
+ Specify an alternate environment file\. You can specify more than one file by using: \fB\-\-env file1,file2\fR\.
99
+ .
100
+ .TP
101
+ \fB\-f\fR, \fB\-\-procfile\fR
102
+ Specify an alternate location for the application\'s Procfile\. This file\'s containing directory will be assumed to be the root directory of the application\.
103
+ .
104
+ .SH "EXPORT FORMATS"
105
+ foreman currently supports the following output formats:
106
+ .
107
+ .IP "\(bu" 4
108
+ bluepill
109
+ .
110
+ .IP "\(bu" 4
111
+ inittab
112
+ .
113
+ .IP "\(bu" 4
114
+ launchd
115
+ .
116
+ .IP "\(bu" 4
117
+ runit
118
+ .
119
+ .IP "\(bu" 4
120
+ supervisord
121
+ .
122
+ .IP "\(bu" 4
123
+ systemd
124
+ .
125
+ .IP "\(bu" 4
126
+ upstart
127
+ .
128
+ .IP "" 0
129
+ .
130
+ .SH "INITTAB EXPORT"
131
+ Will export a chunk of inittab\-compatible configuration:
132
+ .
133
+ .IP "" 4
134
+ .
135
+ .nf
136
+
137
+ # \-\-\-\-\- foreman example processes \-\-\-\-\-
138
+ EX01:4:respawn:/bin/su \- example \-c \'PORT=5000 bundle exec thin start >> /var/log/web\-1\.log 2>&1\'
139
+ EX02:4:respawn:/bin/su \- example \-c \'PORT=5100 bundle exec rake jobs:work >> /var/log/job\-1\.log 2>&1\'
140
+ # \-\-\-\-\- end foreman example processes \-\-\-\-\-
141
+ .
142
+ .fi
143
+ .
144
+ .IP "" 0
145
+ .
146
+ .SH "SYSTEMD EXPORT"
147
+ Will create a series of systemd scripts in the location you specify\. Scripts will be structured to make the following commands valid:
148
+ .
149
+ .P
150
+ \fBsystemctl start appname\.target\fR
151
+ .
152
+ .P
153
+ \fBsystemctl stop appname\-processname\.target\fR
154
+ .
155
+ .P
156
+ \fBsystemctl restart appname\-processname\-3\.service\fR
157
+ .
158
+ .SH "UPSTART EXPORT"
159
+ Will create a series of upstart scripts in the location you specify\. Scripts will be structured to make the following commands valid:
160
+ .
161
+ .P
162
+ \fBstart appname\fR
163
+ .
164
+ .P
165
+ \fBstop appname\-processname\fR
166
+ .
167
+ .P
168
+ \fBrestart appname\-processname\-3\fR
169
+ .
170
+ .SH "PROCFILE"
171
+ A Procfile should contain both a name for the process and the command used to run it\.
172
+ .
173
+ .IP "" 4
174
+ .
175
+ .nf
176
+
177
+ web: bundle exec thin start
178
+ job: bundle exec rake jobs:work
179
+ .
180
+ .fi
181
+ .
182
+ .IP "" 0
183
+ .
184
+ .P
185
+ A process name may contain letters, numbers and the underscore character\. You can validate your Procfile format using the \fBcheck\fR command:
186
+ .
187
+ .IP "" 4
188
+ .
189
+ .nf
190
+
191
+ $ foreman check
192
+ .
193
+ .fi
194
+ .
195
+ .IP "" 0
196
+ .
197
+ .P
198
+ The special environment variables \fB$PORT\fR and \fB$PS\fR are available within the Procfile\. \fB$PORT\fR is the port selected for that process\. \fB$PS\fR is the name of the process for the line\.
199
+ .
200
+ .P
201
+ The \fB$PORT\fR value starts as the base port as specified by \fB\-p\fR, then increments by 100 for each new process line\. Multiple instances of the same process are assigned \fB$PORT\fR values that increment by 1\.
202
+ .
203
+ .SH "ENVIRONMENT"
204
+ If a \fB\.env\fR file exists in the current directory, the default environment will be read from it\. This file should contain key/value pairs, separated by \fB=\fR, with one key/value pair per line\.
205
+ .
206
+ .IP "" 4
207
+ .
208
+ .nf
209
+
210
+ FOO=bar
211
+ BAZ=qux
212
+ .
213
+ .fi
214
+ .
215
+ .IP "" 0
216
+ .
217
+ .SH "DEFAULT OPTIONS"
218
+ If a \fB\.foreman\fR file exists in the current directory, default options will be read from it\. This file should be in YAML format with the long option name as keys\. Example:
219
+ .
220
+ .IP "" 4
221
+ .
222
+ .nf
223
+
224
+ formation: alpha=0,bravo=1
225
+ port: 15000
226
+ .
227
+ .fi
228
+ .
229
+ .IP "" 0
230
+ .
231
+ .SH "EXAMPLES"
232
+ Start one instance of each process type, interleave the output on stdout:
233
+ .
234
+ .IP "" 4
235
+ .
236
+ .nf
237
+
238
+ $ foreman start
239
+ .
240
+ .fi
241
+ .
242
+ .IP "" 0
243
+ .
244
+ .P
245
+ Export the application in upstart format:
246
+ .
247
+ .IP "" 4
248
+ .
249
+ .nf
250
+
251
+ $ foreman export upstart /etc/init
252
+ .
253
+ .fi
254
+ .
255
+ .IP "" 0
256
+ .
257
+ .P
258
+ Run one process type from the application defined in a specific Procfile:
259
+ .
260
+ .IP "" 4
261
+ .
262
+ .nf
263
+
264
+ $ foreman start alpha \-f ~/myapp/Procfile
265
+ .
266
+ .fi
267
+ .
268
+ .IP "" 0
269
+ .
270
+ .P
271
+ Start all processes except the one named worker:
272
+ .
273
+ .IP "" 4
274
+ .
275
+ .nf
276
+
277
+ $ foreman start \-m all=1,worker=0
278
+ .
279
+ .fi
280
+ .
281
+ .IP "" 0
282
+ .
283
+ .SH "COPYRIGHT"
284
+ Foreman is Copyright (C) 2010 David Dollar \fIhttp://daviddollar\.org\fR
@@ -0,0 +1,111 @@
1
+ require "spec_helper"
2
+ require "foreman/cli"
3
+
4
+ describe "Foreman::CLI", :fakefs do
5
+ subject { Foreman::CLI.new }
6
+
7
+ describe ".foreman" do
8
+ before { File.open(".foreman", "w") { |f| f.puts "formation: alpha=2" } }
9
+
10
+ it "provides default options" do
11
+ expect(subject.send(:options)["formation"]).to eq("alpha=2")
12
+ end
13
+
14
+ it "is overridden by options at the cli" do
15
+ subject = Foreman::CLI.new([], :formation => "alpha=3")
16
+ expect(subject.send(:options)["formation"]).to eq("alpha=3")
17
+ end
18
+ end
19
+
20
+ describe "start" do
21
+ describe "when a Procfile doesnt exist", :fakefs do
22
+ it "displays an error" do
23
+ mock_error(subject, "Procfile does not exist.") do
24
+ expect_any_instance_of(Foreman::Engine).to_not receive(:start)
25
+ subject.start
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "with a valid Procfile" do
31
+ it "can run a single command" do
32
+ without_fakefs do
33
+ output = foreman("start env -f #{resource_path("Procfile")}")
34
+ expect(output).to match(/env.1/)
35
+ expect(output).not_to match(/test.1/)
36
+ end
37
+ end
38
+
39
+ it "can run all commands" do
40
+ without_fakefs do
41
+ output = foreman("start -f #{resource_path("Procfile")} -e #{resource_path(".env")}")
42
+ expect(output).to match(/echo.1 \| echoing/)
43
+ expect(output).to match(/env.1 \| bar/)
44
+ expect(output).to match(/test.1 \| testing/)
45
+ end
46
+ end
47
+
48
+ it "sets PS variable with the process name" do
49
+ without_fakefs do
50
+ output = foreman("start -f #{resource_path("Procfile")}")
51
+ expect(output).to match(/ps.1 \| PS env var is ps.1/)
52
+ end
53
+ end
54
+
55
+ it "fails if process fails" do
56
+ output = `bundle exec foreman start -f #{resource_path "Procfile.bad"} && echo success`
57
+ expect(output).not_to include 'success'
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "check" do
63
+ it "with a valid Procfile displays the jobs" do
64
+ write_procfile
65
+ expect(foreman("check")).to eq("valid procfile detected (alpha, bravo, foo_bar, foo-bar)\n")
66
+ end
67
+
68
+ it "with a blank Procfile displays an error" do
69
+ FileUtils.touch "Procfile"
70
+ expect(foreman("check")).to eq("ERROR: no processes defined\n")
71
+ end
72
+
73
+ it "without a Procfile displays an error" do
74
+ expect(foreman("check")).to eq("ERROR: Procfile does not exist.\n")
75
+ end
76
+ end
77
+
78
+ describe "run" do
79
+ it "can run a command" do
80
+ expect(forked_foreman("run echo 1")).to eq("1\n")
81
+ end
82
+
83
+ it "doesn't parse options for the command" do
84
+ expect(forked_foreman("run grep -e FOO #{resource_path(".env")}")).to eq("FOO=bar\n")
85
+ end
86
+
87
+ it "includes the environment" do
88
+ expect(forked_foreman("run -e #{resource_path(".env")} #{resource_path("bin/env FOO")}")).to eq("bar\n")
89
+ end
90
+
91
+ it "can run a command from the Procfile" do
92
+ expect(forked_foreman("run -f #{resource_path("Procfile")} test")).to eq("testing\n")
93
+ end
94
+
95
+ it "exits with the same exit code as the command" do
96
+ expect(fork_and_get_exitstatus("run echo 1")).to eq(0)
97
+ expect(fork_and_get_exitstatus("run date 'invalid_date'")).to eq(1)
98
+ end
99
+ end
100
+
101
+ describe "version" do
102
+ it "displays gem version" do
103
+ expect(foreman("version").chomp).to eq(Foreman::VERSION)
104
+ end
105
+
106
+ it "displays gem version on shortcut command" do
107
+ expect(foreman("-v").chomp).to eq(Foreman::VERSION)
108
+ end
109
+ end
110
+
111
+ end
@@ -0,0 +1,114 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+
4
+ class Foreman::Engine::Tester < Foreman::Engine
5
+ attr_reader :buffer
6
+
7
+ def startup
8
+ @buffer = ""
9
+ end
10
+
11
+ def output(name, data)
12
+ @buffer += "#{name}: #{data}"
13
+ end
14
+
15
+ def shutdown
16
+ end
17
+ end
18
+
19
+ describe "Foreman::Engine", :fakefs do
20
+ subject do
21
+ write_procfile "Procfile"
22
+ Foreman::Engine::Tester.new.load_procfile("Procfile")
23
+ end
24
+
25
+ describe "initialize" do
26
+ describe "with a Procfile" do
27
+ before { write_procfile }
28
+
29
+ it "reads the processes" do
30
+ expect(subject.process("alpha").command).to eq("./alpha")
31
+ expect(subject.process("bravo").command).to eq("./bravo")
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "start" do
37
+ it "forks the processes" do
38
+ expect(subject.process("alpha")).to receive(:run)
39
+ expect(subject.process("bravo")).to receive(:run)
40
+ expect(subject).to receive(:watch_for_output)
41
+ expect(subject).to receive(:wait_for_shutdown_or_child_termination)
42
+ subject.start
43
+ end
44
+
45
+ it "handles concurrency" do
46
+ subject.options[:formation] = "alpha=2"
47
+ expect(subject.process("alpha")).to receive(:run).twice
48
+ expect(subject.process("bravo")).to_not receive(:run)
49
+ expect(subject).to receive(:watch_for_output)
50
+ expect(subject).to receive(:wait_for_shutdown_or_child_termination)
51
+ subject.start
52
+ end
53
+ end
54
+
55
+ describe "directories" do
56
+ it "has the directory default relative to the Procfile" do
57
+ write_procfile "/some/app/Procfile"
58
+ engine = Foreman::Engine.new.load_procfile("/some/app/Procfile")
59
+ expect(engine.root).to eq("/some/app")
60
+ end
61
+ end
62
+
63
+ describe "environment" do
64
+ it "should read env files" do
65
+ write_file("/tmp/env") { |f| f.puts("FOO=baz") }
66
+ subject.load_env("/tmp/env")
67
+ expect(subject.env["FOO"]).to eq("baz")
68
+ end
69
+
70
+ it "should read more than one if specified" do
71
+ write_file("/tmp/env1") { |f| f.puts("FOO=bar") }
72
+ write_file("/tmp/env2") { |f| f.puts("BAZ=qux") }
73
+ subject.load_env "/tmp/env1"
74
+ subject.load_env "/tmp/env2"
75
+ expect(subject.env["FOO"]).to eq("bar")
76
+ expect(subject.env["BAZ"]).to eq("qux")
77
+ end
78
+
79
+ it "should handle quoted values" do
80
+ write_file("/tmp/env") do |f|
81
+ f.puts 'FOO=bar'
82
+ f.puts 'BAZ="qux"'
83
+ f.puts "FRED='barney'"
84
+ f.puts 'OTHER="escaped\"quote"'
85
+ f.puts 'URL="http://example.com/api?foo=bar&baz=1"'
86
+ end
87
+ subject.load_env "/tmp/env"
88
+ expect(subject.env["FOO"]).to eq("bar")
89
+ expect(subject.env["BAZ"]).to eq("qux")
90
+ expect(subject.env["FRED"]).to eq("barney")
91
+ expect(subject.env["OTHER"]).to eq('escaped"quote')
92
+ expect(subject.env["URL"]).to eq("http://example.com/api?foo=bar&baz=1")
93
+ end
94
+
95
+ it "should handle multiline strings" do
96
+ write_file("/tmp/env") do |f|
97
+ f.puts 'FOO="bar\nbaz"'
98
+ end
99
+ subject.load_env "/tmp/env"
100
+ expect(subject.env["FOO"]).to eq("bar\nbaz")
101
+ end
102
+
103
+ it "should fail if specified and doesnt exist" do
104
+ expect { subject.load_env "/tmp/env" }.to raise_error(Errno::ENOENT)
105
+ end
106
+
107
+ it "should set port from .env if specified" do
108
+ write_file("/tmp/env") { |f| f.puts("PORT=9000") }
109
+ subject.load_env "/tmp/env"
110
+ expect(subject.send(:base_port)).to eq(9000)
111
+ end
112
+ end
113
+
114
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+ require "foreman/export"
4
+
5
+ describe "Foreman::Export::Base", :fakefs do
6
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
7
+ let(:location) { "/tmp/init" }
8
+ let(:engine) { Foreman::Engine.new().load_procfile(procfile) }
9
+ let(:subject) { Foreman::Export::Base.new(location, engine) }
10
+
11
+ it "has a say method for displaying info" do
12
+ expect(subject).to receive(:puts).with("[foreman export] foo")
13
+ subject.send(:say, "foo")
14
+ end
15
+
16
+ it "raises errors as a Foreman::Export::Exception" do
17
+ expect { subject.send(:error, "foo") }.to raise_error(Foreman::Export::Exception, "foo")
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+ require "foreman/export/bluepill"
4
+ require "tmpdir"
5
+
6
+ describe Foreman::Export::Bluepill, :fakefs do
7
+ let(:procfile) { FileUtils.mkdir_p("/tmp/app"); write_procfile("/tmp/app/Procfile") }
8
+ let(:formation) { nil }
9
+ let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
10
+ let(:options) { Hash.new }
11
+ let(:bluepill) { Foreman::Export::Bluepill.new("/tmp/init", engine, options) }
12
+
13
+ before(:each) { load_export_templates_into_fakefs("bluepill") }
14
+ before(:each) { allow(bluepill).to receive(:say) }
15
+
16
+ it "exports to the filesystem" do
17
+ bluepill.export
18
+ expect(normalize_space(File.read("/tmp/init/app.pill"))).to eq(normalize_space(example_export_file("bluepill/app.pill")))
19
+ end
20
+
21
+ it "cleans up if exporting into an existing dir" do
22
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app.pill")
23
+
24
+ bluepill.export
25
+ bluepill.export
26
+ end
27
+
28
+ context "with a process formation" do
29
+ let(:formation) { "alpha=2" }
30
+
31
+ it "exports to the filesystem with concurrency" do
32
+ bluepill.export
33
+ expect(normalize_space(File.read("/tmp/init/app.pill"))).to eq(normalize_space(example_export_file("bluepill/app-concurrency.pill")))
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,97 @@
1
+ require "spec_helper"
2
+ require "foreman/engine"
3
+ require "foreman/export/daemon"
4
+ require "tmpdir"
5
+
6
+ describe Foreman::Export::Daemon, :fakefs do
7
+ let(:procfile) { write_procfile("/tmp/app/Procfile") }
8
+ let(:formation) { nil }
9
+ let(:engine) { Foreman::Engine.new(:formation => formation).load_procfile(procfile) }
10
+ let(:options) { Hash.new }
11
+ let(:daemon) { Foreman::Export::Daemon.new("/tmp/init", engine, options) }
12
+
13
+ before(:each) { load_export_templates_into_fakefs("daemon") }
14
+ before(:each) { allow(daemon).to receive(:say) }
15
+
16
+ it "exports to the filesystem" do
17
+ daemon.export
18
+
19
+ expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("daemon/app.conf"))
20
+ expect(File.read("/tmp/init/app-alpha.conf")).to eq(example_export_file("daemon/app-alpha.conf"))
21
+ expect(File.read("/tmp/init/app-alpha-1.conf")).to eq(example_export_file("daemon/app-alpha-1.conf"))
22
+ expect(File.read("/tmp/init/app-bravo.conf")).to eq(example_export_file("daemon/app-bravo.conf"))
23
+ expect(File.read("/tmp/init/app-bravo-1.conf")).to eq(example_export_file("daemon/app-bravo-1.conf"))
24
+ end
25
+
26
+ it "cleans up if exporting into an existing dir" do
27
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app.conf")
28
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha.conf")
29
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-alpha-1.conf")
30
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo.conf")
31
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-bravo-1.conf")
32
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar.conf")
33
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo-bar-1.conf")
34
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar.conf")
35
+ expect(FileUtils).to receive(:rm).with("/tmp/init/app-foo_bar-1.conf")
36
+
37
+ daemon.export
38
+ daemon.export
39
+ end
40
+
41
+ it "does not delete exported files for similarly named applications" do
42
+ FileUtils.mkdir_p "/tmp/init"
43
+
44
+ ["app2", "app2-alpha", "app2-alpha-1"].each do |name|
45
+ path = "/tmp/init/#{name}.conf"
46
+ FileUtils.touch(path)
47
+ expect(FileUtils).to_not receive(:rm).with(path)
48
+ end
49
+
50
+ daemon.export
51
+ end
52
+
53
+ context "with a formation" do
54
+ let(:formation) { "alpha=2" }
55
+
56
+ it "exports to the filesystem with concurrency" do
57
+ daemon.export
58
+
59
+ expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("daemon/app.conf"))
60
+ expect(File.read("/tmp/init/app-alpha.conf")).to eq(example_export_file("daemon/app-alpha.conf"))
61
+ expect(File.read("/tmp/init/app-alpha-1.conf")).to eq(example_export_file("daemon/app-alpha-1.conf"))
62
+ expect(File.read("/tmp/init/app-alpha-2.conf")).to eq(example_export_file("daemon/app-alpha-2.conf"))
63
+ expect(File.exists?("/tmp/init/app-bravo-1.conf")).to eq(false)
64
+ end
65
+ end
66
+
67
+ context "with alternate templates" do
68
+ let(:template) { "/tmp/alternate" }
69
+ let(:options) { { :app => "app", :template => template } }
70
+
71
+ before do
72
+ FileUtils.mkdir_p template
73
+ File.open("#{template}/master.conf.erb", "w") { |f| f.puts "alternate_template" }
74
+ end
75
+
76
+ it "can export with alternate template files" do
77
+ daemon.export
78
+ expect(File.read("/tmp/init/app.conf")).to eq("alternate_template\n")
79
+ end
80
+ end
81
+
82
+ context "with alternate templates from home dir" do
83
+
84
+ before do
85
+ FileUtils.mkdir_p File.expand_path("~/.foreman/templates/daemon")
86
+ File.open(File.expand_path("~/.foreman/templates/daemon/master.conf.erb"), "w") do |file|
87
+ file.puts "default_alternate_template"
88
+ end
89
+ end
90
+
91
+ it "can export with alternate template files" do
92
+ daemon.export
93
+ expect(File.read("/tmp/init/app.conf")).to eq("default_alternate_template\n")
94
+ end
95
+ end
96
+
97
+ end