From 20427b16eefed4a16952d22346ca41021d09cfce Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 24 Jul 2020 13:57:19 -0400 Subject: [PATCH] Update Docker files (#589) --- .github/workflows/docker.yaml | 48 ++++++++++++++++++++++ Dockerfile | 60 ++++++++++++++++++++++++---- NEWS.md | 2 + inst/check/Dockerfile | 34 ---------------- inst/check/Dockerfile-v0.5.0 | 30 -------------- inst/examples/03-github/Dockerfile | 5 +-- inst/examples/06-sessions/Dockerfile | 8 ++-- inst/examples/07-mailgun/Dockerfile | 5 +-- scripts/release.md | 6 --- 9 files changed, 111 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/docker.yaml delete mode 100644 inst/check/Dockerfile delete mode 100644 inst/check/Dockerfile-v0.5.0 diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 000000000..e7f2abcd7 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,48 @@ +name: Docker + +on: + push: + branches: + - "master" + schedule: + - cron: '0 0 1 * *' # first of every month + + +jobs: + docker: + name: ${{ matrix.config.tags }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + + matrix: + r_version: + - "latest" + + config: + - name: CRAN + # always overwrite the latest version with the CRAN version + tags: "v0.4.6,latest" + ref: "v0.4.6" + + - name: GitHub + # 'next' tag signifies the _next_ release + tags: "next" + ref: "master" + + + steps: + - uses: actions/checkout@master + + # https://github.com/marketplace/actions/publish-docker + - name: rstudio/plumber + uses: elgohr/Publish-Docker-Github-Action@2.18 + with: + name: rstudio/plumber + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + cache: false + workdir: "." + buildargs: "R_VERSION=${{ matrix.r_version }},PLUMBER_REF=${{ matrix.config.ref }}${{ matrix.config.extra_buildargs }}" + tags: ${{ matrix.config.tags }} diff --git a/Dockerfile b/Dockerfile index 7e41d9a7d..9e0c3183c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,60 @@ -FROM rocker/r-base -MAINTAINER Jeff Allen -RUN apt-get update -qq && apt-get install -y \ +ARG R_VERSION=latest + +FROM rocker/r-ver:${R_VERSION} +LABEL maintainer="barret@rstudio.com" + +ARG PLUMBER_REF=master + +# BEGIN rstudio/plumber layers +RUN apt-get update -qq && apt-get install -y --no-install-recommends \ git-core \ libssl-dev \ libcurl4-gnutls-dev \ - libsodium-dev + curl \ + libsodium-dev \ + libxml2-dev + +RUN install2.r remotes -## RUN R -e 'install.packages(c("remotes"))' -## RUN R -e 'remotes::install_github("rstudio/plumber")' -RUN install2.r plumber +## Remove this comment to always bust the Docker cache at this step +## https://stackoverflow.com/a/55621942/591574 +#ADD https://github.com/rstudio/plumber/commits/ _docker_cache + +RUN Rscript -e "remotes::install_github('rstudio/plumber@${PLUMBER_REF}')" EXPOSE 8000 -ENTRYPOINT ["R", "-e", "pr <- plumber::plumb(commandArgs()[4]); pr$run(host='0.0.0.0', port=8000)"] + +ENTRYPOINT ["R", "-e", "pr <- plumber::plumb(rev(commandArgs())[1]); pr$run(host='0.0.0.0', port=8000, swagger=TRUE)"] + CMD ["/usr/local/lib/R/site-library/plumber/examples/04-mean-sum/plumber.R"] + +# EOF rstudio/plumber layers + +# README: + +# Usage (adjust the tags/versions according to your preferences): + +# build docker file +# docker build --build-arg R_VERSION=4.0.2 -t rstudio/plumber:latest . +# run with defaults +# docker run -it -p 8000:8000 --rm --name plumber rstudio/plumber:latest +# open in browser +# firefox http://localhost:8000/__swagger__/ & + +# to run with your own api - mount your plumber.R file into the container like so: +# docker run -it -p 8000:8000 --rm -v ~/R/x86_64-pc-linux-gnu-library/4.0/plumber/examples/10-welcome/plumber.R:/api/plumber.R:ro --name myapi rstudio/plumber:latest /api/plumber.R +# then browse with +# curl http://localhost:8000/ + + +# Extend the rstudio/plumber:TAG Dockerfile / build your own custom image adding debian packages and your own api: + +## ./Dockerfile +# FROM rstudio/plumber:latest +# RUN apt-get update -qq && apt-get install -y \ +# [list-your-debian-packages-here] +# # add app files from host's present working dir +# COPY . /api +# # set default startup command to run the app's "plumber.R" file +# CMD ["/api/plumber.R"] diff --git a/NEWS.md b/NEWS.md index 4888ce1a2..dd12337ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -50,6 +50,8 @@ plumber 1.0.0 ### Minor new features and improvements +* Updated Docker files. New Docker repo is now [`rstudio/plumber`](https://hub.docker.com/r/rstudio/plumber/tags). Updates heavily inspired from @mskyttner (#459). (#589) + * Support HTTP 405 Code. (@meztez, #554) * Attached the router to the incoming request object at `req$pr`. (@meztez, #554) diff --git a/inst/check/Dockerfile b/inst/check/Dockerfile deleted file mode 100644 index 272fd1aaf..000000000 --- a/inst/check/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -FROM rocker/drd -MAINTAINER Jeff Allen - -RUN apt-get update -qq && apt-get install -y \ - curl \ - libxml2-dev \ - git-core \ - libssl-dev/unstable \ - libssh2-1 \ - texlive-latex-base \ - texlive-fonts-recommended \ - texlive-fonts-extra - -RUN R -e 'install.packages(c("XML", "devtools", "testthat", "PKI", "httpuv", "rmarkdown"))' - -# Install pandoc -RUN curl -fLo /tmp/pandoc-2.2-1-amd64.deb https://github.com/jgm/pandoc/releases/download/2.2/pandoc-2.2-1-amd64.deb && \ - dpkg -i /tmp/pandoc-2.2-1-amd64.deb && \ - apt-get install -f && \ - rm /tmp/pandoc-2.2-1-amd64.deb - -# ENV RSTUDIO_PANDOC=/pandoc -# ENV PATH=$PATH:/pandoc - -RUN R -e "install.packages(c('htmlwidgets', 'visNetwork', 'analogsea'))" - -# rforge required because of some recent instability in PKI... disconcerting. -# https://stat.ethz.ch/pipermail/r-help/2016-December/443572.html -RUN R -e "install.packages('PKI',,'https://www.rforge.net/')" - - -CMD git clone -b "release-v0.4.6" https://github.com/schloerke/plumber.git /plumber && \ - R CMD build /plumber && \ - R CMD check plumber_*.tar.gz --as-cran diff --git a/inst/check/Dockerfile-v0.5.0 b/inst/check/Dockerfile-v0.5.0 deleted file mode 100644 index da95a6278..000000000 --- a/inst/check/Dockerfile-v0.5.0 +++ /dev/null @@ -1,30 +0,0 @@ -FROM rocker/drd -MAINTAINER Jeff Allen - -RUN apt-get update -qq && apt-get install -y \ - curl \ - libxml2-dev \ - git-core \ - libsodium-dev \ - libssl-dev/unstable \ - libssh2-1 \ - texlive-latex-base \ - texlive-fonts-recommended \ - texlive-fonts-extra - -RUN R -e 'install.packages(c("XML", "devtools", "testthat", "sodium", "httpuv", "rmarkdown", "swagger"))' - -# Install pandoc -RUN curl -fLo /tmp/pandoc-2.2-1-amd64.deb https://github.com/jgm/pandoc/releases/download/2.2/pandoc-2.2-1-amd64.deb && \ - dpkg -i /tmp/pandoc-2.2-1-amd64.deb && \ - apt-get install -f && \ - rm /tmp/pandoc-2.2-1-amd64.deb - -# ENV RSTUDIO_PANDOC=/pandoc -# ENV PATH=$PATH:/pandoc - -RUN R -e "install.packages(c('htmlwidgets', 'visNetwork', 'analogsea'))" - -CMD git clone -b "release-v0.5.0" https://github.com/rstudio/plumber.git /plumber && \ - R CMD build /plumber && \ - R CMD check plumber_*.tar.gz --as-cran diff --git a/inst/examples/03-github/Dockerfile b/inst/examples/03-github/Dockerfile index 4baf1ca22..1a4f92a0b 100644 --- a/inst/examples/03-github/Dockerfile +++ b/inst/examples/03-github/Dockerfile @@ -1,6 +1,5 @@ -FROM trestletech/plumber -MAINTAINER Jeff Allen +FROM rstudio/plumber:next COPY github-key.txt /github-key -CMD ["/examples/03-github/github.R"] +CMD ["/usr/local/lib/R/site-library/plumber/examples/03-github/plumber.R"] diff --git a/inst/examples/06-sessions/Dockerfile b/inst/examples/06-sessions/Dockerfile index 2a988e5ec..e8a2531b4 100644 --- a/inst/examples/06-sessions/Dockerfile +++ b/inst/examples/06-sessions/Dockerfile @@ -1,4 +1,6 @@ -FROM trestletech/plumber -MAINTAINER Jeff Allen +FROM rstudio/plumber:next -ENTRYPOINT R -e "pr <- plumber::plumb('/examples/06-sessions/sessions.R'); pr\$registerHooks(plumber::sessionCookie('secret', 'cookieName', path='/')); pr\$run(host='0.0.0.0', port=8000)" +ENTRYPOINT R \ + -e "pr <- plumber::plumb(system.file('examples/06-sessions/plumber.R', package = 'plumber'))" \ + -e "pr\$registerHooks(plumber::sessionCookie('pleasechangeme', 'cookieName'))" \ + -e "pr\$run(host='0.0.0.0', port=8000)" diff --git a/inst/examples/07-mailgun/Dockerfile b/inst/examples/07-mailgun/Dockerfile index 206717ef6..aeb50e12a 100644 --- a/inst/examples/07-mailgun/Dockerfile +++ b/inst/examples/07-mailgun/Dockerfile @@ -1,6 +1,5 @@ -FROM trestletech/plumber -MAINTAINER Jeff Allen +FROM rstudio/plumber:next RUN R -e "install.packages('htmltools')" -CMD ["/examples/07-mailgun/mailgun.R"] +CMD ["/usr/local/lib/R/site-library/plumber/examples/07-mailgun/plumber.R"] diff --git a/scripts/release.md b/scripts/release.md index 581f2c7d6..c2c5a594b 100644 --- a/scripts/release.md +++ b/scripts/release.md @@ -10,12 +10,6 @@ 1. `devtools::release()`, * (don't actually release in the last step) * DON'T LIE!! -1. Run the docker image in inst/check on the release candidate. Note that you will need to change the CMD to checkout the release branch so you're testing it, not master. - 1. ```{bash} -cd inst/check -docker build -t plumber_docker . -docker run plumber_docker -``` ## Release Steps