1
0
mirror of https://github.com/kochetkov-ma/allure-server.git synced 2024-11-24 08:22:37 +02:00

added 'allure.report.url.base' setting to redefine server base url for reports

This commit is contained in:
kochetkov-ma 2020-07-19 16:29:50 +03:00
parent 19325cb701
commit 888f9c0eb6
6 changed files with 40 additions and 9 deletions

View File

@ -119,6 +119,10 @@ Spring Configutaion:
| allure.support.old.format | boolean | false | Auto-convert old format reports to new and add to db |
| JAVA_OPTS | string | -Xms256m -Xmx2048m | Java memory options for container |
| allure.date.format | string | yy/MM/dd HH:mm:ss | Date Time format in grid |
| allure.report.url.base | string | | Define custom base url for results. If your server behind the proxy or other troubles to get server external hostname. Don't forget about '/' at the end |
Every spring boot setting can be passed through ENV variables with a little changes according to [spring boot cfg docs](https://docs.spring.io/spring-boot/docs/1.5.5.RELEASE/reference/html/boot-features-external-config.html)
For example: `allure.report.host` transform to `ALLURE_REPORT_HOST`
### GUI
##### See example on [allure.iopump.ru](http://allure.iopump.ru/) or [allure-server.herokuapp.com](https://allure-server.herokuapp.com/)

View File

@ -2,7 +2,10 @@ version: '3.7'
services:
allure-server:
container_name: allure-server
# build: . # Local debug
image: kochetkovma/allure-server:latest
# environment: # Local debug
# ALLURE_REPORT_URL_BASE: http://test.ru/ # Local debug
ports:
- 8080:8080
volumes:

View File

@ -29,4 +29,6 @@ public class AppCfg {
boolean supportOldFormat;
@Value("${allure.date.format}")
String dateFormat;
@Value("${allure.report.url.base:}")
String reportHost;
}

View File

@ -1,5 +1,7 @@
package ru.iopump.qa.allure.controller;
import static ru.iopump.qa.allure.helper.Util.url;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.Collection;
@ -22,7 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import ru.iopump.qa.allure.AppCfg;
import ru.iopump.qa.allure.entity.ReportEntity;
import ru.iopump.qa.allure.model.ReportGenerateRequest;
import ru.iopump.qa.allure.model.ReportResponse;
@ -40,9 +42,10 @@ public class AllureReportController {
final static String CACHE = "reports";
private final JpaReportService reportService;
private final ResultService resultService;
private final AppCfg appCfg;
public String baseUrl() {
return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString() + "/";
return url(appCfg);
}
@Operation(summary = "Get generated allure reports")

View File

@ -4,6 +4,7 @@ import static ru.iopump.qa.allure.gui.MainLayout.ALLURE_SERVER;
import static ru.iopump.qa.allure.gui.component.Col.Type.LINK;
import static ru.iopump.qa.allure.gui.component.Col.Type.NUMBER;
import static ru.iopump.qa.allure.gui.component.Col.prop;
import static ru.iopump.qa.allure.helper.Util.url;
import com.google.common.collect.ImmutableList;
import com.vaadin.flow.component.Tag;
@ -22,7 +23,7 @@ import java.util.List;
import java.util.UUID;
import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import ru.iopump.qa.allure.AppCfg;
import ru.iopump.qa.allure.entity.ReportEntity;
import ru.iopump.qa.allure.gui.DateTimeResolver;
import ru.iopump.qa.allure.gui.MainLayout;
@ -37,13 +38,17 @@ import ru.iopump.qa.allure.service.JpaReportService;
public class ReportsView extends VerticalLayout {
private static final long serialVersionUID = 5822017036734476962L;
private final DateTimeResolver dateTimeResolver;
private final AppCfg appCfg;
/* COMPONENTS */
private final FilteredGrid<ReportEntity> reports;
private final Button deleteSelection;
public ReportsView(final JpaReportService jpaReportService, final DateTimeResolver dateTimeResolver) {
public ReportsView(final JpaReportService jpaReportService,
final DateTimeResolver dateTimeResolver,
final AppCfg appCfg) {
this.dateTimeResolver = dateTimeResolver;
this.appCfg = appCfg;
this.dateTimeResolver.retrieve();
this.reports = new FilteredGrid<>(
@ -83,7 +88,7 @@ public class ReportsView extends VerticalLayout {
.value(e -> dateTimeResolver.printDate(e.getCreatedDateTime()))
.build()
)
.add(Col.<ReportEntity>with().name("Url").value(e -> e.generateUrl(baseUrl())).type(LINK).build())
.add(Col.<ReportEntity>with().name("Url").value(e -> e.generateUrl(url(appCfg))).type(LINK).build())
.add(Col.<ReportEntity>with().name("Path").value(prop("path")).build())
.add(Col.<ReportEntity>with().name("Active").value(prop("active")).build())
.add(Col.<ReportEntity>with().name("Size KB").value(prop("size")).type(NUMBER).build())
@ -105,8 +110,4 @@ public class ReportsView extends VerticalLayout {
add(deleteSelection);
reports.addTo(this);
}
public String baseUrl() {
return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString() + "/";
}
}

View File

@ -0,0 +1,18 @@
package ru.iopump.qa.allure.helper;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import ru.iopump.qa.allure.AppCfg;
@SuppressWarnings("RedundantModifiersUtilityClassLombok")
@UtilityClass
public class Util {
public static String url(AppCfg appCfg) {
if (StringUtils.isBlank(appCfg.reportHost())) {
return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString() + "/";
} else {
return appCfg.reportHost();
}
}
}