Skip to content

Commit

Permalink
Template instance builder for (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Feb 17, 2017
1 parent 3f9d4f7 commit ed492a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
20 changes: 19 additions & 1 deletion R/container.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ gce_check_container <- function(instance, container){
#' @param password password if needed (RStudio)
#' @param image_family An image-family. It must come from the \code{google-containers} family.
#' @param dynamic_image Supply an alternative to the default Docker image here to download
#' @param dockerfile If template is \code{builder} the Dockerfile to run on startup
#' @param build_name If template is \code{builder} the name to save the image under on Container Enginer
#' @param ... Other arguments passed to \link{gce_vm_create}
#'
#' @details
Expand Down Expand Up @@ -67,10 +69,12 @@ gce_check_container <- function(instance, container){
#' @export
gce_vm_template <- function(template = c("rstudio","shiny","opencpu",
"r-base", "example", "rstudio-hadleyverse",
"dynamic"),
"dynamic", "builder"),
username=NULL,
password=NULL,
dynamic_image=NULL,
dockerfile = NULL,
build_name = NULL,
image_family = "gci-stable",
name,
...){
Expand Down Expand Up @@ -119,6 +123,20 @@ gce_vm_template <- function(template = c("rstudio","shiny","opencpu",
image <- get_image("rocker/r-base", dynamic_image = dynamic_image)
cloud_init_file <- sprintf(cloud_init_file, image)

} else if(template == "builder") {

if(is.null(build_name)){
stop("Need to specify what to call the Docker image")
}
build_tag <- gce_tag_container(build_name)
myMessage("Creating build VM to create and upload ", build_tag, level = 3)

if(is.null(dockerfile)){
stop("Need to supply Dockerfile file location to build from")
}

cloud_init_file <- sprintf(cloud_init_file, dockerfile, build_tag, build_tag)

} else {
warning("No template settings found for ", template)
}
Expand Down
7 changes: 5 additions & 2 deletions inst/cloudconfig/builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ users:
uid: 2000

write_files:
- path: ~/buildfolder/Dockerfile
- path: /home/gcer/buildfolder/Dockerfile
permissions: 0644
owner: root
content: |
%s

runcmd:
- docker build -t %s ~/buildfolder/Dockerfile
- docker build -t build_me /home/gcer/buildfolder/Dockerfile
- docker tag build_me %s
- /usr/share/google/dockercfg_update.sh
- docker push %s
10 changes: 7 additions & 3 deletions man/gce_vm_template.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed492a8

Please sign in to comment.