31
31
import org .slf4j .Logger ;
32
32
import org .slf4j .LoggerFactory ;
33
33
34
- import java .io .IOException ;
35
- import java .io .UncheckedIOException ;
34
+ import java .io .*;
36
35
import java .net .URL ;
37
36
import java .nio .file .Files ;
38
37
import java .nio .file .Path ;
38
+ import java .nio .file .Paths ;
39
39
import java .text .ParseException ;
40
40
import java .text .SimpleDateFormat ;
41
41
import java .util .*;
@@ -197,7 +197,7 @@ protected void run() throws Exception {
197
197
Path nextflowConfigPath ;
198
198
if (nextflowConfig != null ) {
199
199
nextflowConfigPath = temporalInputDir .resolve ("nextflow.config" );
200
- Files . copy (nextflowConfig .openStream () , nextflowConfigPath );
200
+ writeNextflowConfigFile ( Paths . get (nextflowConfig .toURI ()) , nextflowConfigPath , outDirPath );
201
201
dockerInputBindings .add (new AbstractMap .SimpleEntry <>(nextflowConfigPath .toString (), nextflowConfigPath .toString ()));
202
202
} else {
203
203
throw new RuntimeException ("Can't fetch nextflow.config file" );
@@ -236,8 +236,8 @@ protected void run() throws Exception {
236
236
// when nextflow runs on other dockers, we need to store those files in a path shared between the parent docker and the host
237
237
dockerParams .put ("-e" , "HOME=" + temporalInputDir );
238
238
dockerParams .put ("-e" , "OPENCGA_TOKEN=" + getExpiringToken ());
239
- // Disable user param
240
- dockerParams .put ("user" , "" );
239
+ // Set user uid and guid to 1001
240
+ dockerParams .put ("user" , "1001:1001 " );
241
241
242
242
// Execute docker image
243
243
StopWatch stopWatch = StopWatch .createStarted ();
@@ -257,6 +257,22 @@ protected void close() {
257
257
deleteTemporalFiles ();
258
258
}
259
259
260
+ private void writeNextflowConfigFile (Path inputFile , Path outputFile , String outdirPath ) {
261
+ try (BufferedReader reader = Files .newBufferedReader (inputFile );
262
+ BufferedWriter writer = Files .newBufferedWriter (outputFile )) {
263
+
264
+ String line ;
265
+ while ((line = reader .readLine ()) != null ) {
266
+ // Replace occurrences of "$OUTPUT" with the replacement string
267
+ line = line .replace ("$OUTPUT" , outdirPath );
268
+ writer .write (line );
269
+ writer .newLine ();
270
+ }
271
+ } catch (IOException e ) {
272
+ throw new RuntimeException (e );
273
+ }
274
+ }
275
+
260
276
private void deleteTemporalFiles () {
261
277
// Delete temporal files and folders created by nextflow
262
278
try (Stream <Path > paths = Files .walk (getOutDir ().resolve (".nextflow" ))) {
0 commit comments