2.15. Staging input files#
Normally, input files are located in a read-only directory separate from
the output directory. This causes problems if the underlying tool expects to
write its output files alongside the input file in the same directory. You use InitialWorkDirRequirement
to stage input files into the output directory.
In this example, we use a JavaScript expression to extract the base name of the
input file from its leading directory path.
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
hints:
DockerRequirement:
dockerPull: openjdk:9.0.1-11-slim
baseCommand: javac
requirements:
InitialWorkDirRequirement:
listing:
- $(inputs.src)
inputs:
src:
type: File
inputBinding:
position: 1
valueFrom: $(self.basename)
outputs:
classfile:
type: File
outputBinding:
glob: "*.class"
src:
class: File
path: Hello.java
Now invoke cwltool
with the tool description and the input object on the
command line:
$ cwltool linkfile.cwl arguments-job.yml
INFO /opt/hostedtoolcache/Python/3.9.13/x64/bin/cwltool 3.1.20220913185150
INFO Resolved 'linkfile.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/linkfile.cwl'
INFO ['udocker', 'pull', 'openjdk:9.0.1-11-slim']
Info: downloading layer sha256:8d602e635a7063b254ddcd64997153b2e8f74c29ff4648089ae116a4ca3ea8e3
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:45b0cb5bfff7921055b3160e463c0cbbd0da8804c54c0e81870e32789de17696
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:31aaf5b382af90e713d7581c352ac81060358c641b90a3708b45268486ae3911
Info: downloading layer sha256:5713db526a481e662cb137cca84372e8433d562ce47cab6f445157cd465a6caf
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Info: downloading layer sha256:a8a43101ae4292a3536f04251309008da5dbec2da6fb32802dca83a617d2688e
Info: downloading layer sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
INFO [job linkfile.cwl] /tmp/vfs43j6u$ udocker \
--quiet \
run \
--volume=/tmp/vfs43j6u:/fsUHAN \
--volume=/tmp/yaunqos_:/tmp \
--volume=/home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/Hello.java:/fsUHAN/Hello.java \
--workdir=/fsUHAN \
--rm \
--env=TMPDIR=/tmp \
--env=HOME=/fsUHAN \
openjdk:9.0.1-11-slim \
javac \
Hello.java
INFO [job linkfile.cwl] Max memory used: 20MiB
INFO [job linkfile.cwl] completed success
{
"classfile": {
"location": "file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/Hello.class",
"basename": "Hello.class",
"class": "File",
"checksum": "sha1$fdb876b40ad9ebc7fee873212e02d5940588642e",
"size": 184,
"path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/staging-input-files/Hello.class"
}
}
INFO Final process status is success