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

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



the hosted docker image to run on a schedule


The schedule you want to run via cron


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


The crontab schedule of the VM including your script


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.

See also

Other scheduler functions: gce_vm_scheduler


# 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) # }