rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

GCP App Engine with plumber #401

Closed pedreen closed 5 years ago

pedreen commented 5 years ago

Hello guys! I'm having a problem while creating an app on App Engine with Plumber. I can raise the API, but when I try to access https://plumber-4int.appspot.com/swagger.json I get a 404 error. But https://plumber-4int.appspot.com/demoR works normally . I need swagger.json to work because I'll be applying Cloud Endpoints to manage my API's. Can you help me?

schloerke commented 5 years ago

Your link seems to be working for me.

Make sure you set swagger = TRUE when you run your plumber API. The default is to not run when there is not an interactive R session.

pedreen commented 5 years ago

Thanks @schloerke ! I was able to do this, it was swagger's problem = TRUE, however, I'm having an error when giving a deploy in openapi.yaml. ERROR: (gcloud.endpoints.services.deploy) INVALID_ARGUMENT: Can not convert to service config. 'location: "unknown location" kind: ERROR message: "Invalid OpenAPI file. Please fix the schema errors: \ n \" / paths / ~ 1demoR / get / tags \ ": domain: validation; keyword: type; message: instance has incorrect type; expected: [\" array \ "]; found: \" null \ "".

Do you know what I need to do to solve this problem?

schloerke commented 5 years ago

Can you post the output of your /swagger.json route?

I am curious why there is an ~ in the path. There should be no NULL values being returned by plumber. (If there are, that's a bug).

pedreen commented 5 years ago

https://plumber-4int.appspot.com/swagger.json

{
  "swagger": "2.0",
  "info": {
    "description": "API Description",
    "title": "API Title",
    "version": "1.0.0"
  },
  "host": "127.0.0.1:8080",
  "schemes": [
    "http"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/demoR": {
      "get": {
        "summary": "",
        "responses": {
          "default": {
            "description": "Default response."
          }
        },
        "parameters": [],
        "tags": null
      }
    }
  }
}
schloerke commented 5 years ago

Ah! This using the CRAN version of plumber, which has a known bug of producing invalid specification.

Is it possible to use the github version of plumber? Then this should be solved.

remotes::install_github('trestletech/plumber")

Since you'll be upgrading to the dev version, the swagger param in pr$run() can be a function that upgrades what is automatically produced by plumber. This allows you to enhance the spec to something that is much more in detail that what is automatically produced.

Example: https://github.com/sol-eng/plumber-model/blob/master/R/model-api/entrypoint.R

Also, the specification will be using OpenAPI v3 (not swagger spec, which is same as OpenAPI v2). OpenAPI spec: https://swagger.io/specification/

pedreen commented 5 years ago

This is the Dockerfile I used to create the plumber in appEngine. I'm already using trestletech / plumber. I'll take a look at what you told me about a function that updates what is automatically produced by the plumber.

FROM trestletech/plumber LABEL maintainer="pedro" RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \ && apt-get install -y libcurl4 \ libssl-dev \ make RUN ["install2.r", "askpass", "assertthat", "crayon", "curl", "digest", "googleAuthR", "googleCloudStorageR", "hms", "httr", "jsonlite", "memoise", "openssl", "pillar", "pkgconfig", "R6", "Rcpp", "readr", "rlang", "rstudioapi", "tibble", "yaml", "zip"] WORKDIR /payload/ COPY ["./", "./"]

EXPOSE 8080 ENTRYPOINT ["R", "-e", "pr <- plumber::plumb(commandArgs()[4]); pr$run(host='0.0.0.0', port=8080, swagger=TRUE)"] CMD ["schedule.R"]

schloerke commented 5 years ago

untested

Maybe add the code below between your COPY and EXPOSE statements?

RUN ["install2.r", "remotes"]
RUN ["R", "-e", "remotes::install_github('trestletech/plumber')"]
pedreen commented 5 years ago

Thanks for the tip. I will modify the Dockerfile and take the test. After everything is ready, I'll send you the result.

pedreen commented 5 years ago

When I tried to implement the git version I had this error: ERROR: (gcloud.app.deploy) Cloud build failed. Check logs at https://console.cloud.google.com/gcr/builds/7df8d1e6-55c0-4559-bd7d-1438fd3002e5?project=507038821580 Failure status: UNKNOWN: Error Response: [4] DEADLINE_EXCEEDED

I tried to run this in my Dockerfile:

RUN ["install2.r", "remotes"]
RUN ["R", "-e", "remotes :: install_github ('trestletech / plumber')"]

, and did not work. I also tried with the: devtools :: install_github ('trestletech / plumber').

Here's my openapi.yaml, maybe it could be wrong and giving this error:

swagger: '2.0'
info:
  description: API Test for Cloud Endpoints
  title: API test Cloud Endpoints
  version: 1.0.0
host: plumber-4int.appspot.com
schemes: [http]
produces: [application / json]
paths:
  / demoR:
    get
      summary: ''
      responses:
        default:
          description: Default response.
      parameters: []
      tags:
      operationId: demoR
ashishsr123 commented 5 years ago

I am facing a issue when deploying R + plumber on Google App engine Flexible with Docker. Refer to issue details: https://stackoverflow.com/questions/57735491/google-app-engine-flexible-with-docker-site-cannot-be-reached

Any guidance will be greatly appreciated.

Ashishsr123

ashishsr123 commented 5 years ago

Hello guys! I'm having a problem while creating an app on App Engine with Plumber. I can raise the API, but when I try to access https://plumber-4int.appspot.com/swagger.json I get a 404 error. But https://plumber-4int.appspot.com/demoR works normally . I need swagger.json to work because I'll be applying Cloud Endpoints to manage my API's. Can you help me?

did you manage to solve your issue ?

schloerke commented 5 years ago

@ashishsr123 https://github.com/rstudio/plumber/issues/401#issuecomment-474953668

Make sure you set swagger = TRUE when you run your plumber API. The default is to not run when there is not an interactive R session.


(In the future, please open a new issue referencing this one.)