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
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,29 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*
# Run necessary 'ant' deploy scripts
RUN ant init_installation update_configs update_code update_webapps
# A new named volume takes the owner of the folder it is mounted on, so create the volume folders ant does not create.
RUN mkdir -p /dspace/assetstore /dspace/sitemaps

# Step 3 - Start up DSpace via Runnable JAR
FROM docker.io/eclipse-temurin:${JDK_VERSION}
# Below syntax may look odd, but it is how to override dspace.cfg settings via env variables.
# See https://github.com/DSpace/DSpace/blob/main/dspace/config/config-definition.xml
# "dspace__P__dir" is setting the value of the "dspace.dir" configuration. This is our installation directory.
ENV dspace__P__dir=/dspace
# Run DSpace as 'dspace', not root. UID 1100 is the same as in the 7.x image.
RUN useradd -u 1100 -m -s /bin/bash dspace
# Copy the /dspace directory from 'ant_build' container to /dspace in this container
COPY --from=ant_build /dspace $dspace__P__dir
COPY --chown=dspace:dspace --from=ant_build /dspace $dspace__P__dir
WORKDIR $dspace__P__dir
# Need host command for "[dspace]/bin/make-handle-config"
RUN apt-get update \
&& apt-get install -y --no-install-recommends host \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*
# Expose Tomcat port (8080) & Handle Server HTTP port (8000)
EXPOSE 8080 8000
# Expose Tomcat port (8080) & Handle Server HTTP port (8010)
EXPOSE 8080 8010
# Give java extra memory (2GB)
ENV JAVA_OPTS=-Xmx2000m
USER dspace
# On startup, run DSpace Runnable JAR (uses the "dspace.dir" setting defined in "dspace__P__dir" env variable)
ENTRYPOINT ["java", "-jar", "webapps/server-boot.jar"]
7 changes: 6 additions & 1 deletion Dockerfile.cli
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*
# Run necessary 'ant' deploy scripts
RUN ant init_installation update_configs update_code
# A new named volume takes the owner of the folder it is mounted on, so create the assetstore folder.
RUN mkdir -p /dspace/assetstore

# Step 3 - Run jdk
FROM docker.io/eclipse-temurin:${JDK_VERSION}
# Below syntax may look odd, but it is how to override dspace.cfg settings via env variables.
# See https://github.com/DSpace/DSpace/blob/main/dspace/config/config-definition.xml
# "dspace__P__dir" is setting the value of the "dspace.dir" configuration. This is our installation directory.
ENV dspace__P__dir=/dspace
# Run DSpace as 'dspace', not root. UID 1100 is the same as in the backend image.
RUN useradd -u 1100 -m -s /bin/bash dspace
# Copy the /dspace directory from 'ant_build' container to /dspace in this container
COPY --from=ant_build /dspace $dspace__P__dir
COPY --chown=dspace:dspace --from=ant_build /dspace $dspace__P__dir
WORKDIR $dspace__P__dir
# Give java extra memory (1GB)
ENV JAVA_OPTS=-Xmx1000m
Expand All @@ -59,6 +63,7 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends unzip \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*
USER dspace

# On startup, run DSpace commandline script
ENTRYPOINT ["./bin/dspace"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.sql.SQLException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -1083,13 +1085,17 @@ public static LocalDate parseDate(String date) {


/**
* Take the date object and convert it into a string of the form YYYY-MM-DD
* Take the date object and convert it into an Instant datetime object of the form YYYY-MM-DDTHH:MM:SSZ
*
* @param date the date to be converted
* @return A string of the form YYYY-MM-DD
* @return An Instant datetime object of the form YYYY-MM-DDTHH:MM:SSZ
*/
public static String unParseDate(LocalDate date) {
return DateTimeFormatter.ISO_LOCAL_DATE.format(date);
public static Instant convertDate(LocalDate date, boolean startOfDay) {
if (startOfDay) {
return date.atStartOfDay(ZoneId.systemDefault()).toInstant();
} else {
return date.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()).toInstant();
}
}


Expand Down Expand Up @@ -1219,13 +1225,13 @@ public static Integer getNumItems(Context context, String type)
StringBuilder accessionedQuery = new StringBuilder();
accessionedQuery.append("dc.date.accessioned_dt:[");
if (startDate != null) {
accessionedQuery.append(unParseDate(startDate));
accessionedQuery.append(convertDate(startDate, true));
} else {
accessionedQuery.append("*");
}
accessionedQuery.append(" TO ");
if (endDate != null) {
accessionedQuery.append(unParseDate(endDate));
accessionedQuery.append(convertDate(endDate, false));
} else {
accessionedQuery.append("*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
*/
package org.dspace.app.rest.health;

import static org.dspace.app.rest.configuration.ActuatorConfiguration.UP_WITH_ISSUES_STATUS;

import java.net.URI;

import org.apache.commons.lang3.StringUtils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.web.client.RestTemplate;
Expand All @@ -22,44 +26,63 @@
*/
public class SEOHealthIndicator extends AbstractHealthIndicator {

ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
public static final String SITEMAP = "sitemap";
public static final String ROBOTS_TXT = "robots.txt";
public static final String SSR = "ssr";
public static final String OK = "OK";
public static final String SITEMAP_MISSING = "Sitemaps are missing or inaccessible. Please see the " +
"DSpace Documentation on Search Engine Optimization for how to enable " +
"Sitemaps.";
public static final String ROBOTS_MISSING = "Missing or inaccessible. Please see the DSpace Documentation on " +
"Search Engine Optimization for how to create a robots.txt.";
public static final String ROBOTS_INVALID = "Invalid because it contains localhost URLs. This is often a sign " +
"that a proxy is failing to pass X-Forwarded headers to DSpace. Please see the DSpace " +
"Documentation on Search Engine Optimization for how to pass X-Forwarded headers.";
public static final String SSR_DISABLED = "Server-side rendering (SSR) appears to be disabled. Most " +
"search engines require enabling SSR for proper indexing. Please see the DSpace Documentation on" +
" Search Engine Optimization for more details.";

@Autowired
private ConfigurationService configurationService;

private final RestTemplate restTemplate = new RestTemplate();
private RestTemplate restTemplate = new RestTemplate();

@Override
protected void doHealthCheck(Health.Builder builder) {
String baseUrl = configurationService.getProperty("dspace.ui.url");

boolean sitemapOk = checkUrl(baseUrl + "/sitemap_index.xml") || checkUrl(baseUrl + "/sitemap_index.html");
RobotsTxtStatus robotsTxtStatus = checkRobotsTxt(baseUrl + "/robots.txt");
RobotsTxtStatus robotsTxtStatus = checkRobotsTxt(baseUrl);
boolean ssrOk = checkSSR(baseUrl);

if (sitemapOk && robotsTxtStatus == RobotsTxtStatus.VALID && ssrOk) {
builder.up()
.withDetail("sitemap", "OK")
.withDetail("robots.txt", "OK")
.withDetail("ssr", "OK");
.withDetail(SITEMAP, OK)
.withDetail(ROBOTS_TXT, OK)
.withDetail(SSR, OK);
} else {
builder.down();
builder.withDetail("sitemap", sitemapOk ? "OK" : "Sitemaps are missing or inaccessible. Please see the " +
"DSpace Documentation on Search Engine Optimization for how to enable Sitemaps.");
builder.status(UP_WITH_ISSUES_STATUS)
.withDetail(SITEMAP, sitemapOk ? OK : SITEMAP_MISSING);

if (robotsTxtStatus == RobotsTxtStatus.MISSING) {
builder.withDetail("robots.txt", "Missing or inaccessible. Please see the DSpace Documentation on " +
"Search Engine Optimization for how to create a robots.txt.");
builder.withDetail(ROBOTS_TXT, ROBOTS_MISSING);
} else if (robotsTxtStatus == RobotsTxtStatus.INVALID) {
builder.withDetail("robots.txt", "Invalid because it contains localhost URLs. This is often a sign " +
"that a proxy is failing to pass X-Forwarded headers to DSpace. Please see the DSpace " +
"Documentation on Search Engine Optimization for how to pass X-Forwarded headers.");
builder.withDetail(ROBOTS_TXT, ROBOTS_INVALID);
} else {
builder.withDetail("robots.txt", "OK");
builder.withDetail(ROBOTS_TXT, OK);
}
builder.withDetail("ssr", ssrOk ? "OK" : "Server-side rendering (SSR) appears to be disabled. Most " +
"search engines require enabling SSR for proper indexing. Please see the DSpace Documentation on" +
" Search Engine Optimization for more details.");
builder.withDetail(SSR, ssrOk ? OK : SSR_DISABLED);
}
}

/**
* Crawlers read robots.txt only from the root of the site, also when the UI runs under a path like /repository.
*/
private String getSiteRoot(String url) {
URI uri = URI.create(url);
return uri.getScheme() + "://" + uri.getRawAuthority();
}

private boolean checkUrl(String url) {
try {
restTemplate.getForEntity(url, String.class);
Expand All @@ -69,10 +92,11 @@ private boolean checkUrl(String url) {
}
}

private RobotsTxtStatus checkRobotsTxt(String url) {
private RobotsTxtStatus checkRobotsTxt(String baseUrl) {
try {
String content = restTemplate.getForObject(url, String.class);
if (StringUtils.isBlank(content)) {
String content = restTemplate.getForObject(getSiteRoot(baseUrl) + "/robots.txt", String.class);
// An HTML page here comes from a catch-all route of the site, not from a real robots.txt.
if (StringUtils.isBlank(content) || content.stripLeading().startsWith("<")) {
return RobotsTxtStatus.MISSING;
}
if (content.contains("localhost")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,15 @@ public void testWithAdminUser() throws Exception {
)));

}

@Test
public void testLdapIndicatorIsOff() throws Exception {

String token = getAuthToken(admin.getEmail(), password);

getClient(token).perform(get(HEALTH_PATH))
.andExpect(status().isOk())
.andExpect(jsonPath("$.components.ldap").doesNotExist());

}
}
Loading
Loading