From 59a3fc8a376e5e8f7b7e90f186cbb86708576e03 Mon Sep 17 00:00:00 2001 From: Frank Escobar Date: Tue, 1 Dec 2020 12:24:00 +0000 Subject: [PATCH] Updating version to 2.13.6 & Doc Improvements Updating flask-swagger-ui to 3.36.0 #134 - Order of test cases in the Emailable Report #135 - Create project if it doesn't already exist --- .travis.yml | 2 +- README.md | 23 +++-- allure-docker-api/app.py | 92 ++++++++++--------- allure-docker-api/static/swagger/swagger.json | 8 ++ docker-compose-dev.yml | 2 +- docker-custom/Dockerfile.bionic-custom | 8 +- docker/Dockerfile.bionic | 4 +- 7 files changed, 82 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index 47f416d..d1a30d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ language: bash env: global: - - ALLURE_RELEASE=2.13.5 + - ALLURE_RELEASE=2.13.6 - TARGET=frankescobar/allure-docker-service - QEMU_VERSION=v4.0.0 matrix: diff --git a/README.md b/README.md index 12f83a5..e2eaf49 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Table of contents * [Send results through API](#send-results-through-api) * [Content-Type - application/json](#content-type---applicationjson) * [Content-Type - multipart/form-data](#content-type---multipartform-data) + * [Force Project Creation Option](#force-project-creation-option) * [Customize Executors Configuration](#customize-executors-configuration) * [API Response Less Verbose](#api-response-less-verbose) * [Switching version](#switching-version) @@ -92,9 +93,9 @@ The following table shows the provided Manifest Lists. | **Tag** | **allure-docker-service Base Image** | |----------------------------------------|---------------------------------------------------| -| latest, 2.13.5 | frankescobar/allure-docker-service:2.13.5-amd64 | -| | frankescobar/allure-docker-service:2.13.5-arm32v7 | -| | frankescobar/allure-docker-service:2.13.5-arm64v8 | +| latest, 2.13.6 | frankescobar/allure-docker-service:2.13.6-amd64 | +| | frankescobar/allure-docker-service:2.13.6-arm32v7 | +| | frankescobar/allure-docker-service:2.13.6-arm64v8 | ## USAGE ### Generate Allure Results @@ -112,6 +113,7 @@ We have some examples projects: - [allure-docker-python-behave-example](https://github.com/fescobar/allure-docker-service-examples/tree/master/allure-docker-python-behave-example) - [allure-docker-python-pytest-example](https://github.com/fescobar/allure-docker-service-examples/tree/master/allure-docker-python-pytest-example) - [AllureDockerCSharpExample](https://github.com/fescobar/allure-docker-service-examples/tree/master/AllureDockerCSharpExample) +- [AllureDockerCSharpSpecFlow3Example](https://github.com/fescobar/allure-docker-service-examples/tree/master/AllureDockerCSharpSpecFlow3Example) In this case we are going to generate results using the java project [allure-docker-java-testng-example](https://github.com/fescobar/allure-docker-service-examples/tree/master/allure-docker-java-testng-example) of this repository. @@ -255,6 +257,10 @@ NOTE FOR WINDOWS USERS: With this option you could generate multiple reports for multiple projects, you can create, delete and get projects using [Project Endpoints](#project-endpoints). You can use Swagger documentation to help you. +IMPORTANT NOTE: +- For multiple projects configuration you must use `CHECK_RESULTS_EVERY_SECONDS` with value `NONE`. Otherwise, your performance machine would be affected, it could consume high memory, processors and storage. Use the endpoint `GET /generate-report` on demand after sending the results `POST /send-results`. +- If you use automatic reports a daemom is created and it will be listening any change in the `results` directory it will generate a new report each time find a new file. The same will happen for every project. For that reason, it's convenient disable the automatic reports using the value `NONE` in `CHECK_RESULTS_EVERY_SECONDS`. + ##### Multiple Project - Docker on Unix/Mac ```sh docker run -p 5050:5050 -e CHECK_RESULTS_EVERY_SECONDS=NONE -e KEEP_HISTORY=1 \ @@ -633,6 +639,11 @@ NOTE: - If you want to clean the results use the endpoint `GET /clean-results` ([Allure API](#allure-api)). +##### Force Project Creation Option +`Available from Allure Docker Service version 2.13.6` +If you use the query parameter `force_project_creation` with value `true`, the project where you want to send the results will be created automatically in case doesn't exist. + +`POST /send-results?project_id=any-unexistent-project&force_project_creation=true` #### Customize Executors Configuration `Available from Allure Docker Service version 2.13.3` @@ -693,7 +704,7 @@ You can switch the version container using `frankescobar/allure-docker-service:$ Docker Compose example: ```sh allure: - image: "frankescobar/allure-docker-service:2.13.5" + image: "frankescobar/allure-docker-service:2.13.6" ``` or using latest version: @@ -1242,7 +1253,7 @@ If you want to use docker without sudo, read following links: ### Build image ```sh -docker build -t allure-release -f docker-custom/Dockerfile.bionic-custom --build-arg ALLURE_RELEASE=2.13.5 . +docker build -t allure-release -f docker-custom/Dockerfile.bionic-custom --build-arg ALLURE_RELEASE=2.13.6 . ``` ### Run container ```sh @@ -1293,5 +1304,5 @@ docker run -d -p 5050:5050 frankescobar/allure-docker-service ``` ### Download specific tagged image registered (Example) ```sh -docker run -d -p 5050:5050 frankescobar/allure-docker-service:2.13.5 +docker run -d -p 5050:5050 frankescobar/allure-docker-service:2.13.6 ``` diff --git a/allure-docker-api/app.py b/allure-docker-api/app.py index af0e64c..28de621 100644 --- a/allure-docker-api/app.py +++ b/allure-docker-api/app.py @@ -680,7 +680,7 @@ def latest_report_endpoint(): @app.route("/send-results", methods=['POST'], strict_slashes=False) @app.route("/allure-docker-service/send-results", methods=['POST'], strict_slashes=False) @jwt_required -def send_results_endpoint(): +def send_results_endpoint(): #pylint: disable=too-many-branches try: content_type = str(request.content_type) if content_type is None: @@ -694,14 +694,17 @@ def send_results_endpoint(): project_id = resolve_project(request.args.get('project_id')) if is_existent_project(project_id) is False: - body = { - 'meta_data': { - 'message' : "project_id '{}' not found".format(project_id) + if request.args.get('force_project_creation') == 'true': + project_id = create_project({ "id": project_id }) + else: + body = { + 'meta_data': { + 'message' : "project_id '{}' not found".format(project_id) + } } - } - resp = jsonify(body) - resp.status_code = 404 - return resp + resp = jsonify(body) + resp.status_code = 404 + return resp validated_results = [] processed_files = [] @@ -956,6 +959,7 @@ def emailable_report_render_endpoint(): tcs_latest_report_project = "{}/reports/latest/data/test-cases/*.json".format(project_path) files = glob.glob(tcs_latest_report_project) + files.sort(key=os.path.getmtime, reverse=True) test_cases = [] for file_name in files: with open(file_name) as file: @@ -1089,41 +1093,7 @@ def create_project_endpoint(): if not request.is_json: raise Exception("Header 'Content-Type' is not 'application/json'") - json_body = request.get_json() - - if 'id' not in json_body: - raise Exception("'id' is required in the body") - - if isinstance(json_body['id'], str) is False: - raise Exception("'id' should be string") - - if not json_body['id'].strip(): - raise Exception("'id' should not be empty") - - if len(json_body['id']) > 100: - raise Exception("'id' should not contains more than 100 characters.") - - project_id_pattern = re.compile('^[a-z\\d]([a-z\\d -]*[a-z\\d])?$') - match = project_id_pattern.match(json_body['id']) - if match is None: - raise Exception("'id' should contains alphanumeric lowercase characters or hyphens. For example: 'my-project-id'") #pylint: disable=line-too-long - - project_id = json_body['id'] - if is_existent_project(project_id) is True: - raise Exception("project_id '{}' is existent".format(project_id)) - - if project_id == 'default': - raise Exception("The id 'default' is not allowed. Try with another project_id") - - project_path = get_project_path(project_id) - latest_report_project = '{}/reports/latest'.format(project_path) - results_project = '{}/results'.format(project_path) - - if not os.path.exists(latest_report_project): - os.makedirs(latest_report_project) - - if not os.path.exists(results_project): - os.makedirs(results_project) + project_id = create_project(request.get_json()) except Exception as ex: body = { 'meta_data': { @@ -1404,6 +1374,42 @@ def send_json_results(results_project, validated_results, processed_files, faile if file is not None: file.close() +def create_project(json_body): + if 'id' not in json_body: + raise Exception("'id' is required in the body") + + if isinstance(json_body['id'], str) is False: + raise Exception("'id' should be string") + + if not json_body['id'].strip(): + raise Exception("'id' should not be empty") + + if len(json_body['id']) > 100: + raise Exception("'id' should not contains more than 100 characters.") + + project_id_pattern = re.compile('^[a-z\\d]([a-z\\d -]*[a-z\\d])?$') + match = project_id_pattern.match(json_body['id']) + if match is None: + raise Exception("'id' should contains alphanumeric lowercase characters or hyphens. For example: 'my-project-id'") #pylint: disable=line-too-long + + project_id = json_body['id'] + if is_existent_project(project_id) is True: + raise Exception("project_id '{}' is existent".format(project_id)) + + if project_id == 'default': + raise Exception("The id 'default' is not allowed. Try with another project_id") + + project_path = get_project_path(project_id) + latest_report_project = '{}/reports/latest'.format(project_path) + results_project = '{}/results'.format(project_path) + + if not os.path.exists(latest_report_project): + os.makedirs(latest_report_project) + + if not os.path.exists(results_project): + os.makedirs(results_project) + + return project_id def is_existent_project(project_id): if not project_id.strip(): diff --git a/allure-docker-api/static/swagger/swagger.json b/allure-docker-api/static/swagger/swagger.json index bd7d12a..5e4187d 100644 --- a/allure-docker-api/static/swagger/swagger.json +++ b/allure-docker-api/static/swagger/swagger.json @@ -150,6 +150,14 @@ "schema":{ "type":"string" } + }, + { + "in":"query", + "name":"force_project_creation", + "schema":{ + "type":"string" + }, + "value": "false" } ], "requestBody":{ diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 3225274..dfe5a49 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -10,7 +10,7 @@ services: context: ../allure-docker-service dockerfile: docker-custom/Dockerfile.bionic-custom args: - ALLURE_RELEASE: "2.13.5" + ALLURE_RELEASE: "2.13.6" environment: DEV_MODE: 0 CHECK_RESULTS_EVERY_SECONDS: NONE diff --git a/docker-custom/Dockerfile.bionic-custom b/docker-custom/Dockerfile.bionic-custom index 9d5d67b..6022ed4 100644 --- a/docker-custom/Dockerfile.bionic-custom +++ b/docker-custom/Dockerfile.bionic-custom @@ -1,9 +1,9 @@ ARG ARCH=amd64 ARG JDK=adoptopenjdk:11-jre-openj9-bionic ARG BUILD_DATE -ARG BUILD_VERSION=2.13.5-custom +ARG BUILD_VERSION=2.13.6-custom ARG BUILD_REF=na -ARG ALLURE_RELEASE=2.13.5 +ARG ALLURE_RELEASE=2.13.6 ARG ALLURE_REPO=https://dl.bintray.com/qameta/maven/io/qameta/allure/allure-commandline ARG UID=1000 ARG GID=1000 @@ -16,7 +16,7 @@ RUN apk add build-base RUN pip install -U pylint && \ pip install -U flask-cors RUN pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0 + pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 ENV ROOT_DIR=/code RUN mkdir -p $ROOT_DIR @@ -59,7 +59,7 @@ RUN apt-get update && \ ln -s `which python3` /usr/bin/python && \ pip3 install --upgrade pip && \ pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0 && \ + pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 && \ pip install -U flask-cors && \ curl ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.zip -L -o /tmp/allure-commandline.zip && \ unzip -q /tmp/allure-commandline.zip -d / && \ diff --git a/docker/Dockerfile.bionic b/docker/Dockerfile.bionic index e162dc0..9718da8 100644 --- a/docker/Dockerfile.bionic +++ b/docker/Dockerfile.bionic @@ -18,7 +18,7 @@ RUN apk add build-base RUN pip install -U pylint && \ pip install -U flask-cors RUN pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0 + pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 ENV ROOT_DIR=/code RUN mkdir -p $ROOT_DIR @@ -67,7 +67,7 @@ RUN apt-get update && \ ln -s `which python3` /usr/bin/python && \ pip3 install --upgrade pip && \ pip install -Iv setuptools==47.1.1 wheel==0.34.2 waitress==1.4.4 && \ - pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.25.0 requests==2.23.0 && \ + pip install -Iv Flask==1.1.2 Flask-JWT-Extended==3.24.1 flask-swagger-ui==3.36.0 requests==2.23.0 && \ pip install -U flask-cors && \ curl ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.zip -L -o /tmp/allure-commandline.zip && \ unzip -q /tmp/allure-commandline.zip -d / && \