Skip to content

Commit 13a031e

Browse files
committed
During initialization, avoid creating files in an empty (unused) data directory.
This is important for Docker etc, where the directory will already exist but be empty, and the location configured externally.
1 parent 5625d31 commit 13a031e

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

package/docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM tomcat:8.5-jdk8
2-
LABEL MAINTAINERS="Markus Döring <[email protected]>, Matthew Blissett <[email protected]>"
2+
LABEL MAINTAINERS="Matthew Blissett <[email protected]>"
33

44
ARG IPT_VERSION
55
ARG IPT_NAME=ROOT

package/docker/README.adoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ We regularly publish IPT releases as Docker images to https://hub.docker.com/r/g
88

99
== To run the Docker image
1010

11-
Refer to https://ipt.gbif.org/manual/en/ipt/2.5/installation/#_installation_using_docker[Installation using Docker] in the IPT User Manual.
11+
Refer to https://ipt.gbif.org/manual/en/ipt/2.5/installation#installation-using-docker[Installation using Docker] in the IPT User Manual.
1212

1313
== Upgrading
1414

@@ -18,10 +18,10 @@ Note that, for better consistency with the https://en.wikipedia.org/wiki/Filesys
1818

1919
(This process is for GBIF developers.)
2020

21-
. `docker build --pull --build-arg IPT_VERSION=2.4.2 -t gbif/ipt:2.4.2 .`
21+
. `docker build --pull --build-arg IPT_VERSION=2.5.0 -t gbif/ipt:2.5.0 .`
2222
. *Test the resulting image!*
2323
+
24-
`docker run --volume /full/path/to/data-directory:/srv/ipt --publish 8080:8080 gbif/ipt:2.4.2`
24+
`docker run --volume /full/path/to/data-directory:/srv/ipt --publish 8080:8080 gbif/ipt:2.5.0`
2525

26-
. `docker push gbif/ipt:2.4.2` (stop here for a pre-release)
27-
. `docker tag gbif/ipt:2.4.2 gbif/ipt:latest && docker push gbif/ipt:latest`
26+
. `docker push gbif/ipt:2.5.0` (stop here for a pre-release)
27+
. `docker tag gbif/ipt:2.5.0 gbif/ipt:latest && docker push gbif/ipt:latest`

src/main/java/org/gbif/ipt/config/AppConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ protected void loadConfig() throws InvalidConfigException {
371371
props.load(configStream);
372372
LOG.debug("Loaded default configuration from application.properties in classpath");
373373
}
374-
if (dataDir.dataDir != null && dataDir.dataDir.exists()) {
374+
if (dataDir.isConfigured()) {
375375
// load user configuration properties from data dir ipt.properties (if it exists)
376376
File userCfgFile = new File(dataDir.dataDir, "config/" + DATADIR_PROPFILE);
377377
if (userCfgFile.exists()) {

src/main/java/org/gbif/ipt/config/DataDir.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,14 @@ public File dataFile(String path) {
164164
* @return true if a working data directory is configured
165165
*/
166166
public boolean isConfigured() {
167-
return dataDir != null && dataDir.exists();
167+
return dataDir != null && dataDir.isDirectory() && dataDir.list().length > 0;
168+
}
169+
170+
/**
171+
* @return true if a working data directory is configured, but is not yet set up
172+
*/
173+
public boolean isConfiguredButEmpty() {
174+
return dataDir != null && dataDir.isDirectory() && dataDir.list().length == 0;
168175
}
169176

170177
/**
@@ -327,7 +334,7 @@ public boolean setDataDir(File dataDir) throws InvalidConfigException {
327334
throw new InvalidConfigException(TYPE.INVALID_DATA_DIR,
328335
"DataDir " + dataDir.getAbsolutePath() + " exists already and is no IPT data dir.");
329336
}
330-
LOG.info("Reusing existing data dir.");
337+
LOG.info("Reusing existing data dir {}", dataDir);
331338
// persist location in WEB-INF
332339
try {
333340
persistLocation();
@@ -343,6 +350,7 @@ public boolean setDataDir(File dataDir) throws InvalidConfigException {
343350

344351
} else {
345352
// NEW datadir
353+
LOG.info("Setting up new data directory {}", dataDir);
346354
try {
347355
// create new main data dir. Populate later
348356
FileUtils.forceMkdir(dataDir);

src/main/java/org/gbif/ipt/config/SetupAction.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,19 @@ public void setSetup2(boolean setup2) {
174174
*/
175175
public String setup() {
176176
if (isHttpPost() && dataDirPath != null) {
177-
178177
// since IPT v2.2, user must check that they have read and understood disclaimer
179178
if (!readDisclaimer) {
180179
addFieldError("readDisclaimer", getText("admin.config.setup.read.error"));
181180
return INPUT;
182181
}
182+
}
183+
184+
if ((dataDir.dataDir != null && (!dataDir.dataDir.exists() || dataDir.isConfiguredButEmpty())) ||
185+
isHttpPost() && dataDirPath != null) {
183186

184-
File dd = new File(dataDirPath.trim());
187+
LOG.info("Set up data directory {}", dataDir);
188+
189+
File dd = dataDirPath != null ? new File(dataDirPath.trim()) : dataDir.dataDir;
185190
try {
186191
if (dd.isAbsolute()) {
187192
boolean created = configManager.setDataDir(dd);
@@ -206,8 +211,10 @@ public String setup() {
206211
addActionError(msg);
207212
}
208213
}
214+
209215
if (dataDir.isConfigured()) {
210216
// the data dir is already/now configured, skip the first setup step
217+
LOG.info("Skipping setup step 1");
211218
return SUCCESS;
212219
}
213220
return INPUT;

0 commit comments

Comments
 (0)