forked from reanahub/reana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
1057 lines (898 loc) · 39.8 KB
/
cli.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2018 CERN.
#
# REANA is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# REANA is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# REANA; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307, USA.
#
# In applying this license, CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization or
# submit itself to any jurisdiction.
"""Helper scripts for REANA developers. Run `reana --help` for help."""
import os
import subprocess
import sys
import click
SRCDIR = os.environ.get('REANA_SRCDIR')
GITHUB_USER = os.environ.get('REANA_GITHUB_USER')
REPO_LIST_ALL = [
'reana',
'reana-client',
'reana-cluster',
'reana-commons',
'reana-db',
'reana-demo-alice-lego-train-test-run',
'reana-demo-atlas-recast',
'reana-demo-bsm-search',
'reana-demo-cms-h4l',
'reana-demo-helloworld',
'reana-demo-lhcb-d2pimumu',
'reana-demo-root6-roofit',
'reana-demo-worldpopulation',
'reana-env-aliphysics',
'reana-env-jupyter',
'reana-env-root6',
'reana-job-controller',
'reana-message-broker',
'reana-server',
'reana-ui',
'reana-workflow-controller',
'reana-workflow-engine-cwl',
'reana-workflow-engine-serial',
'reana-workflow-engine-yadage',
'reana-workflow-monitor',
'reana.io',
]
REPO_LIST_CLIENT = [
'reana-commons',
'reana-client',
]
REPO_LIST_CLUSTER = [
'reana-commons',
'reana-db',
'reana-job-controller',
'reana-message-broker',
'reana-server',
'reana-workflow-controller',
'reana-workflow-engine-cwl',
'reana-workflow-engine-serial',
'reana-workflow-engine-yadage',
'reana-workflow-monitor',
]
REPO_LIST_CLUSTER_CLI = [
'reana-commons',
'reana-cluster',
]
WORKFLOW_ENGINE_LIST_ALL = [
'cwl',
'serial',
'yadage'
]
@click.group()
def cli(): # noqa: D301
"""Run REANA development and integration commands.
How to configure your environment:
.. code-block:: console
\b
$ export REANA_SRCDIR=~/project/reana/src
$ export REANA_GITHUB_USER=tiborsimko
How to prepare your environment:
.. code-block:: console
\b
$ # prepare directoru that will hold sources
$ mkdir $REANA_SRCDIR && cd $REANA_SRCDIR
$ # install reana developer helper script
$ mkvirtualenv reana
$ pip install git+git://github.com/reanahub/reana.git#egg=reana
$ # run ssh-agent locally to simplify GitHub interaction
$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_rsa
How to fork and clone all REANA repositories:
.. code-block:: console
\b
$ reana git-fork -c ALL
$ eval "$(reana git-fork -c ALL)"
$ reana git-clone -c ALL
How to install latest ``master`` REANA cluster and client CLI scripts:
.. code-block:: console
\b
$ workon reana
$ reana install-client
$ reana install-cluster
How to compile and deploy latest ``master`` REANA cluster:
.. code-block:: console
\b
$ minikube start --kubernetes-version="v1.9.4" --vm-driver=kvm2
$ eval $(minikube docker-env)
$ reana docker-build
$ reana docker-images
$ pip install reana-cluster
$ reana-cluster -f reana-cluster-latest.yaml init
How to set up your shell environment variables:
.. code-block:: console
\b
$ eval $(reana setup-environment)
How to run full REANA example using a given workflow engine:
.. code-block:: console
\b
$ reana run-example -c reana-demo-root6-roofit -w serial -s 10
How to test one component pull request:
.. code-block:: console
\b
$ cd reana-job-controller
$ reana git-checkout -b . 72 --fetch
$ reana docker-build -c .
$ kubectl delete pod -l app=job-controller
How to test multiple component branches:
.. code-block:: console
\b
$ reana git-checkout -b reana-job-controller 72
$ reana git-checkout -b reana-workflow-controller 98
$ reana git-status
$ reana docker-build
$ kubectl delete pod -l app=job-controller
$ kubectl delete pod -l app=workflow-controller
How to release and push cluster component images:
.. code-block:: console
\b
$ reana git-clean
$ reana docker-build --no-cache
$ # we should now run one more test with non-cached ``latest``
$ # once it works, we can tag and push
$ reana docker-build -t 0.3.0.dev20180625
$ reana docker-push -t 0.3.0.dev20180625
$ # we should now make PR for ``reana-cluster.yaml`` to use given tag
"""
pass
def shorten_component_name(component):
"""Return canonical short version of the component name.
Example: reana-job-controller -> r-j-controller
:param component: standard component name
:type component: str
:return: short component name
:rtype: str
"""
short_name = ''
parts = component.split('-')
for part in parts[:-1]:
short_name += part[0] + '-'
short_name += parts[-1]
return short_name
def find_standard_component_name(short_component_name):
"""Return standard component name corresponding to the short name.
Example: r-j-controller -> reana-job-controller
:param short_component_name: short component name
:type component: str
:return: standard component name
:rtype: str
:raise: exception in case more than one is found
"""
output = []
for component in REPO_LIST_ALL:
component_short_name = shorten_component_name(component)
if component_short_name == short_component_name:
output.append(component)
if len(output) == 1:
return output[0]
raise Exception('Component name {0} cannot be uniquely mapped.'.format(
'short_component_name'))
def get_srcdir(component=''):
"""Return source code directory of the given REANA component.
:param component: standard component name
:type component: str
:return: source code directory for given component
:rtype: str
"""
if not SRCDIR:
click.echo('Please set environment variable REANA_SRCDIR'
' to the directory that will contain'
' REANA source code repositories.')
click.echo('Example:'
' $ export REANA_SRCDIR=~/private/project/reana/src')
sys.exit(1)
if component:
return SRCDIR + os.sep + component
else:
return SRCDIR
def get_current_branch(srcdir):
"""Return current Git branch name checked out in the given directory.
:param srcdir: source code directory
:type srcdir: str
:return: checkout out branch in the component source code directory
:rtype: str
"""
os.chdir(srcdir)
return subprocess.getoutput('git branch 2>/dev/null | '
'grep "^*" | colrm 1 2')
def get_current_commit(srcdir):
"""Return information about git commit checked out in the given directory.
:param srcdir: source code directory
:type srcdir: str
:return: commit information composed of brief SHA1 and subject
:rtype: str
"""
os.chdir(srcdir)
return subprocess.getoutput('git log --pretty=format:"%h %s" -n 1')
def select_components(components):
"""Return expanded and unified component name list based on input values.
:param components: A list of component name that may consist of:
* (1) standard component names such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components;
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type components: list
:return: Unique standard component names.
:rtype: list
"""
short_component_names = [shorten_component_name(name)
for name in REPO_LIST_ALL]
output = set([])
for component in components:
if component == 'ALL':
for repo in REPO_LIST_ALL:
output.add(repo)
elif component == 'CLIENT':
for repo in REPO_LIST_CLIENT:
output.add(repo)
elif component == 'CLUSTER':
for repo in REPO_LIST_CLUSTER:
output.add(repo)
elif component == '.':
cwd = os.path.basename(os.getcwd())
output.add(cwd)
elif component in REPO_LIST_ALL:
output.add(component)
elif component in short_component_names:
component_standard_name = find_standard_component_name(component)
output.add(component_standard_name)
else:
display_message('Ignoring unknown component {0}.'.format(
component))
return list(output)
def select_workflow_engines(workflow_engines):
"""Return known workflow engine names that REANA supports.
:param workflow_engines: A list of workflow engine names such as 'cwl'.
:type components: list
:return: Unique workflow engine names.
:rtype: list
"""
output = set([])
for workflow_engine in workflow_engines:
if workflow_engine in WORKFLOW_ENGINE_LIST_ALL:
output.add(workflow_engine)
else:
display_message('Ignoring unknown workflow engine {0}.'.format(
workflow_engine))
return list(output)
def is_component_dockerised(component):
"""Return whether the component contains Dockerfile.
Useful to skip some docker-related commands for those components that are
not concerned, such as building Docker images for `reana-cluster` that does
not provide any.
:param component: standard component name
:type component: str
:return: True/False whether the component is dockerisable
:rtype: bool
"""
if os.path.exists(get_srcdir(component) + os.sep + 'Dockerfile'):
return True
return False
def is_component_runnable_example(component):
"""Return whether the component contains reana.yaml.
Useful for safety check when using some run-example commands for those
components that are not REANA examples.
:param component: standard component name
:type component: str
:return: True/False whether the component is a REANA example
:rtype: bool
"""
if os.path.exists(get_srcdir(component) + os.sep + 'reana.yaml'):
return True
return False
def construct_workflow_name(example, workflow_engine):
"""Construct suitable workflow name for given REANA example.
:param example: REANA example (e.g. reana-demo-root6-roofit)
:param workflow_engine: workflow engine to use (cwl, serial, yadage)
:type example: str
:type workflow_engine: str
"""
output = '{0}.{1}'.format(example.replace('reana-demo-', ''),
workflow_engine)
return output
def run_command(cmd, component=''):
"""Run given command in the given component source directory.
Exit in case of troubles.
:param cmd: shell command to run
:param component: standard component name
:type cmd: str
:type component: str
"""
click.secho('[{0}] {1}'.format(component, cmd), bold=True)
if component:
os.chdir(get_srcdir(component))
try:
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError as err:
click.secho('[{0}] {1}'.format(component, err), bold=True)
sys.exit(err.returncode)
def display_message(msg, component=''):
"""Display message in a similar style as run_command().
:param msg: message to display
:param component: standard component name
:type msg: str
:type component: str
"""
click.secho('[{0}] {1}'.format(component, msg), bold=True)
@cli.command()
def version():
"""Return REANA version."""
from reana.version import __version__
click.echo(__version__)
@cli.command()
def help():
"""Display usage help tips and tricks."""
click.echo(cli.__doc__)
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@click.option('--browser', '-b', default='firefox',
help='Which browser to use? [firefox]')
@cli.command(name='git-fork')
def git_fork(component, browser): # noqa: D301
"""Display commands to fork REANA source code repositories on GitHub.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param browser: The web browser to use. [default=firefox]
:type component: str
:type browser: str
"""
components = select_components(component)
if components:
click.echo('# Fork REANA repositories on GitHub using your browser.')
click.echo('# Run the following eval and then complete the fork'
' process in your browser.')
click.echo('#')
click.echo('# eval "$(reana git-fork -b {0} {1})"'.format(
browser,
"".join([" -c {0}".format(c) for c in component])))
for component in components:
cmd = '{0} https://github.com/reanahub/{1}/fork;'.format(browser,
component)
click.echo(cmd)
click.echo('echo "Please continue the fork process in the opened'
' browser windows."')
@click.option('--user', '-u', default=GITHUB_USER,
help='GitHub user name [{0}]'.format(GITHUB_USER))
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@cli.command(name='git-clone')
def git_clone(user, component): # noqa: D301
"""Clone REANA source repositories from GitHub.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: The GitHub user name. [default=$REANA_GITHUB_USER]
:type component: str
:type user: str
"""
if not GITHUB_USER:
click.echo('Please set environment variable REANA_GITHUB_USER to your'
' GitHub user name.')
click.echo('Example: $ export REANA_GITHUB_USER=tiborsimko')
sys.exit(1)
components = select_components(component)
for component in components:
os.chdir(get_srcdir())
cmd = 'git clone git@github.com:{0}/{1}'.format(user, component)
run_command(cmd)
for cmd in [
'git remote add upstream'
' "git@github.com:reanahub/{0}"'.format(component),
'git config --add remote.upstream.fetch'
' "+refs/pull/*/head:refs/remotes/upstream/pr/*"',
]:
run_command(cmd, component)
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@cli.command(name='git-status')
def git_status(component): # noqa: D301
"""Report status of REANA source repositories.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
components = select_components(component)
for component in components:
branch = get_current_branch(get_srcdir(component))
commit = get_current_commit(get_srcdir(component))
click.secho('- {0}'.format(component), nl=False, bold=True)
if branch == 'master':
click.secho(' @ {0} {1}'.format(branch, commit))
else:
click.secho(' @ {0} {1}'.format(branch, commit), fg='red')
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@cli.command(name='git-clean')
def git_clean(component): # noqa: D301
"""Clean REANA source repository code tree.
Removes pyc, eggs, _build and other leftover friends.
Less aggressive then "git clean -x".
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
components = select_components(component)
for component in components:
for cmd in [
'find . -name "*.pyc" -delete',
'find . -type d -name "*.egg-info" -exec rm -rf {} \\;',
'find . -type d -name ".eggs" -exec rm -rf {} \\;',
'find . -type d -name __pycache__ -delete',
'find docs -type d -name "_build" -exec rm -rf {} \\;'
]:
run_command(cmd, component)
@click.option('--branch', '-b', nargs=2, multiple=True,
help='Which PR? [number component]')
@click.option('--fetch', is_flag=True, default=False)
@cli.command(name='git-checkout')
def git_checkout(branch, fetch): # noqa: D301
"""Check out local branch corresponding to a component pull request.
The ``-b`` option can be repetitive to check out several pull requests in
several repositories at the same time.
\b
:param branch: The option ``branch`` can be repeated. The value consist of
two strings specifying the component name and the pull
request number. For example, ``-b reana-job-controler 72``
will create a local branch called ``pr-72`` in the
reana-job-component source code directory.
:param fetch: Should we fetch latest upstream first? [default=False]
:type component: str
:type fetch: bool
"""
for cpr in branch:
component, pull_request = cpr
component = select_components([component, ])[0]
if component in REPO_LIST_ALL:
if fetch:
cmd = 'git fetch upstream'
run_command(cmd, component)
cmd = 'git checkout -b pr-{0} upstream/pr/{0}'.format(pull_request)
run_command(cmd, component)
else:
msg = 'Ignoring unknown component.'
display_message(msg, component)
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@cli.command(name='git-fetch')
def git_fetch(component): # noqa: D301
"""Fetch REANA upstream source code repositories without upgrade.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
for component in select_components(component):
cmd = 'git fetch upstream'
run_command(cmd, component)
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@cli.command(name='git-upgrade')
def git_upgrade(component): # noqa: D301
"""Upgrade REANA local source code repositories.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
for component in select_components(component):
for cmd in ['git fetch upstream',
'git checkout master',
'git merge --ff-only upstream/master',
'git push origin master',
'git checkout -']:
run_command(cmd, component)
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [shortname|name|.|CLUSTER|ALL]')
@cli.command(name='git-diff')
def git_diff(component): # noqa: D301
"""Diff checked-out REANA local source code repositories.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
for component in select_components(component):
for cmd in ['git diff master', ]:
run_command(cmd, component)
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [name|CLUSTER]')
@cli.command(name='git-push')
def git_push(full, component): # noqa: D301
"""Push REANA local repositories to GitHub origin.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:type component: str
"""
components = select_components(component)
for component in components:
for cmd in ['git push origin master']:
run_command(cmd, component)
@click.option('--user', '-u', default='reanahub',
help='DockerHub user name [reanahub]')
@click.option('--tag', '-t', default='latest',
help='Image tag [latest]')
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [name|CLUSTER]')
@click.option('--no-cache', is_flag=True)
@cli.command(name='docker-build')
def docker_build(user, tag, component, no_cache): # noqa: D301
"""Build REANA component images.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
:param no_cache: Flag instructing to avoid using cache. [default=False]
:type component: str
:type user: str
:type tag: str
:type no_cache: bool
"""
components = select_components(component)
for component in components:
if is_component_dockerised(component):
if no_cache:
cmd = 'docker build --no-cache -t {0}/{1}:{2} .'.format(
user, component, tag)
else:
cmd = 'docker build -t {0}/{1}:{2} .'.format(
user, component, tag)
run_command(cmd, component)
else:
msg = 'Ignoring this component that does not contain' \
' a Dockerfile.'
display_message(msg, component)
@click.option('--user', '-u', default='reanahub',
help='DockerHub user name [reanahub]')
@cli.command(name='docker-images')
def docker_images(user): # noqa: D301
"""List REANA component images.
:param user: DockerHub user name. [default=reanahub]
:type user: str
"""
cmd = 'docker images | grep {0}'.format(user)
run_command(cmd)
@click.option('--user', '-u', default='reanahub',
help='DockerHub user name [reanahub]')
@click.option('--tag', '-t', default='latest',
help='Image tag [latest]')
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [name|CLUSTER]')
@cli.command(name='docker-rmi')
def docker_rmi(user, tag, component): # noqa: D301
"""Remove REANA component images.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
:type component: str
:type user: str
:type tag: str
"""
components = select_components(component)
for component in components:
if is_component_dockerised(component):
cmd = 'docker rmi {0}/{1}:{2}'.format(user, component, tag)
run_command(cmd, component)
else:
msg = 'Ignoring this component that does not contain' \
' a Dockerfile.'
display_message(msg, component)
@click.option('--user', '-u', default='reanahub',
help='DockerHub user name [reanahub]')
@click.option('--tag', '-t', default='latest',
help='Image tag [latest]')
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [name|CLUSTER]')
@cli.command(name='docker-push')
def docker_push(user, tag, component): # noqa: D301
"""Push REANA component images to DockerHub.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
:type component: str
:type user: str
:type tag: str
"""
components = select_components(component)
for component in components:
if is_component_dockerised(component):
cmd = 'docker push {0}/{1}:{2}'.format(user, component, tag)
run_command(cmd, component)
else:
msg = 'Ignoring this component that does not contain' \
' a Dockerfile.'
display_message(msg, component)
@click.option('--user', '-u', default='reanahub',
help='DockerHub user name [reanahub]')
@click.option('--tag', '-t', default='latest',
help='Image tag [latest]')
@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
help='Which components? [name|CLUSTER]')
@cli.command(name='docker-pull')
def docker_pull(user, tag, component): # noqa: D301
"""Pull REANA component images from DockerHub.
\b
:param components: The option ``component`` can be repeated. The value may
consist of:
* (1) standard component name such as
'reana-job-controller';
* (2) short component name such as 'r-j-controller';
* (3) special value '.' indicating component of the
current working directory;
* (4) special value 'CLUSTER' that will expand to
cover all REANA cluster components [default];
* (5) special value 'CLIENT' that will expand to
cover all REANA client components;
* (6) special value 'ALL' that will expand to include
all REANA repositories.
:param user: DockerHub organisation or user name. [default=reanahub]
:param tag: Docker tag to use. [default=latest]
:type component: str
:type user: str
:type tag: str
"""
components = select_components(component)
for component in components:
if is_component_dockerised(component):
cmd = 'docker pull {0}/{1}:{2}'.format(user, component, tag)
run_command(cmd, component)
else:
msg = 'Ignoring this component that does not contain' \
' a Dockerfile.'
display_message(msg, component)
@cli.command(name='install-client')
def install_client(): # noqa: D301
"""Install latest REANA client Python package and its dependencies.
\b
:param upgrade: Should we upgrade? [default=True]
:type fetch: bool
"""
for component in REPO_LIST_CLIENT:
for cmd in [
'pip install . --upgrade',
]:
run_command(cmd, component)
@cli.command(name='install-cluster')
def install_cluster(): # noqa: D301
"""Install latest REANA cluster Python package and its dependencies.
\b
:param upgrade: Should we upgrade if already installed? [default=True]
:type fetch: bool
"""
for component in REPO_LIST_CLUSTER_CLI:
for cmd in [
'pip install . --upgrade',
]:
run_command(cmd, component)
@cli.command(name='setup-environment')
def setup_environment(): # noqa: D301
"""Display commands to set up shell environment for local cluster.
Display commands how to set up REANA_SERVER_URL and REANA_ACCESS_TOKEN
suitable for current local REANA cluster deployment. The output should be
passed to eval.
"""
my_reana_server_url_cmd = subprocess.getoutput('reana-cluster env')
my_reana_access_token = subprocess.getoutput('kubectl logs -l app=server |'
' grep access_token: |'
' awk \'{print $NF;}\' |'
' tr -d \'[:space:]\'')
print(my_reana_server_url_cmd)
print('export REANA_ACCESS_TOKEN={0}'.format(my_reana_access_token))
@click.option('--component', '-c', multiple=True,
default=['reana-demo-root6-roofit'],
help='Which examples to run? [reana-demo-root6-roofit]')
@click.option('--workflow_engine', '-w', multiple=True,
default=['cwl', 'serial', 'yadage'],
help='Which workflow engine to run? [cwl,serial,yadage]')
@click.option('--output', '-o', multiple=True,
default=['plot.png'],