Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Table of contents
* [Switching port](#switching-port)
* [Updating seconds to check Allure Results](#updating-seconds-to-check-allure-results)
* [Keep History and Trends](#keep-history-and-trends)
* [Use custom build order value](#use-custom-build-order-value)
* [Override User Container](#override-user-container)
* [Start in DEV Mode](#start-in-dev-mode)
* [Enable TLS](#enable-tls)
Expand Down Expand Up @@ -849,6 +850,21 @@ The `latest` directory contains the report from the last execution. On this case
[![](resources/allure-docker-service-history-latest-and-last-execution.png)](allure-docker-service-history-latest-and-last-execution.png)


#### Use custom build order value
`Available from Allure Docker Service version 2.28.0`

Enable `USE_CUSTOM_BUILD_ORDER` environment variable to work with a custom build order instead of a counter.

Docker Compose example:
```sh
environment:
USE_CUSTOM_BUILD_ORDER: 1
```

This new value is sending as a new param in generate-report api [Action Endpoints](#action-endpoints)

[![](resources/custom_build_order.png)](custom_build_order.png)

#### Override User Container
`Available from Allure Docker Service version 2.13.1`

Expand Down
57 changes: 56 additions & 1 deletion allure-docker-api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __str__(self):
URL_SCHEME = 'http'
URL_PREFIX = ''
OPTIMIZE_STORAGE = 0
USE_CUSTOM_BUILD_ORDER = False
ENABLE_SECURITY_LOGIN = False
MAKE_VIEWER_ENDPOINTS_PUBLIC = False
SECURITY_USER = None
Expand Down Expand Up @@ -224,6 +225,15 @@ def __str__(self):
except Exception as ex:
LOGGER.error('Wrong env var value. Setting OPTIMIZE_STORAGE=0 by default')

if "USE_CUSTOM_BUILD_ORDER" in os.environ:
try:
USE_CUSTOM_BUILD_ORDER_TMP = int(os.environ['USE_CUSTOM_BUILD_ORDER'])
if USE_CUSTOM_BUILD_ORDER_TMP == 1:
USE_CUSTOM_BUILD_ORDER = True
LOGGER.info('Overriding USE_CUSTOM_BUILD_ORDER=%s', USE_CUSTOM_BUILD_ORDER_TMP)
except Exception as ex:
LOGGER.error('Wrong env var value. Setting USE_CUSTOM_BUILD_ORDER=0 by default')

if "MAKE_VIEWER_ENDPOINTS_PUBLIC" in os.environ:
try:
VIEWER_ENDPOINTS_PUBLIC_TMP = int(os.environ['MAKE_VIEWER_ENDPOINTS_PUBLIC'])
Expand Down Expand Up @@ -421,6 +431,20 @@ def generate_security_swagger_spec():
except Exception as ex:
LOGGER.error(str(ex))

def add_build_order_swagger_param():
try:
build_order_path = "{}/swagger/{}".format(STATIC_CONTENT, 'custom_build_order.json')
build_order = eval(get_file_as_string(build_order_path))
with open("{}/swagger/swagger.json".format(STATIC_CONTENT)) as json_file:
data = json.load(json_file)
params = data['paths']['/generate-report']['get']['parameters']
params.append(build_order)
data['paths']['/generate-report']['get']['parameters'] = params
with open("{}/swagger/swagger.json".format(STATIC_CONTENT), 'w') as outfile:
json.dump(data, outfile)
except Exception as ex:
LOGGER.error(str(ex))

### swagger specific ###
NATIVE_PREFIX = '/allure-docker-service'
SWAGGER_ENDPOINT = '/swagger'
Expand Down Expand Up @@ -449,6 +473,9 @@ def generate_security_swagger_spec():
url_prefix='{}{}'.format(NATIVE_PREFIX, SWAGGER_ENDPOINT))
### end swagger specific ###

if USE_CUSTOM_BUILD_ORDER:
add_build_order_swagger_param()

### Security Section
if ENABLE_SECURITY_LOGIN:
generate_security_swagger_spec()
Expand Down Expand Up @@ -983,6 +1010,12 @@ def generate_report_endpoint():
execution_type = request.args.get('execution_type')
if execution_type is None or not execution_type:
execution_type = ''

if USE_CUSTOM_BUILD_ORDER is True:
custom_build_order_arg = request.args.get('custom_build_order')
custom_build_order = is_valid_build_order(project_id, custom_build_order_arg)
else:
custom_build_order=''

check_process(KEEP_HISTORY_PROCESS, project_id)
check_process(GENERATE_REPORT_PROCESS, project_id)
Expand All @@ -992,7 +1025,7 @@ def generate_report_endpoint():
call([KEEP_HISTORY_PROCESS, project_id, ORIGIN])
response = subprocess.Popen([
GENERATE_REPORT_PROCESS, exec_store_results_process,
project_id, ORIGIN, execution_name, execution_from, execution_type],
project_id, ORIGIN, execution_name, execution_from, execution_type, custom_build_order],
stdout=subprocess.PIPE).communicate()[0]
call([RENDER_EMAIL_REPORT_PROCESS, project_id, ORIGIN])

Expand Down Expand Up @@ -1635,6 +1668,28 @@ def resolve_project(project_id_param):
project_id = project_id_param
return project_id

def get_build_order_path(project_id, build_order):
project_path=get_project_path(project_id)
return '{}/reports/{}'.format(project_path, build_order)

def is_existent_build_order(project_id, build_order):
if not build_order.strip():
return False
return os.path.isdir(get_build_order_path(project_id, build_order))

def is_valid_build_order(project_id, build_order):
if build_order is None or not build_order:
raise Exception("custom_build_order is a required parameter")

if is_existent_build_order(project_id, build_order) is True:
raise Exception("custom_build_order '{}' exist".format(build_order))

build_order_pattern = re.compile('^[0-9\\d .]*[0-9\\d]$')
match = build_order_pattern.match(build_order)
if match is None:
raise Exception("custom_build_order should contains numeric characters or dots. For example: '1.0.0'") #pylint: disable=line-too-long
return build_order

def check_admin_access(user):
if ENABLE_SECURITY_LOGIN is False:
return True
Expand Down
7 changes: 7 additions & 0 deletions allure-docker-api/static/swagger/custom_build_order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"in": "query",
"name": "custom_build_order",
"schema": {
"type": "string"
}
}
2 changes: 1 addition & 1 deletion allure-docker-scripts/cleanAllureHistory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$(ls -A $PROJECT_LATEST_REPORT | wc -l)" != "0" ]; then
fi

if [ "$(ls -A $PROJECT_REPORTS_DIRECTORY | wc -l)" != "0" ]; then
ls -d $PROJECT_REPORTS_DIRECTORY/* | grep -wv $PROJECT_REPORTS_DIRECTORY/latest | grep -wv 0 | xargs rm 2 -rf> /dev/null
ls -d $PROJECT_REPORTS_DIRECTORY/* | grep -wv $PROJECT_REPORTS_DIRECTORY/latest | grep -wv $PROJECT_REPORTS_DIRECTORY/0 | xargs rm 2 -rf> /dev/null
fi

if [ -e $PROJECT_RESULTS_HISTORY ]; then
Expand Down
9 changes: 6 additions & 3 deletions allure-docker-scripts/generateAllureReport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ORIGIN=$3
EXECUTION_NAME=$4
EXECUTION_FROM=$5
EXECUTION_TYPE=$6
BUILD_ORDER=$7

PROJECT_REPORTS=$STATIC_CONTENT_PROJECTS/$PROJECT_ID/reports
if [ "$(ls $PROJECT_REPORTS | wc -l)" != "0" ]; then
Expand All @@ -31,8 +32,10 @@ EXECUTOR_PATH=$RESULTS_DIRECTORY/$EXECUTOR_FILENAME

echo "Creating $EXECUTOR_FILENAME for PROJECT_ID: $PROJECT_ID"
if [[ "$LAST_REPORT_DIRECTORY" != "latest" ]]; then
BUILD_ORDER=$(($LAST_REPORT_DIRECTORY + 1))

if [ -z "$BUILD_ORDER" ]; then
BUILD_ORDER=$(($LAST_REPORT_DIRECTORY + 1))
fi

if [ -z "$EXECUTION_NAME" ]; then
EXECUTION_NAME='Automatic Execution'
fi
Expand All @@ -45,7 +48,7 @@ EXECUTOR_JSON=$(cat <<EOF
{
"reportName": "$PROJECT_ID",
"buildName": "$PROJECT_ID #$BUILD_ORDER",
"buildOrder": "$BUILD_ORDER",
"buildOrder": "${BUILD_ORDER//.}",
"name": "$EXECUTION_NAME",
"reportUrl": "../$BUILD_ORDER/index.html",
"buildUrl": "$EXECUTION_FROM",
Expand Down
4 changes: 2 additions & 2 deletions allure-docker-scripts/keepAllureLatestHistory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ if [ "$KEEP_HISTORY" == "TRUE" ] || [ "$KEEP_HISTORY" == "true" ] || [ "$KEEP_HI
if echo $KEEP_HISTORY_LATEST | egrep -q '^[0-9]+$'; then
KEEP_LATEST=$KEEP_HISTORY_LATEST
fi
CURRENT_SIZE=$(ls -Ad $PROJECT_REPORTS_DIRECTORY/* | grep -wv $PROJECT_REPORTS_DIRECTORY/latest | grep -wv 0 | grep -v $EMAILABLE_REPORT_FILE_NAME | wc -l)
CURRENT_SIZE=$(ls -Ad $PROJECT_REPORTS_DIRECTORY/* | grep -wv $PROJECT_REPORTS_DIRECTORY/latest | grep -v $EMAILABLE_REPORT_FILE_NAME | wc -l)

if [ "$CURRENT_SIZE" -gt "$KEEP_LATEST" ]; then
SIZE_TO_REMOVE="$(($CURRENT_SIZE-$KEEP_LATEST))"
echo "Keeping latest $KEEP_LATEST history reports for PROJECT_ID: $PROJECT_ID"
ls -tAd $PROJECT_REPORTS_DIRECTORY/* | grep -wv $PROJECT_REPORTS_DIRECTORY/latest | grep -wv 0 | grep -v $EMAILABLE_REPORT_FILE_NAME | tail -$SIZE_TO_REMOVE | xargs rm 2 -rf> /dev/null
ls -tAd $PROJECT_REPORTS_DIRECTORY/* | grep -wv $PROJECT_REPORTS_DIRECTORY/latest | grep -v $EMAILABLE_REPORT_FILE_NAME | tail -$SIZE_TO_REMOVE | xargs rm 2 -rf> /dev/null
fi
fi
Binary file added resources/custom_build_order.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.