From 48638e77cf14b6591de21543653f607caf9b48b6 Mon Sep 17 00:00:00 2001 From: Dan Lu Date: Mon, 3 Apr 2023 17:01:26 -0700 Subject: [PATCH] add docker image and rspecify environment variables --- .github/workflows/Release_Docker_build.yml | 65 ++++++++++++++++++++++ .releaserc.json | 7 +++ Dockerfile | 22 ++++++++ R/zzz.R | 10 +++- app.R | 2 +- dccmonitor_startup.sh | 8 +++ inst/config.yml | 54 +++++++++++++++++- 7 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/Release_Docker_build.yml create mode 100644 .releaserc.json create mode 100644 Dockerfile create mode 100755 dccmonitor_startup.sh diff --git a/.github/workflows/Release_Docker_build.yml b/.github/workflows/Release_Docker_build.yml new file mode 100644 index 0000000..8f9739b --- /dev/null +++ b/.github/workflows/Release_Docker_build.yml @@ -0,0 +1,65 @@ +# 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 + +name: Create and publish a Docker image + +on: + push: + branches: + - 'master' + tags: + - 'v*' +env: + REGISTRY: ghcr.io + IMAGE_PATH: ghcr.io/${{ github.repository }} + +jobs: + tagging: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: '0' + - name: Bump version and push tag + id: tag_version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + - name: Create a GitHub release + uses: ncipollo/release-action@v1 + with: + tag: ${{ steps.tag_version.outputs.new_tag }} + name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} + + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2.1.0 + if: github.event_name == 'push' + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4.1.1 + with: + images: ${{ env.IMAGE_PATH }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3.2.0 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags}} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..0985abb --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/github" + ] +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..301abae --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM sagebionetworks/shiny-base:release-1.0 +# This is the expected application installation folder +WORKDIR /srv/shiny-server/app +COPY --chown=shiny ./ ./ + +# Set up Python and install the Synapse Python client +RUN Rscript -e "install.packages('reticulate', repos='http://cran.rstudio.com/', verbose=FALSE)" +RUN Rscript -e "library(reticulate); install_miniconda(); py_discover_config(); py_install(c('synapseclient', 'pandas'), pip = TRUE, pip_ignore_installed=TRUE)" + +# alternative to using renv +#RUN Rscript -e "install.packages(c('shinydashboard','tidyverse','readxl','gt','gtsummary','survival','survminer','rsconnect','janitor','rjson'), repos='http://cran.rstudio.com/', verbose=FALSE)" + +# By default the log level is TRACE. We bump up one level to DEBUG to make the logs a bit less verbose +ENV SHINY_LOG_LEVEL=DEBUG + +# set up r packages via renv. Use binary lib matching the shiny-base ubuntu version +# to speed up installatioon. +RUN Rscript -e 'renv::restore(repos="https://packagemanager.rstudio.com/all/__linux__/jammy/latest"); renv::install("./")' + +# running that script, to pass a configuration env var to Shiny +RUN chmod +x dccmonitor_startup.sh +CMD ["./dccmonitor_startup.sh"] \ No newline at end of file diff --git a/R/zzz.R b/R/zzz.R index 3ffe8f5..dd882eb 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -7,11 +7,19 @@ app_url <- NULL claims_param <- NULL authorization_url <- NULL +if (interactive()) { + # testing url + options(shiny.port = 8100) + app_url <- "http://127.0.0.1:8100" +} else { + app_url <- Sys.getenv("APP_REDIRECT_URL") +} + .onLoad <- function(libname, pkgname) { # nolint synapse <<- reticulate::import("synapseclient", delay_load = TRUE) if (!interactive()) { setup_global_oauth_vars( - app_url = get_golem_config("app_url"), + app_url = Sys.getenv("app_url"), client_name = Sys.getenv("client_name"), client_id = Sys.getenv("client_id"), client_secret = Sys.getenv("client_secret") diff --git a/app.R b/app.R index a28b27f..5b775c8 100644 --- a/app.R +++ b/app.R @@ -2,7 +2,7 @@ # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file -Sys.setenv(R_CONFIG_ACTIVE = "default", # Replace "default" with your config +Sys.setenv(R_CONFIG_ACTIVE = Sys.getenv("R_CONFIG_ACTIVE"), # Replace "default" with your config R_CONFIG_FILE = "inst/config.yml") pkgload::load_all() options("golem.app.prod" = TRUE) diff --git a/dccmonitor_startup.sh b/dccmonitor_startup.sh new file mode 100755 index 0000000..2479f10 --- /dev/null +++ b/dccmonitor_startup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +# Pass environment variable to Shiny +echo "" >> .Renviron +echo APP_REDIRECT_URL=$APP_REDIRECT_URL >> .Renviron + +# Now run the base start-up script +./startup.sh \ No newline at end of file diff --git a/inst/config.yml b/inst/config.yml index a792d68..fc77f9f 100644 --- a/inst/config.yml +++ b/inst/config.yml @@ -110,7 +110,7 @@ amp-ad: - "specimenID" pec: - app_url: "https://shinypro.synapse.org/users/kmontgomery/dccmonitor/" + #app_url: "https://shinypro.synapse.org/users/danlu/dccmonitor-pec/" samples_table: "syn22175287" annotations_table: "syn20981788" annotations_storage: "syn21763155" @@ -174,3 +174,55 @@ pec: - "libraryPrep" - "libraryPreparationMethod" - "runType" + +1kD: + #app_url: "https://shinypro.synapse.org/users/danlu/dccmonitor_1kD/" + samples_table: "syn27817789" + annotations_table: "syn27806892" + annotations_storage: "syn27605404" + annotations_link: "https://www.synapse.org/#!Synapse:syn27817580" + annotation_keys: + - "age" + - "primaryDiagnosis" + consortium_fileview: "syn27646655" + teams: + - "3433360" + templates: + manifest_template: "syn27832372" + individual_templates: + human: "syn29358381" + biospecimen_templates: + human: "syn29358373" + assay_templates: + species_list: + - "human" + complete_columns: + manifest: + - "path" + - "parent" + - "fileFormat" + - "program" + - "project" + - "study" + - "resourceType" + individual: + - "program" + - "project" + - "study" + - "individualID" + - "householdID" + - "person" + - "sex" + - "noOfChildren" + - "noOfAdults" + - "spokenLanguage" + biospecimen: + - "program" + - "project" + - "study" + - "person" + - "individualID" + - "specimenID" + - "specimenType" + - "samplingAge" + - "samplingAgeUnits"