Skip to content

Commit

Permalink
add: Now -o modify the shared volume when running with `--docker-ru…
Browse files Browse the repository at this point in the history
…n`. #2075
  • Loading branch information
Luis Gonzalez committed Nov 3, 2021
1 parent e655f0d commit 9fa79dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
16 changes: 13 additions & 3 deletions deps/wazuh_testing/wazuh_testing/qa_docs/dockerfiles/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/bin/bash

BRANCH="$1";
CMD="${@:2}";
SHARED_VOL="$2"
CMD="${@:3}";

# Clone tests to be parsed as qa-docs input
mkdir /tests && cd /tests
echo "Cloning tests to parse from ${BRANCH} branch"
git clone https:/wazuh/wazuh-qa --depth=1 -b ${BRANCH} &> /dev/null

# get run status
status=$?
# If not returned 0, exit
if [ $status -ne 0 ]
then
echo "Could not download tests input from ${BRANCH} branch"
exit 1
fi

/usr/local/bin/qa-docs -d -I /tests/wazuh-qa/tests --validate-parameters ${CMD}

# get run status
Expand All @@ -31,6 +41,6 @@ echo "Running /usr/local/bin/qa-docs -I /tests/wazuh-qa/tests ${CMD}"
/usr/local/bin/qa-docs -I /tests/wazuh-qa/tests ${CMD}

# Move the documentation parsed to the shared dir
echo "Moving qa-docs output to shared directory /tmp/qa_docs"
echo "Moving qa-docs output to shared directory: ${SHARED_VOL}/output"
rm -rf /qa_docs/output &> /dev/null
mv -f /usr/local/lib/python3.8/dist-packages/wazuh_testing-*/wazuh_testing/qa_docs/output/ /qa_docs
mv -f /tmp/qa_docs/output /qa_docs
13 changes: 7 additions & 6 deletions deps/wazuh_testing/wazuh_testing/qa_docs/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def run_local_command_with_output(command):
return run.stdout.read().decode()


def qa_docs_docker_run(qa_branch, command):
def qa_docs_docker_run(qa_branch, command, output_path):
"""Run qa-docs in a Linux docker container.
Having this functionality helps the people that do not have ElasticSearch and(or) wazuh framework to generate
Expand All @@ -269,20 +269,21 @@ def qa_docs_docker_run(qa_branch, command):
qa_branch (str): Wazuh qa branch that will be used as tests input.
command (str): A string with the arguments to pass qa-docs when running within the docker container.
"""
docker_args = f"{qa_branch} {command}"
docker_args = f"{qa_branch} {output_path} {command}"
docker_image_name = 'wazuh/qa-docs'
docker_image_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'dockerfiles')

utils_logger.info(f"Building qa-docs docker image")
run_local_command(f"cd {docker_image_path} && docker build -q -t {docker_image_name} .")
run_local_command_with_output(f"cd {docker_image_path} && docker build -q -t {docker_image_name} .")

utils_logger.info(f"Running the Linux container")
run_local_command(f"docker run --name qa_docs_container --rm -v {os.path.join(gettempdir(), 'qa_docs')}:/qa_docs {docker_image_name} {docker_args}")
run_local_command(f"docker run --name qa_docs_container --rm -v {output_path}:/qa_docs {docker_image_name} "
f"{docker_args}")


def get_qa_docs_run_options(args):
"""Get the parameters to run qa-docs.
Args:
args (argparse.Namespace): arguments that are passed to the tool.
Returns:
Expand All @@ -309,4 +310,4 @@ def get_qa_docs_run_options(args):
for test_name in args.test_names:
command += f" {test_name} "

return command
return command
12 changes: 7 additions & 5 deletions deps/wazuh_testing/wazuh_testing/scripts/qa_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ def set_parameters(args):
if args.no_logging:
set_qadocs_logger_level(None)

if args.output_path:
if args.run_with_docker:
global OUTPUT_PATH
OUTPUT_PATH = os.path.join(gettempdir(), 'qa_docs')

if args.output_path:
OUTPUT_PATH = args.output_path

if args.output_format:
Expand Down Expand Up @@ -374,14 +377,13 @@ def index_and_visualize_data(args):
def main():
args, parser = get_parameters()

if not args.run_with_docker:
set_parameters(args)
validate_parameters(args, parser)
set_parameters(args)
if not args.run_with_docker: validate_parameters(args, parser)
if args.validate_parameters: return 0

if args.run_with_docker:
command = get_qa_docs_run_options(args)
qa_docs_docker_run(args.qa_branch, command)
qa_docs_docker_run(args.qa_branch, command, OUTPUT_PATH)
elif args.version:
with open(VERSION_PATH, 'r') as version_file:
version_data = version_file.read()
Expand Down

0 comments on commit 9fa79dc

Please sign in to comment.