简体   繁体   中英

Error while deploying R using plumber in Google App Engine Flex with Docker

What am doing?

I am trying to deploy a R model on Google App Engine Flex with docker container. My final objective is to serve model as API. I am getting errors when deploying app using plumber and docker container.

R code with plumber runs fine on my local computer using RStudio. But now I am using AI platform jupyter notebooks with R. I tested the docker locally using Docker Run image-name command and I get below message once Docker run.

Starting server to listen on port 8080 

When I run the R + plumber code in my local Rstudio , I get below messages

Starting server to listen on port 8080
Running the swagger UI at http://127.0.0.1:8080/__swagger__/

After this I run gcloud app deploy ( this agains build docker image etc) , build runs for more than 15 mins and fails with error message , as shown in the end.

Details of code etc:

app.yaml

service: iris-custom
runtime: custom
env: flex

manual_scaling:
  instances: 1

resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 20

# added below to increase app_start_timeout_sec  
readiness_check:
  path: "/readiness_check"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 900

Dockerfile

FROM gcr.io/gcer-public/plumber-appengine

# install the linux libraries needed for plumber
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
&& apt-get install -y

# install plumber commented as plumber is preinstalled
#RUN R -e "install.packages(c('plumber'), repos='http://cran.rstudio.com/')"

# copy everything from the current directory into the container
WORKDIR /payload/
COPY [".", "./"]

# open port 8080 to traffic
EXPOSE 8080

# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "main.R"]

main.R

library(plumber)
r <- plumb("rest_controller.R")
r$run(port=8080, host="0.0.0.0")

rest_controller.R

#* @get /predict_petal_length
get_predict_length <- function(){

  dataset <- iris

  # create the model
  model <- lm(Petal.Length ~ Petal.Width, data = dataset)
  petal_width = "0.4"

  # convert the input to a number
  petal_width <- as.numeric(petal_width)

  #create the prediction data frame
  prediction_data <- data.frame(Petal.Width=petal_width)

  # create the prediction
  predict(model,prediction_data)
}

Error message:

ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.

I tried a little modified code ,deployment succeeds but app engine still does not work. issue with code link

From the Google Cloud Doku it seems like in order for your Apllication to pass it needs to return the http status code 200 (see https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#updated_health_checks ).

But your Application returns the http status code 404 on the path you have defined for redincess check, since it doesn't exist.

readiness_check:
 path: "/readiness_check"

So I would either suggest to add this path as an option to your rest_controller.R file like

#* @get /readiness_check
readiness_check<- function(){
    return ("app ready")
}

or modify your app.yml so that it checks the get_predict_length enpoint instead

readiness_check:
  path: "/get_predict_length"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM