RestRserve icon indicating copy to clipboard operation
RestRserve copied to clipboard

Docker and HAproxy example

Open dselivanov opened this issue 7 years ago • 7 comments
trafficstars

http and tcp forwarding

dselivanov avatar May 29 '18 17:05 dselivanov

docker available at https://hub.docker.com/r/dselivanov/restrserve/

dselivanov avatar Jun 07 '18 18:06 dselivanov

Link points to a 404 error page. It doesn't exist i guess

vikram-rawat avatar Oct 02 '20 00:10 vikram-rawat

@vikram-rawat please refer to the readme - https://restrserve.org/#docker as the source of truth.

dselivanov avatar Oct 03 '20 07:10 dselivanov

I got a PoC working with this:

Dockerfile

FROM rocker/r-base:latest

RUN mkdir -p /app
COPY . /app

RUN Rscript /app/install_packages.R

CMD Rscript /app/server.R

app/install_packages.R

install.packages("RestRserve", repos = "https://cloud.r-project.org")
install.packages("readr")

app/server.R

library(RestRserve)

app = Application$new()

app$add_get(
  path = "/health", 
  FUN = function(.req, .res) {
    .res$set_body("OK")
  })

app$add_post(
  path = "/addone", 
  FUN = function(.req, .res) {
    result = list(x = .req$body$x + 1L)
    .res$set_content_type("application/json")
    .res$set_body(result)
  })

backend = BackendRserve$new()
backend$start(app, http_port = 8080)

Build Steps

$ docker pull rocker/r-base
$ docker build -t username/image_name .  # build time took like 10mins tho
$ docker run --rm -it -p 8080:8080 username/image_name

Testing

$ curl http://localhost:8080/health
OK
$ curl -X POST -H "Content-Type: application/json" -d '{"x":4}' http://localhost:8080/addone
{"x":5}

d3an avatar Mar 20 '21 19:03 d3an

@d3an that looks like an ordinal example of RestRserve docker image, but not a RestRserve paired with HAproxy. As for standard RestRserve base docker images I suggest "official" one - https://hub.docker.com/repository/docker/rexyai/restrserve (and corresponding Dockerfile)

dselivanov avatar Mar 21 '21 09:03 dselivanov

Hi @dselivanov is there a reason you removed HAproxy from the base docker? Is it no longer recommended or was that to just make things simpler?

ncullen93 avatar Nov 20 '23 12:11 ncullen93

To make things simpler

dselivanov avatar Nov 20 '23 13:11 dselivanov