Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount workdir in docker container for awsbatch #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class AwsBatchTaskHandler extends TaskHandler implements BatchHandler<String,Job
cliPath: executor.getSession().getExecConfigProp(name,'awscli',null) as String,
storageClass: executor.getSession().config.navigate('aws.client.uploadStorageClass') as String,
storageEncryption: executor.getSession().config.navigate('aws.client.storageEncryption') as String,
mountPoint: executor.getSession().config.navigate('aws.mountPoint', '/tmp') as String,
remoteBinDir: executor.remoteBinDir as String,
region: executor.getSession().config.navigate('aws.region') as String
)
Expand Down Expand Up @@ -376,29 +377,49 @@ class AwsBatchTaskHandler extends TaskHandler implements BatchHandler<String,Job
result.setJobDefinitionName(name)
result.setType(JobDefinitionType.Container)

def mountPointPath = getAwsOptions().mountPoint

// container definition
def container = new ContainerProperties()
.withImage(image)
// note the actual command, memory and cpus are overridden when the job is executed
.withCommand('true')
.withMemory(1024)
.withVcpus(1)

def awscli = getAwsOptions().cliPath
def mounts = new LinkedList<MountPoint>()
def volumes = new LinkedList<Volume>()
def mountPointName = 'mount'
def mountWorkDir = new MountPoint()
.withSourceVolume(mountPointName)
.withContainerPath(mountPointPath)
.withReadOnly(false)
mounts.add(mountWorkDir)
def volumeWorkDir = new Volume()
.withName(mountPointName)
.withHost(new Host()
.withSourcePath(mountPointPath))
volumes.add(volumeWorkDir)

if( awscli ) {
def mountName = 'aws-cli'
def path = Paths.get(awscli).parent.parent.toString()
def mount = new MountPoint()
.withSourceVolume(mountName)
.withContainerPath(path)
.withReadOnly(true)
container.setMountPoints([mount])
mounts.add(mount)

def vol = new Volume()
.withName(mountName)
.withHost(new Host()
.withSourcePath(path))
container.setVolumes([vol])
volumes.add(vol)
}
container.setMountPoints(mounts)
container.setVolumes(volumes)

result.setContainerProperties(container)

// create a job marker uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class AwsOptions {

String region

String mountPoint

AwsOptions() { }

AwsOptions(Session session) {
Expand Down Expand Up @@ -78,6 +80,15 @@ class AwsOptions {
}
}

void setMountPath(String value) {
if( !value )
this.mountPoint = '/tmp'
else {
if (!value.startsWith('/')) throw new ProcessUnrecoverableException("Not a valid mount path: $value -- it must be an absolute path")
this.mountPoint = value
}
}

String getAwsCli() {
def result = getCliPath()
if( !result ) result = 'aws'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +457,35 @@ class AwsBatchTaskHandlerTest extends Specification {
def result = handler.makeJobDefRequest(IMAGE)
then:
1 * handler.normalizeJobDefinitionName(IMAGE) >> JOB_NAME
1 * handler.getAwsOptions() >> new AwsOptions()
2 * handler.getAwsOptions() >> new AwsOptions()
result.jobDefinitionName == JOB_NAME
result.type == 'container'
result.parameters.'nf-token' == 'fdb5ef295f566138a43252b2ea272282'
!result.containerProperties.mountPoints
result.containerProperties.mountPoints[0].sourceVolume == 'mount'
!result.containerProperties.mountPoints[0].readOnly

when:
result = handler.makeJobDefRequest(IMAGE)
then:
1 * handler.normalizeJobDefinitionName(IMAGE) >> JOB_NAME
1 * handler.getAwsOptions() >> new AwsOptions(cliPath: '/home/conda/bin/aws')
2 * handler.getAwsOptions() >> new AwsOptions(cliPath: '/home/conda/bin/aws', mountPoint: '/tmp')
result.jobDefinitionName == JOB_NAME
result.type == 'container'
result.parameters.'nf-token' == '9c56fd073d32e0c29f51f12afdfe4750'
result.containerProperties.mountPoints[0].sourceVolume == 'aws-cli'
result.containerProperties.mountPoints[0].containerPath == '/home/conda'
result.containerProperties.mountPoints[0].readOnly
result.containerProperties.volumes[0].host.sourcePath == '/home/conda'
result.containerProperties.volumes[0].name == 'aws-cli'
result.containerProperties.mountPoints[0].sourceVolume == 'mount'
result.containerProperties.mountPoints[0].containerPath == '/tmp'
!result.containerProperties.mountPoints[0].readOnly
result.containerProperties.volumes[0].host.sourcePath == '/tmp'
result.containerProperties.volumes[0].name == 'mount'

result.containerProperties.mountPoints[1].sourceVolume == 'aws-cli'
result.containerProperties.mountPoints[1].containerPath == '/home/conda'
result.containerProperties.mountPoints[1].readOnly
result.containerProperties.volumes[1].host.sourcePath == '/home/conda'
result.containerProperties.volumes[1].name == 'aws-cli'

result.containerProperties.environment[0].name == "TMPDIR"
result.containerProperties.environment[0].value == "/tmp"

}

Expand Down