Skip to content

Commit

Permalink
config: generate config inside current directory
Browse files Browse the repository at this point in the history
Signed-off-by: Diego Rodriguez <[email protected]>
  • Loading branch information
Diego Rodriguez committed Feb 17, 2017
1 parent 25b5509 commit 125e02d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
47 changes: 24 additions & 23 deletions docs/gettingstarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,30 @@ Second, you can build resource manifests by doing:
.. code-block:: console
$ reana-resources-k8s build-manifests
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/job-controller.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/message-broker.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/storage-admin.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/yadage-alice-worker.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/yadage-atlas-worker.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/yadage-cms-worker.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/yadage-lhcb-worker.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/workflow-controller.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/workflow-monitor.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/deployments/zeromq-msg-proxy.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/namespaces/alice.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/namespaces/atlas.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/namespaces/cms.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/namespaces/lhcb.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/resourcequotas/alice-quota.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/resourcequotas/atlas-quota.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/resourcequotas/cms-quota.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/resourcequotas/lhcb-quota.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/services/job-controller.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/services/message-broker.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/services/workflow-controller.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/services/workflow-monitor.yaml
Created -> /home/rodrigdi/reanahub-forks/reana-resources-k8s/reana_resources_k8s/templates/../configuration-manifests/services/zeromq-msg-proxy.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/job-controller.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/message-broker.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/storage-admin.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/yadage-alice-worker.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/yadage-atlas-worker.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/yadage-cms-worker.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/yadage-lhcb-worker.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/workflow-controller.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/workflow-monitor.yaml
Created -> /home/reanauser/reana/configuration-manifests/deployments/zeromq-msg-proxy.yaml
Created -> /home/reanauser/reana/configuration-manifests/namespaces/alice.yaml
Created -> /home/reanauser/reana/configuration-manifests/namespaces/atlas.yaml
Created -> /home/reanauser/reana/configuration-manifests/namespaces/cms.yaml
Created -> /home/reanauser/reana/configuration-manifests/namespaces/lhcb.yaml
Created -> /home/reanauser/reana/configuration-manifests/resourcequotas/alice-quota.yaml
Created -> /home/reanauser/reana/configuration-manifests/resourcequotas/atlas-quota.yaml
Created -> /home/reanauser/reana/configuration-manifests/resourcequotas/cms-quota.yaml
Created -> /home/reanauser/reana/configuration-manifests/resourcequotas/lhcb-quota.yaml
Created -> /home/reanauser/reana/configuration-manifests/services/job-controller.yaml
Created -> /home/reanauser/reana/configuration-manifests/services/message-broker.yaml
Created -> /home/reanauser/reana/configuration-manifests/services/workflow-controller.yaml
Created -> /home/reanauser/reana/configuration-manifests/services/workflow-monitor.yaml
Created -> /home/reanauser/reana/configuration-manifests/services/zeromq-msg-proxy.yaml
Once it is done, a directory called `configuration-manifests` with the following structure should be available:

Expand Down
32 changes: 17 additions & 15 deletions scripts/reana-resources-k8s
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@
# submit itself to any jurisdiction.

split_file () {
file=$1
extension=${file##*.}
cd "$(dirname "$file")" || exit
csplit -zq "$(basename "$file")" /"$2"/ "{*}"
file_path=$1
sep=$2
extension=${file_path##*.}
cd "$(dirname "$file_path")" || exit
csplit -zq "$(basename "$file_path")" /"$sep"/ "{*}"
for old_file_name in xx*
do
new_file_name="$(grep 'name' "$old_file_name" | head -1 | cut -d ':' -f 2 | tr -d ' ').$extension"
mv "$old_file_name" "$new_file_name"
echo "Created -> $(dirname "$file")/$new_file_name"
echo "Created -> $(dirname "$file_path")/$new_file_name"
done
rm "$config_file_path"
cd "$(dirname "$file")" || exit
cd "$OLDPWD" || exit
}

populate_templates () {
resource=$1
mkdir -p "$templates_path"/../configuration-manifests/"$resource"
templates_path=$1
resource=$2
output_directory="$PWD"/configuration-manifests/"$resource"
mkdir -p "$output_directory"
for template_file_path in $templates_path/"$resource"/*template.yaml
do
template_file_name=$(printf '%s' "$template_file_path" | sed -e "s@$templates_path\/@@g")
template_file_name=$(printf '%s' "$template_file_path" | sed -e "s@$templates_path\/$resource\/@@g")
config_file_name=$(printf '%s' "$template_file_name" | sed -e "s/-template//g")
config_file_path="$templates_path/../configuration-manifests/$config_file_name"
config_file_path="$output_directory/$config_file_name"
jinja2 "$template_file_path" "$templates_path/config.yaml" > "$config_file_path"
sed '/^[[:space:]]*$/d' -i "$config_file_path"
if [ "$(grep -c '\-\-\-' "$config_file_path")" -gt 1 ]
Expand All @@ -65,10 +67,10 @@ print(pkg_resources.resource_filename('reana_resources_k8s', \
# grab the name of the resources which need to be built
resources=$(for child in $templates_path/*; do file_name=$(basename "$child"); if [ "$file_name" != "config.yaml" ]; then echo "$file_name"; fi ; done)

for resource in $resources;
for resource in $resources
do
populate_templates "$resource";
done;
populate_templates "$templates_path" "$resource"
done
}

usage() {
Expand All @@ -79,7 +81,7 @@ usage() {
echo " -h Help"
}

if [ "$1" != "" ];
if [ "$1" != "" ]
then
case $1 in
build-manifests ) build_manifests
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
url='https://github.com/reanahub/reana-resources-k8s',
packages=['reana_resources_k8s', ],
zip_safe=False,
include_package_data=True,
extras_require=extras_require,
install_requires=install_requires,
setup_requires=setup_requires,
Expand Down

0 comments on commit 125e02d

Please sign in to comment.