Skip to content

Commit ce7b457

Browse files
committed
cli: parametrisable run-ci command
Parametrises `run-ci` to allow various CI builds via one single CLI command. Signed-off-by: Tibor Šimko <[email protected]>
1 parent fbee402 commit ce7b457

File tree

1 file changed

+137
-32
lines changed

1 file changed

+137
-32
lines changed

reana/cli.py

+137-32
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ def cli(): # noqa: D301
185185
$ mkdir -p ~/project/reana/src
186186
$ cd ~/project/reana/src
187187
$ # create new virtual environment
188-
$ virtualenv ~/.virtualenvs/myreana
189-
$ source ~/.virtualenvs/myreana/bin/activate
188+
$ virtualenv ~/.virtualenvs/reana
189+
$ source ~/.virtualenvs/reana/bin/activate
190190
$ # install reana-dev developer helper script
191191
$ pip install git+git://github.com/reanahub/reana.git#egg=reana
192192
$ # run ssh-agent locally to simplify GitHub interaction
@@ -202,27 +202,31 @@ def cli(): # noqa: D301
202202
$ eval "$(reana-dev git-fork -c ALL)"
203203
$ reana-dev git-clone -c ALL -u tiborsimko
204204
205-
How to install latest ``master`` REANA client CLI scripts:
205+
How to run CI tests:
206206
207207
.. code-block:: console
208208
209209
\b
210-
$ reana-dev client-install
210+
$ # example (a): fast, CLI mode only, fast example
211+
$ reana-dev cluster-delete
212+
$ reana-dev run-ci -m /var/reana:/var/reana -c r-d-helloworld --exclude-components=r-ui,r-a-vomsproxy
213+
$ # example (b): slow, CLI and Web modes, all examples
214+
$ reana-dev cluster-delete
215+
$ reana-dev run-ci
211216
212-
How to compile and deploy latest ``master`` REANA cluster:
217+
How to create REANA cluster:
213218
214219
.. code-block:: console
215220
216221
\b
217-
$ # create cluster and set docker environment
222+
$ # example (a): simple cluster creation
218223
$ reana-dev cluster-create
219-
$ kubectl cluster-info --context kind-kind
220-
$ # option (a): cluster in production-like mode
221-
$ reana-dev docker-build
222-
$ helm install reana helm/reana
223-
$ # option (b): cluster in developer-like debug-friendly mode
224-
$ reana-dev docker-build -b DEBUG=1
225-
$ helm install reana helm/reana --set debug.enabled=true
224+
$ # example (b): mount sharing /var/reana with host
225+
$ reana-dev cluster-create -m /var/reana:/var/reana
226+
$ # example (c): mount sharing /var/reana with host and /cvmfs for jobs
227+
$ reana-dev cluster-create -m /var/reana:/var/reana -j /cvmfs:/cvmfs
228+
$ # example (d): debug mode with code sharing as well
229+
$ reana-dev cluster-create -m /var/reana:/var/reana --debug
226230
227231
How to set up your shell environment variables:
228232
@@ -255,6 +259,7 @@ def cli(): # noqa: D301
255259
$ cd reana-workflow-controller
256260
$ reana-dev git-checkout -b . 72 --fetch
257261
$ reana-dev docker-build -c .
262+
$ reana-dev kind-load-docker-image -c .
258263
$ reana-dev kubectl-delete-pod -c .
259264
260265
How to test multiple component branches:
@@ -266,7 +271,9 @@ def cli(): # noqa: D301
266271
$ reana-dev git-checkout -b reana-workflow-controller 98
267272
$ reana-dev git-status
268273
$ reana-dev docker-build
274+
$ reana-dev kind-load-docker-image -c reana-server
269275
$ reana-dev kubectl-delete-pod -c reana-server
276+
$ reana-dev kind-load-docker-image -c reana-workflow-controller
270277
$ reana-dev kubectl-delete-pod -c reana-workflow-controller
271278
272279
How to test multiple component branches with commits to shared modules:
@@ -278,17 +285,7 @@ def cli(): # noqa: D301
278285
$ reana-dev git-checkout -b reana-db 73
279286
$ reana-dev git-checkout -b reana-workflow-controller 98
280287
$ reana-dev git-checkout -b reana-server 112
281-
$ reana-dev git-submodule --update
282-
$ reana-dev client-install
283-
$ reana-dev install-cluster
284-
$ reana-dev docker-build
285-
$ helm delete helm/reana
286-
$ docker-exec -i -t kind-control-plane sh -c 'sudo rm -rf /var/reana/*'
287-
$ helm install reana helm/reana
288-
$ eval $(reana-dev client-setup-environment)
289-
$ reana-dev run-example -c r-d-helloworld
290-
$ reana-dev git-submodule --delete
291-
$ reana-dev git-status -s
288+
$ reana-dev run-ci [using same old options]
292289
293290
How to release and push cluster component images:
294291
@@ -757,6 +754,15 @@ def volume_mounts_to_list(ctx, param, value):
757754
sys.exit(1)
758755

759756

757+
def is_cluster_created():
758+
"""Return True/False based on whether there is a cluster created already."""
759+
cmd = "kind get clusters"
760+
output = run_command(cmd, "reana", return_output=True)
761+
if "kind" in output:
762+
return True
763+
return False
764+
765+
760766
@cli.command()
761767
def version():
762768
"""Show version."""
@@ -1807,28 +1813,121 @@ def cluster_undeploy(): # noqa: D301
18071813
display_message(msg, "reana")
18081814

18091815

1816+
@click.option(
1817+
"--build-arg",
1818+
"-b",
1819+
default="",
1820+
multiple=True,
1821+
help="Any build arguments? (e.g. `-b COMPUTE_BACKENDS=kubernetes,htcondorcern,slurmcern`)",
1822+
)
18101823
@click.option(
18111824
"-d",
18121825
"--debug",
18131826
is_flag=True,
18141827
default=False,
18151828
help="Should we deploy REANA in debug mode? ",
18161829
)
1830+
@click.option(
1831+
"--exclude-components",
1832+
default="",
1833+
help="Which components to exclude from build? [c1,c2,c3]",
1834+
)
1835+
@click.option(
1836+
"-m",
1837+
"--mount",
1838+
"mounts",
1839+
multiple=True,
1840+
help="Which local directories to mount in the cluster nodes? [local_path:cluster_node_path]",
1841+
)
1842+
@click.option(
1843+
"-j",
1844+
"--job-mounts",
1845+
multiple=True,
1846+
help="Which directories from the Kubernetes nodes to mount inside the job pods? "
1847+
"cluster_node_path:job_pod_mountpath, e.g /var/reana/mydata:/mydata",
1848+
)
1849+
@click.option("--no-cache", is_flag=True, help="Do not use Docker image layer cache.")
1850+
@click.option(
1851+
"--component",
1852+
"-c",
1853+
multiple=True,
1854+
default=["DEMO"],
1855+
help="Which examples to run? [default=DEMO]",
1856+
)
18171857
@cli.command(name="run-ci")
1818-
def run_ci(debug): # noqa: D301
1858+
def run_ci(
1859+
build_arg, debug, exclude_components, mounts, job_mounts, no_cache, component,
1860+
): # noqa: D301
18191861
"""Run CI build.
18201862
18211863
Builds and installs REANA and runs a demo example.
1864+
1865+
\b
1866+
Basically it runs the following sequence of commands:
1867+
$ reana-dev client-install
1868+
$ reana-dev cluster-undeploy
1869+
$ reana-dev cluster-build
1870+
$ reana-dev cluster-deploy
1871+
$ eval "$(reana-dev client-setup-environment)" && reana-dev run-example
1872+
1873+
in the appropriate order and with the appropriate mounting or debugging
1874+
arguments.
1875+
1876+
\b
1877+
Example:
1878+
$ reana-dev run-cli -m /var/reana:/var/reana
1879+
-m /usr/share/local/mydata:/mydata
1880+
-j /mydata:/mydata
1881+
-c r-d-helloworld
1882+
--exclude-components=r-ui,r-a-vomsproxy
1883+
--debug
18221884
"""
1885+
# parse arguments
1886+
components = select_components(component)
1887+
# create cluster if needed
1888+
if not is_cluster_created():
1889+
cmd = "reana-dev cluster-create"
1890+
for mount in mounts:
1891+
cmd += " -m {}".format(mount)
1892+
if debug:
1893+
cmd += " --debug"
1894+
run_command(cmd, "reana")
1895+
# prefetch and load images for selected demo examples
1896+
for component in components:
1897+
for cmd in [
1898+
"reana-dev docker-pull -c {}".format(component),
1899+
"reana-dev kind-load-docker-image -c {}".format(component),
1900+
]:
1901+
run_command(cmd, "reana")
1902+
# undeploy cluster and install latest client
18231903
for cmd in [
18241904
"reana-dev cluster-undeploy",
18251905
"reana-dev client-install",
1826-
"reana-dev cluster-build" + (" --debug" if debug else ""),
1827-
"reana-dev kind-load-docker-image -c CLUSTER --exclude-components=r-ui,r-a-vomsproxy",
1828-
"reana-dev cluster-deploy" + (" --debug" if debug else ""),
1829-
"eval $(reana-dev client-setup-environment) && reana-dev run-example",
18301906
]:
18311907
run_command(cmd, "reana")
1908+
# build cluster
1909+
cmd = "reana-dev cluster-build"
1910+
if exclude_components:
1911+
cmd += " --exclude-components {}".format(exclude_components)
1912+
for arg in build_arg:
1913+
cmd += " -b {0}".format(arg)
1914+
if debug:
1915+
cmd += " --debug"
1916+
if no_cache:
1917+
cmd += " --no-cache"
1918+
run_command(cmd, "reana")
1919+
# deploy cluster
1920+
cmd = "reana-dev cluster-deploy"
1921+
if debug:
1922+
cmd += " --debug"
1923+
for job_mount in job_mounts:
1924+
cmd += " -j {}".format(job_mount)
1925+
run_command(cmd, "reana")
1926+
# run demo examples
1927+
cmd = "eval $(reana-dev client-setup-environment) && reana-dev run-example"
1928+
for component in components:
1929+
cmd += " -c {}".format(component)
1930+
run_command(cmd, "reana")
18321931

18331932

18341933
@cli.command(name="client-setup-environment")
@@ -2029,7 +2128,7 @@ def run_example(
20292128
"mounts",
20302129
multiple=True,
20312130
callback=volume_mounts_to_list,
2032-
help="Which local directories would be mounted in the Kind nodes? local_path:cluster_node_path",
2131+
help="Which local directories to mount in the cluster nodes? [local_path:cluster_node_path]",
20332132
)
20342133
@click.option(
20352134
"--debug",
@@ -2039,9 +2138,15 @@ def run_example(
20392138
)
20402139
@click.option("--worker-nodes", default=0, help="How many worker nodes? [default=0]")
20412140
@cli.command(name="cluster-create")
2042-
def cluster_create(mounts, debug, worker_nodes):
2043-
"""Create cluster."""
2141+
def cluster_create(mounts, debug, worker_nodes): # noqa: D301
2142+
"""Create cluster.
20442143
2144+
\b
2145+
Example:
2146+
$ reana-dev cluster-create -m /var/reana:/var/reana
2147+
-m /usr/share/local/mydata:/mydata
2148+
--debug
2149+
"""
20452150
class literal_str(str):
20462151
pass
20472152

0 commit comments

Comments
 (0)