Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit b97f447

Browse files
authored
Feature: Add Batch Service Built-In Container support (#291)
* Replaced Virtual Configuration * Added containerSettings in addTask helper function * Using new Dockerfile with blobxfer and R * Removed container settings * Fixed containerConfiguration lintr * Fixed description dependency * Fixed cluster setting * Fixed R packages installation on pool level
1 parent ce263e7 commit b97f447

File tree

5 files changed

+42
-46
lines changed

5 files changed

+42
-46
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ Suggests:
2828
plyr,
2929
lintr
3030
Remotes:
31-
Azure/rAzureBatch@v0.6.1
31+
Azure/rAzureBatch@v0.6.2
3232
RoxygenNote: 6.0.1

R/batch-api.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ BatchUtilities <- R6::R6Class(
1717
userOutputFiles <- args$outputFiles
1818
containerImage <- args$containerImage
1919

20-
resultFile <- paste0(taskId, "-result", ".rds")
2120
accountName <- storageClient$authentication$name
2221

2322
resourceFiles <- NULL
@@ -46,8 +45,15 @@ BatchUtilities <- R6::R6Class(
4645
# Otherwise just leave it empty
4746
commands <- c()
4847

48+
containerSettings <- list(
49+
imageName = containerImage,
50+
containerRunOptions = "--rm"
51+
)
52+
4953
if (!is.null(cloudCombine)) {
5054
assign("cloudCombine", cloudCombine, .doAzureBatchGlobals)
55+
containerSettings$imageName <- "brianlovedocker/doazureparallel-merge-dockerfile:0.12.1"
56+
5157
copyCommand <- sprintf(
5258
"%s %s %s --download --saskey $BLOBXFER_SASKEY --remoteresource . --include results/*.rds --endpoint %s",
5359
accountName,
@@ -56,9 +62,7 @@ BatchUtilities <- R6::R6Class(
5662
config$endpointSuffix
5763
)
5864

59-
downloadCommand <-
60-
dockerRunCommand("alfpark/blobxfer:0.12.1", copyCommand, "blobxfer", FALSE)
61-
commands <- c(downloadCommand)
65+
commands <- c(paste("blobxfer", copyCommand))
6266
}
6367

6468
exitConditions <- NULL
@@ -108,7 +112,7 @@ BatchUtilities <- R6::R6Class(
108112

109113
commands <-
110114
c(commands,
111-
dockerRunCommand(containerImage, rCommand))
115+
rCommand)
112116

113117
commands <- linuxWrapCommands(commands)
114118

@@ -141,7 +145,8 @@ BatchUtilities <- R6::R6Class(
141145
commandLine = commands,
142146
dependsOn = dependsOn,
143147
outputFiles = outputFiles,
144-
exitConditions = exitConditions
148+
exitConditions = exitConditions,
149+
containerSettings = containerSettings
145150
)
146151
},
147152
addJob = function(jobId,
@@ -250,12 +255,13 @@ BatchUtilities <- R6::R6Class(
250255

251256
virtualMachineConfiguration <- list(
252257
imageReference = list(
253-
publisher = "Canonical",
254-
offer = "UbuntuServer",
255-
sku = "16.04-LTS",
258+
publisher = "microsoft-azure-batch",
259+
offer = "ubuntu-server-container",
260+
sku = "16-04-lts",
256261
version = "latest"
257262
),
258-
nodeAgentSKUId = "batch.node.ubuntu 16.04"
263+
nodeAgentSKUId = "batch.node.ubuntu 16.04",
264+
containerConfiguration = args$containerConfiguration
259265
)
260266

261267
response <- batchClient$poolOperations$addPool(

R/cluster.R

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,61 +92,54 @@ makeCluster <-
9292
installGithubCommand <- NULL
9393
installBioconductorCommand <- NULL
9494

95+
packages <- c()
9596
if (!is.null(poolConfig$rPackages) &&
9697
!is.null(poolConfig$rPackages$cran) &&
9798
length(poolConfig$rPackages$cran) > 0) {
9899
installCranCommand <-
99100
getPoolPackageInstallationCommand("cran", poolConfig$rPackages$cran)
101+
packages <- c(packages, installCranCommand)
100102
}
101103

102104
if (!is.null(poolConfig$rPackages) &&
103105
!is.null(poolConfig$rPackages$github) &&
104106
length(poolConfig$rPackages$github) > 0) {
105107
installGithubCommand <-
106108
getPoolPackageInstallationCommand("github", poolConfig$rPackages$github)
109+
packages <- c(packages, installGithubCommand)
107110
}
108111

109112
if (!is.null(poolConfig$rPackages) &&
110113
!is.null(poolConfig$rPackages$bioconductor) &&
111114
length(poolConfig$rPackages$bioconductor) > 0) {
112115
installBioconductorCommand <-
113116
getPoolPackageInstallationCommand("bioconductor", poolConfig$rPackages$bioconductor)
114-
}
115-
116-
packages <- c()
117-
if (!is.null(installCranCommand)) {
118-
packages <- c(packages, installCranCommand)
119-
}
120-
if (!is.null(installGithubCommand)) {
121-
packages <- c(packages, installGithubCommand)
122-
}
123-
if (!is.null(installBioconductorCommand)) {
124117
packages <- c(packages, installBioconductorCommand)
125118
}
126119

127120
if (length(packages) == 0) {
128121
packages <- NULL
129122
}
130123

131-
commandLine <- NULL
132-
133124
# install docker
125+
containerConfiguration <- list(
126+
type = "docker"
127+
)
128+
134129
dockerImage <- "rocker/tidyverse:latest"
135130
if (!is.null(poolConfig$containerImage) &&
136131
nchar(poolConfig$containerImage) > 0) {
137132
dockerImage <- poolConfig$containerImage
138133
}
139134

135+
containerConfiguration$containerImageNames <-
136+
list(dockerImage,
137+
"brianlovedocker/doazureparallel-merge-dockerfile:0.12.1")
138+
140139
config$containerImage <- dockerImage
141-
installAndStartContainerCommand <- "cluster_setup.sh"
142140

143141
# Note: Revert it to master once PR is approved
144142
dockerInstallCommand <- c(
145-
paste0(
146-
"wget https://raw.githubusercontent.com/Azure/doAzureParallel/",
147-
"master/inst/startup/cluster_setup.sh"
148-
),
149-
"chmod u+x cluster_setup.sh",
150143
paste0(
151144
"wget https://raw.githubusercontent.com/Azure/doAzureParallel/",
152145
"master/inst/startup/install_bioconductor.R"
@@ -155,11 +148,12 @@ makeCluster <-
155148
"wget https://raw.githubusercontent.com/Azure/doAzureParallel/",
156149
"master/inst/startup/install_custom.R"
157150
),
158-
"chmod u+x install_bioconductor.R",
159-
installAndStartContainerCommand
151+
"chmod u+x install_bioconductor.R"
160152
)
161153

162-
commandLine <- dockerInstallCommand
154+
commandLine <- c(dockerInstallCommand,
155+
'mkdir -p $AZ_BATCH_NODE_SHARED_DIR/R/packages',
156+
'chmod -R 0777 $AZ_BATCH_NODE_SHARED_DIR/R')
163157

164158
# log into private registry if registry credentials were provided
165159
if (!is.null(config$dockerAuthentication) &&
@@ -171,14 +165,13 @@ makeCluster <-
171165
password <- config$dockerAuthentication$password
172166
registry <- config$dockerAuthentication$registry
173167

174-
loginCommand <- dockerLoginCommand(username, password, registry)
175-
commandLine <- c(commandLine, loginCommand)
168+
containerConfiguration$containerRegistries <- list(
169+
list(password = password,
170+
username = username,
171+
registryServer = registry)
172+
)
176173
}
177174

178-
# pull docker image
179-
pullImageCommand <- dockerPullCommand(dockerImage)
180-
commandLine <- c(commandLine, pullImageCommand)
181-
182175
if (!is.null(poolConfig$commandLine)) {
183176
commandLine <- c(commandLine, poolConfig$commandLine)
184177
}
@@ -235,7 +228,8 @@ makeCluster <-
235228
environmentSettings = environmentSettings,
236229
resourceFiles = resourceFiles,
237230
commandLine = commandLine,
238-
networkConfiguration = networkConfiguration
231+
networkConfiguration = networkConfiguration,
232+
containerConfiguration = containerConfiguration
239233
)
240234

241235
if (nchar(response) > 0) {

inst/startup/merger.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ azbatchenv <-
3636

3737
setwd(batchTaskWorkingDirectory)
3838

39-
for (package in azbatchenv$packages) {
40-
library(package, character.only = TRUE)
41-
}
42-
4339
parent.env(azbatchenv$exportenv) <- globalenv()
4440

4541
enableCloudCombine <- azbatchenv$enableCloudCombine
@@ -88,7 +84,7 @@ if (typeof(cloudCombine) == "list" && enableCloudCombine) {
8884
"batchJobId",
8985
"chunkSize",
9086
"errorHandling",
91-
"isError")) %dopar% {
87+
"isError")) %do% {
9288
task <- tryCatch({
9389
readRDS(files[i])
9490
}, error = function(e) {

tests/testthat/utility.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
getSettings <- function(dedicatedMin = 2,
1+
getSettings <- function(dedicatedMin = 0,
22
dedicatedMax = 2,
3-
lowPriorityMin = 2,
3+
lowPriorityMin = 0,
44
lowPriorityMax = 2,
55
poolName = "test-pool"){
66
list(

0 commit comments

Comments
 (0)