Skip to content

Commit

Permalink
cli: allow passing email & pwd to cluster-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Sep 3, 2020
1 parent 2909e92 commit 4408587
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -200,7 +200,7 @@ deploy: # Deploy/redeploy previously built REANA cluster.
sleep ${TIMECHECK}; \
fi;\
done && \
source ${PWD}/scripts/create-admin-user.sh ${TRUNC_INSTANCE_NAME} && \
source ${PWD}/scripts/create-admin-user.sh ${TRUNC_INSTANCE_NAME} admin@reana.io 123456 && \
eval $$(reana-dev client-setup-environment $(addprefix --server-hostname , ${SERVER_URL}))

example: # Run one or several demo examples.
Expand Down
2 changes: 1 addition & 1 deletion helm/reana/templates/NOTES.txt
Expand Up @@ -13,7 +13,7 @@ If you are installing REANA for the first time, there are a few steps left to fi

3. Create your administrator user and store the token:

$ kubectl exec $REANA_SERVER -- flask reana-admin create-admin-user john.doe@example.org
$ kubectl exec $REANA_SERVER -- flask reana-admin create-admin-user --email john.doe@example.org --password mysecretpassword
<reana-admin-access-token-value>
$ read -s REANA_ADMIN_ACCESS_TOKEN # paste the secret here
$ kubectl create secret generic {{ .Release.Name }}-admin-access-token \
Expand Down
25 changes: 23 additions & 2 deletions reana/reana_dev/cluster.py
Expand Up @@ -241,15 +241,33 @@ def cluster_build(
default="",
help="Which components to exclude from build? [c1,c2,c3]",
)
@click.option(
"--admin-email", required=True, help="Admin user email address",
)
@click.option(
"--admin-password", required=True, help="Admin user password",
)
@click.option(
"--instance-name", default="reana", help="REANA instance name",
)
def cluster_deploy(
namespace, job_mounts, mode, values, exclude_components
namespace,
job_mounts,
mode,
values,
exclude_components,
admin_email,
admin_password,
instance_name,
): # noqa: D301
"""Deploy REANA cluster.
\b
Example:
$ reana-dev cluster-deploy --mode debug
--exclude-components=r-ui
--admin-email john.doe@example.org
--admin-password mysecretpassword
"""

def job_mounts_to_config(job_mounts):
Expand Down Expand Up @@ -301,7 +319,10 @@ def job_mounts_to_config(job_mounts):
"helm dep update helm/reana",
helm_install,
"kubectl config set-context --current --namespace={}".format(namespace),
os.path.join(get_srcdir("reana"), "scripts/create-admin-user.sh"),
os.path.join(
get_srcdir("reana"),
f"scripts/create-admin-user.sh {instance_name} {admin_email} {admin_password}",
),
]
if mode in ("latest", "debug"):
cmds.append("reana-dev git-submodule --update")
Expand Down
10 changes: 7 additions & 3 deletions reana/reana_dev/run.py
Expand Up @@ -202,7 +202,10 @@ def run_ci(
cmd += " --no-cache"
run_command(cmd, "reana")
# deploy cluster
cmd = "reana-dev cluster-deploy --mode {}".format(mode)
cmd = (
f"reana-dev cluster-deploy --mode {mode}"
" --admin-email john.doe@example.org --admin-password 123456"
)
for job_mount in job_mounts:
cmd += " -j {}".format(job_mount)
run_command(cmd, "reana")
Expand Down Expand Up @@ -252,7 +255,8 @@ def run_ci(
"--option",
"options",
multiple=True,
help="Additional operatioal options for the workflow execution. " "E.g. CACHE=off.",
help="Additional operational options for the workflow execution. "
"E.g. CACHE=off.",
)
@run_commands.command(name="run-example")
def run_example(
Expand Down Expand Up @@ -281,7 +285,7 @@ def run_example(
:param parameters: Additional input parameters to override original ones
from reana.yaml.
E.g. -p myparam1=myval1 -p myparam2=myval2.
:param options: Additional operatioal options for the workflow execution.
:param options: Additional operational options for the workflow execution.
E.g. CACHE=off.
:type component: str
Expand Down
18 changes: 15 additions & 3 deletions scripts/create-admin-user.sh
Expand Up @@ -3,11 +3,18 @@
# Two parameters: instance name and email address of the admin
instance_name=$1
if [ -z "$instance_name" ]; then
instance_name=reana
echo 'Instance name missing.'
exit 1
fi
email_address=$2
if [ -z "$email_address" ]; then
email_address=root@localhost
echo 'Email address missing.'
exit 1
fi
password=$3
if [ -z "$password" ]; then
echo 'Password missing.'
exit 1
fi

# Get REANA Server pod name
Expand All @@ -28,7 +35,12 @@ kubectl exec "$REANA_SERVER" -- ./scripts/setup

# Create admin user
admin_access_token=$(kubectl exec "$REANA_SERVER" -- \
flask reana-admin create-admin-user $email_address)
flask reana-admin create-admin-user --email $email_address --password $password)
if [ $? -ne 0 ]; then
# Failure output
echo $admin_access_token
exit 1
fi

# Add token to secrets
kubectl create secret generic "$instance_name"-admin-access-token \
Expand Down

0 comments on commit 4408587

Please sign in to comment.