1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* this file is part of pipelines */ |
4
|
|
|
|
5
|
|
|
namespace Ktomk\Pipelines\Utility; |
6
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Ktomk\Pipelines\Cli\Args; |
9
|
|
|
use Ktomk\Pipelines\Cli\Streams; |
10
|
|
|
|
11
|
|
|
class Help |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Streams |
15
|
|
|
*/ |
16
|
|
|
private $streams; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Help constructor. |
20
|
|
|
* |
21
|
|
|
* @param Streams $streams |
22
|
|
|
*/ |
23
|
1 |
|
public function __construct(Streams $streams) |
24
|
|
|
{ |
25
|
1 |
|
$this->streams = $streams; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return int |
30
|
|
|
*/ |
31
|
2 |
|
public function showVersion() |
32
|
|
|
{ |
33
|
2 |
|
$version = Version::resolve(App::VERSION); |
34
|
2 |
|
$this->streams->out( |
35
|
2 |
|
sprintf("pipelines version %s\n", $version) |
36
|
|
|
); |
37
|
|
|
|
38
|
2 |
|
return 0; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
3 |
|
public function showUsage() |
45
|
|
|
{ |
46
|
3 |
|
$this->streams->out( |
47
|
|
|
<<<'EOD' |
48
|
|
|
usage: pipelines [<options>] --version | -h | --help |
49
|
|
|
pipelines [<options>] [--working-dir <path>] [--file <path>] |
50
|
|
|
[--basename <basename>] [--prefix <prefix>] |
51
|
|
|
[--verbatim] [--[no-|error-]keep] [--no-run] |
52
|
|
|
[(-e | --env) <variable>] [--env-file <path>] |
53
|
|
|
[--no-dot-env-files] [--no-dot-env-dot-dist] |
54
|
|
|
[--docker-client <package>] [--ssh] |
55
|
|
|
[--user[=<name|uid>[:<group|gid>]]] |
56
|
|
|
[--deploy mount | copy ] [--pipeline <id>] |
57
|
|
|
[(--step | --steps) <steps>] [--no-manual] |
58
|
|
|
[--trigger <ref>] [--no-cache] |
59
|
|
|
pipelines [<options>] --service <service> |
60
|
|
|
pipelines [<options>] --list | --show | --images |
61
|
|
|
| --show-pipelines | --show-services |
62
|
|
|
| --step-script[=(<id> | <step>[:<id>])] |
63
|
|
|
| --validate[=<path>] |
64
|
|
|
pipelines [<options>] --docker-client-pkgs |
65
|
|
|
pipelines [<options>] [--docker-list] [--docker-kill] |
66
|
|
|
[--docker-clean] [--docker-zap] |
67
|
|
|
|
68
|
|
|
EOD |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
2 |
|
public function showHelp() |
76
|
|
|
{ |
77
|
2 |
|
$this->showUsage(); |
78
|
2 |
|
$this->streams->out( |
79
|
|
|
<<<'EOD' |
80
|
|
|
|
81
|
|
|
Generic options |
82
|
|
|
-h, --help show usage and help information |
83
|
|
|
--version show version information |
84
|
|
|
-v, --verbose be more verbose, show more information and |
85
|
|
|
commands to be executed |
86
|
|
|
--dry-run do not execute commands, e.g. invoke docker or |
87
|
|
|
run containers, with --verbose show the |
88
|
|
|
commands that would have run w/o --dry-run |
89
|
|
|
-c <name>=<value> pass a configuration parameter to the command |
90
|
|
|
|
91
|
|
|
Pipeline runner options |
92
|
|
|
--basename <basename> set basename for pipelines file, defaults to |
93
|
|
|
'bitbucket-pipelines.yml' |
94
|
|
|
--deploy mount|copy how files from the working directory are |
95
|
|
|
placed into the pipeline container: |
96
|
|
|
copy (default) working dir is copied into |
97
|
|
|
the container. stronger isolation as |
98
|
|
|
the pipeline scripts can change all |
99
|
|
|
files without side-effects in the |
100
|
|
|
working directory |
101
|
|
|
mount the working directory is mounted. |
102
|
|
|
fastest, no isolation |
103
|
|
|
--file <path> path to the pipelines file, overrides looking |
104
|
|
|
up the <basename> file from the current |
105
|
|
|
working directory, use '-' to read from stdin |
106
|
|
|
--trigger <ref> build trigger; <ref> can be either of: |
107
|
|
|
tag:<name>, branch:<name>, bookmark:<name> or |
108
|
|
|
pr:<branch-name>[:<destination-branch>] |
109
|
|
|
determines the pipeline to run |
110
|
|
|
--pipeline <id> run pipeline with <id>, use --list for a list |
111
|
|
|
of all pipeline ids available. overrides |
112
|
|
|
--trigger for the pipeline while keeping |
113
|
|
|
environment from --trigger. |
114
|
|
|
--step, --steps <steps> |
115
|
|
|
execute not all but this/these <steps>. all |
116
|
|
|
duplicates and orderings allowed, <steps> are |
117
|
|
|
a comma/space separated list of step and step |
118
|
|
|
ranges, e.g. 1 2 3; 1-3; 1,2-3; 3-1 or -1,3- |
119
|
|
|
and 1,1,3,3,2,2 |
120
|
|
|
--no-manual ignore manual steps, by default manual steps |
121
|
|
|
stop the pipeline execution when not the first |
122
|
|
|
step in invocation of a pipeline |
123
|
|
|
--verbatim only give verbatim output of the pipeline, do |
124
|
|
|
not display other information like which step |
125
|
|
|
currently executes, which image is in use ... |
126
|
|
|
--working-dir <path> run as if pipelines was started in <path> |
127
|
|
|
--no-run do not run the pipeline |
128
|
|
|
--prefix <prefix> use a different prefix for container names, |
129
|
|
|
default is 'pipelines' |
130
|
|
|
--no-cache disable step caches; docker always caches |
131
|
|
|
|
132
|
|
|
File information options |
133
|
|
|
--images list all images in file, in order of use, w/o |
134
|
|
|
duplicate names and exit |
135
|
|
|
--list list pipeline <id>s in file and exit |
136
|
|
|
--show show information about pipelines in file and |
137
|
|
|
exit |
138
|
|
|
--show-pipelines same as --show but with old --show output |
139
|
|
|
format without services and images / steps are |
140
|
|
|
summarized - one line for each pipeline |
141
|
|
|
--show-services show all defined services in use by pipeline |
142
|
|
|
steps and exit |
143
|
|
|
--validate[=<path>] schema-validate file, shows errors if any, |
144
|
|
|
exits; can be used more than once, exit status |
145
|
|
|
is non-zero on error |
146
|
|
|
--step-script[=(<id> | <step>[:<id>])] |
147
|
|
|
write the step-script of pipeline <id> and |
148
|
|
|
<step> to standard output and exit |
149
|
|
|
|
150
|
|
|
Environment control options |
151
|
|
|
-e, --env <variable> pass or set an environment <variable> for the |
152
|
|
|
docker container, just like a docker run, |
153
|
|
|
<variable> can be the name of a variable which |
154
|
|
|
adds the variable to the container as export |
155
|
|
|
or a variable definition with the name of the |
156
|
|
|
variable, the equal sign "=" and the value, |
157
|
|
|
e.g. --env NAME=<value> |
158
|
|
|
--env-file <path> pass variables from environment file to the |
159
|
|
|
docker container |
160
|
|
|
--no-dot-env-files do not pass .env.dist and .env files as |
161
|
|
|
environment files to docker |
162
|
|
|
--no-dot-env-dot-dist dot not pass .env.dist as environment file to |
163
|
|
|
docker only |
164
|
|
|
|
165
|
|
|
Keep options |
166
|
|
|
--keep always keep docker containers |
167
|
|
|
--error-keep keep docker containers if a step failed; |
168
|
|
|
outputs non-zero exit status and the id of the |
169
|
|
|
container kept and exit w/ container exec exit |
170
|
|
|
status |
171
|
|
|
--no-keep do not keep docker containers; default |
172
|
|
|
|
173
|
|
|
Container runner options |
174
|
|
|
--ssh ssh agent forwarding: if $SSH_AUTH_SOCK is set |
175
|
|
|
and accessible, mount SSH authentication |
176
|
|
|
socket read only and set SSH_AUTH_SOCK in the |
177
|
|
|
pipeline step container to the mount point. |
178
|
|
|
--user[=<name|uid>[:<group|gid>]] |
179
|
|
|
run pipeline step container as current or |
180
|
|
|
given <user>/<group>; overrides container |
181
|
|
|
default <user> - often root, (better) run |
182
|
|
|
rootless by default. |
183
|
|
|
|
184
|
|
|
Service runner options |
185
|
|
|
--service <service> runs <service> attached to the current shell |
186
|
|
|
and waits until the service exits, exit status |
187
|
|
|
is the one of the docker run service |
188
|
|
|
container; for testing services, run in a |
189
|
|
|
shell of its own or background |
190
|
|
|
|
191
|
|
|
Docker service options |
192
|
|
|
--docker-client <package> |
193
|
|
|
which docker client binary to use for the |
194
|
|
|
pipeline service 'docker' defaults to the |
195
|
|
|
'docker-19.03.1-linux-static-x86_64' package |
196
|
|
|
--docker-client-pkgs list all docker client packages that ship with |
197
|
|
|
pipelines and exit |
198
|
|
|
|
199
|
|
|
Docker container maintenance options |
200
|
|
|
usage might leave containers on the system. either by interrupting |
201
|
|
|
a running pipeline step or by keeping the running containers |
202
|
|
|
(--keep, --error-keep) |
203
|
|
|
|
204
|
|
|
pipelines uses a <prefix> 'pipelines' by default, followed by '-' |
205
|
|
|
and a compound name based on step-number, step-name, pipeline id |
206
|
|
|
and image name for container names. the prefix can be set by the |
207
|
|
|
--prefix <prefix> option and argument. |
208
|
|
|
|
209
|
|
|
three options are built-in to monitor and interact with leftovers, |
210
|
|
|
if one or more of these are given, the following operations are |
211
|
|
|
executed in the order from top to down: |
212
|
|
|
--docker-list list prefixed containers |
213
|
|
|
--docker-kill kills prefixed containers |
214
|
|
|
--docker-clean remove (non-running) containers with |
215
|
|
|
pipelines prefix |
216
|
|
|
|
217
|
|
|
for ease of use: |
218
|
|
|
--docker-zap kill and remove all prefixed containers at |
219
|
|
|
once; no show/listing |
220
|
|
|
|
221
|
|
|
Less common options |
222
|
|
|
--debug flag for trouble-shooting (fatal) errors, |
223
|
|
|
warnings, notices and strict warnings; useful |
224
|
|
|
for trouble-shooting and bug-reports |
225
|
|
|
|
226
|
|
|
EOD |
227
|
|
|
); |
228
|
|
|
|
229
|
2 |
|
return 0; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param Args $args |
234
|
|
|
* |
235
|
|
|
* @throws InvalidArgumentException |
236
|
|
|
* @throws StatusException |
237
|
|
|
* |
238
|
|
|
* @return void |
239
|
|
|
*/ |
240
|
3 |
|
public function run(Args $args) |
241
|
|
|
{ |
242
|
|
|
# quickly handle version |
243
|
3 |
|
if ($args->hasOption('version')) { |
244
|
1 |
|
throw new StatusException('', $this->showVersion()); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
# quickly handle help |
248
|
2 |
|
if ($args->hasOption(array('h', 'help'))) { |
249
|
1 |
|
throw new StatusException('', $this->showHelp()); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|