gce_schedule_docker: Schedule running a docker image upon a VM

Description Usage Arguments Details Value See Also Examples

Description

Utility function to start a VM to run a docker container on a schedule. You will need to create and build the Dockerfile first.

Usage

1
2
gce_schedule_docker(docker_image, schedule = "53 4 * * *",
  vm = gce_vm_scheduler())

Arguments

docker_image

the hosted docker image to run on a schedule

schedule

The schedule you want to run via cron

vm

A VM object to schedule the script upon that you can SSH into

Details

You may need to run gce_vm_scheduler yourself first and then set up SSH details if not defaults, to pass to argument vm

You can create a Dockerfile with your R script installed by running it through containeRit::dockerfile. It also takes care of any dependencies.

It is recommended to create a script that is self contained in output and input, e.g. don't save files to the VM, instead upload or download any files from Google Cloud Storage via authentication via googleAuthR::gar_gce_auth() then downloading and uploading data using library(googleCloudStorageR) or similar.

Once the script is working locally, build it and upload to a repository so it can be reached via argument docker_image

You can build via Google cloud repository build triggers, in which case the name can be created via gce_tag_container or build via docker_build to build on another VM or locally, then push to a registry via gce_push_registry

Any Docker image can be run, it does not have to be an R one.

Value

The crontab schedule of the VM including your script

See Also

Other scheduler functions: gce_vm_scheduler

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Not run: 
# create a Dockerfile of your script
if(!require(containeRit)){
  remotes::install_github("o2r-project/containerit")
  library(containeRit)
}


## create your scheduled script, example below named schedule.R
## it will run the script whilst making the dockerfile
container <- dockerfile("schedule.R",
                        copy = "script_dir",
                        cmd = CMD_Rscript("schedule.R"),
                        soft = TRUE)
write(container, file = "Dockerfile")

## upload created Dockerfile to GitHub, 
  then use a Build Trigger to create Docker image "demoDockerScheduler"
## built trigger uses "demo-docker-scheduler" as must be lowercase

## After image is built:
## Create a VM to run the schedule
vm <- gce_vm_scheduler("my_scheduler")

## setup any SSH not on defaults
vm <- gce_vm_setup(vm, username = "mark")

## get the name of the just built Docker image that runs your script
docker_tag <- gce_tag_container("demo-docker-scheduler", project = "gcer-public")

## Schedule the docker_tag to run every day at 0453AM
gce_schedule_docker(docker_tag, schedule = "53 4 * * *", vm = vm)



## End(Not run)

googleComputeEngineR documentation built on May 6, 2019, 1:01 a.m.