From 80656df7e35d87f6f39895077f17bca0bf5dfc7c Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 8 Jan 2022 16:21:27 -0500 Subject: [PATCH 1/6] feat: create initial Dockerfile for plumber API --- inst/api/Dockerfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 inst/api/Dockerfile diff --git a/inst/api/Dockerfile b/inst/api/Dockerfile new file mode 100644 index 0000000..a9933d2 --- /dev/null +++ b/inst/api/Dockerfile @@ -0,0 +1,25 @@ +FROM rocker/r-ver + +# FROM rstudio/plumber + +# sysreqs - pak::pkg_system_requirements("plumber", "ubuntu", "20.04") +RUN apt-get install -y libcurl4-openssl-dev \ + apt-get install -y libssl-dev \ + apt-get install -y libsodium-dev \ + apt-get install -y libicu-dev \ + apt-get install -y make \ + apt-get install -y zlib1g-dev + +# R packages +RUN R -e "install.packages('plumber')" +RUN R -e "install.packages('remotes')" +RUN R -e "remotes::install_github('jimbrig/lossrx')" + +# Copy API +COPY plumber.R / + +# Expose Port 80 to Traffic +EXPOSE 80 + +# Entrypoint +ENTRYPOINT ["R", "-e", "pr <- plumber::plumb('plumber.R'); pr$run(host='0.0.0.0', port=80)"] From 16f58ac4e54ec66c8bb0ad971cccb712db94f6a4 Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 8 Jan 2022 16:21:44 -0500 Subject: [PATCH 2/6] feat: scaffold API directory in inst/api --- inst/api/README.md | 0 inst/api/openapi.yml | 0 inst/api/plumber.R | 31 +++++++++++++++++++++++++++++++ inst/api/run_api.sh | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 inst/api/README.md create mode 100644 inst/api/openapi.yml create mode 100644 inst/api/plumber.R create mode 100644 inst/api/run_api.sh diff --git a/inst/api/README.md b/inst/api/README.md new file mode 100644 index 0000000..e69de29 diff --git a/inst/api/openapi.yml b/inst/api/openapi.yml new file mode 100644 index 0000000..e69de29 diff --git a/inst/api/plumber.R b/inst/api/plumber.R new file mode 100644 index 0000000..d27087d --- /dev/null +++ b/inst/api/plumber.R @@ -0,0 +1,31 @@ +# +# This is a Plumber API. You can run the API by clicking +# the 'Run API' button above. +# +# Find out more about building APIs with Plumber here: +# +# https://www.rplumber.io/ +# + +library(plumber) + +#* @apiTitle Loss Reserving API +#* @apiDescription An Actuarial API for dealing with Loss Reserving Data and Workflows. + + +# Utility Endpoints ------------------------------------------------------- + +#* Echo back the input +#* @param msg The message to echo +#* @get /echo +function(msg = "") { + list(msg = paste0("The message is: '", msg, "'")) +} + +# Programmatically alter your API +#* @plumber +function(pr) { + pr %>% + # Overwrite the default serializer to return unboxed JSON + pr_set_serializer(serializer_unboxed_json()) +} diff --git a/inst/api/run_api.sh b/inst/api/run_api.sh new file mode 100644 index 0000000..bb1f1b6 --- /dev/null +++ b/inst/api/run_api.sh @@ -0,0 +1,2 @@ +docker build -t lossreservingapi:latest . +docker run -p 80:80 -d lossreservingapi:latest From e6b4849cfbec22ccb0d9ae4f28d6007533a2847f Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 12 Feb 2022 20:51:06 -0500 Subject: [PATCH 3/6] Delete test-coverage.yaml --- .github/workflows/test-coverage.yaml | 32 ---------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/test-coverage.yaml diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml deleted file mode 100644 index 5e15b8c..0000000 --- a/.github/workflows/test-coverage.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - workflow_dispatch: - -name: test-coverage - -jobs: - test-coverage: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - CODCOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v1 - with: - extra-packages: covr - - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} From 50e4244d2a705f7200786df1e63c163751fe77ef Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 8 Jan 2022 16:21:27 -0500 Subject: [PATCH 4/6] feat: create initial Dockerfile for plumber API --- inst/api/Dockerfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 inst/api/Dockerfile diff --git a/inst/api/Dockerfile b/inst/api/Dockerfile new file mode 100644 index 0000000..a9933d2 --- /dev/null +++ b/inst/api/Dockerfile @@ -0,0 +1,25 @@ +FROM rocker/r-ver + +# FROM rstudio/plumber + +# sysreqs - pak::pkg_system_requirements("plumber", "ubuntu", "20.04") +RUN apt-get install -y libcurl4-openssl-dev \ + apt-get install -y libssl-dev \ + apt-get install -y libsodium-dev \ + apt-get install -y libicu-dev \ + apt-get install -y make \ + apt-get install -y zlib1g-dev + +# R packages +RUN R -e "install.packages('plumber')" +RUN R -e "install.packages('remotes')" +RUN R -e "remotes::install_github('jimbrig/lossrx')" + +# Copy API +COPY plumber.R / + +# Expose Port 80 to Traffic +EXPOSE 80 + +# Entrypoint +ENTRYPOINT ["R", "-e", "pr <- plumber::plumb('plumber.R'); pr$run(host='0.0.0.0', port=80)"] From 742abda39b75563f9342bfbca85a2d30732b044e Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 8 Jan 2022 16:21:44 -0500 Subject: [PATCH 5/6] feat: scaffold API directory in inst/api --- inst/api/README.md | 0 inst/api/openapi.yml | 0 inst/api/plumber.R | 31 +++++++++++++++++++++++++++++++ inst/api/run_api.sh | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 inst/api/README.md create mode 100644 inst/api/openapi.yml create mode 100644 inst/api/plumber.R create mode 100644 inst/api/run_api.sh diff --git a/inst/api/README.md b/inst/api/README.md new file mode 100644 index 0000000..e69de29 diff --git a/inst/api/openapi.yml b/inst/api/openapi.yml new file mode 100644 index 0000000..e69de29 diff --git a/inst/api/plumber.R b/inst/api/plumber.R new file mode 100644 index 0000000..d27087d --- /dev/null +++ b/inst/api/plumber.R @@ -0,0 +1,31 @@ +# +# This is a Plumber API. You can run the API by clicking +# the 'Run API' button above. +# +# Find out more about building APIs with Plumber here: +# +# https://www.rplumber.io/ +# + +library(plumber) + +#* @apiTitle Loss Reserving API +#* @apiDescription An Actuarial API for dealing with Loss Reserving Data and Workflows. + + +# Utility Endpoints ------------------------------------------------------- + +#* Echo back the input +#* @param msg The message to echo +#* @get /echo +function(msg = "") { + list(msg = paste0("The message is: '", msg, "'")) +} + +# Programmatically alter your API +#* @plumber +function(pr) { + pr %>% + # Overwrite the default serializer to return unboxed JSON + pr_set_serializer(serializer_unboxed_json()) +} diff --git a/inst/api/run_api.sh b/inst/api/run_api.sh new file mode 100644 index 0000000..bb1f1b6 --- /dev/null +++ b/inst/api/run_api.sh @@ -0,0 +1,2 @@ +docker build -t lossreservingapi:latest . +docker run -p 80:80 -d lossreservingapi:latest From 767aa21a6d3b148bea62f836326b7d93c31dec6c Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Sat, 12 Feb 2022 20:51:06 -0500 Subject: [PATCH 6/6] Delete test-coverage.yaml --- .github/workflows/coverage.yml | 38 ---------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index d8357d2..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - workflow_dispatch: - -name: Code-Coverage - -jobs: - test-coverage: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - CODCOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - steps: - - uses: actions/checkout@v3.5.0 - - - uses: r-lib/actions/setup-r@v2 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - extra-packages: covr - - - name: Install Package - run: | - R CMD INSTALL --install-tests . - - - name: Test coverage - # run: covr::codecov() - run: covr::codecov(coverage = covr::package_coverage(line_exclusions = list("R/utils-feedback.R"))) - shell: Rscript {0} -