Skip to content

Commit

Permalink
Merge pull request #133 from FredHutch/dev
Browse files Browse the repository at this point in the history
shiny-cromwell v1.1.0 Updates
  • Loading branch information
tefirman authored Sep 17, 2024
2 parents d358811 + 3cb24cb commit cd3946a
Show file tree
Hide file tree
Showing 13 changed files with 370 additions and 67 deletions.
30 changes: 23 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ variables:
before_script:
- apk update
- apk --no-cache add py3-pip python3 curl
- pip3 install pyyaml --break-system-packages
- python3 -m venv $HOME/.venv
- export PATH=$HOME/.venv/bin:$PATH
- pip3 install pyyaml
- curl -O https://raw.githubusercontent.com/FredHutch/swarm-build-helper/main/build_helper.py
# below is from https://stackoverflow.com/a/65810302/470769
- mkdir -p $HOME/.docker
- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
- set -x

stages:
- build
- test
- deploy

stages:
- build
- test
Expand All @@ -27,7 +24,7 @@ build:
script: |
python3 build_helper.py docker-compose.yml --fluentd-logging > /dev/null
echo $DB_CONFIG | base64 -d > .my.cnf
docker build \
docker build --no-cache \
-t sc-registry.fredhutch.org/shiny-cromwell:test \
--build-arg CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH} \
--build-arg CI_COMMIT_SHA=${CI_COMMIT_SHA} \
Expand All @@ -54,6 +51,25 @@ test:
curl -sI http://shiny-cromwell:3838 | head -1 | grep -q "200 OK"
docker run -w /srv/shiny-server --rm sc-registry.fredhutch.org/shiny-cromwell:test R -q -e 'testthat::test_dir("tests")'
deploy_review_image:
stage: deploy
except:
refs:
- main
- dev
script:
- docker tag sc-registry.fredhutch.org/shiny-cromwell:test nexus-registry.fredhutch.org/scicomp-nexus/${CI_PROJECT_NAME}:${CI_COMMIT_BRANCH}
- docker push nexus-registry.fredhutch.org/scicomp-nexus/${CI_PROJECT_NAME}:${CI_COMMIT_BRANCH}

deploy_review_image:
stage: deploy
except:
refs:
- main
- dev
script:
- docker tag sc-registry.fredhutch.org/shiny-cromwell:test nexus-registry.fredhutch.org/scicomp-nexus/${CI_PROJECT_NAME}:${CI_COMMIT_BRANCH}
- docker push nexus-registry.fredhutch.org/scicomp-nexus/${CI_PROJECT_NAME}:${CI_COMMIT_BRANCH}

deploy_preview:
stage: deploy
Expand Down
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM fredhutch/r-shiny-server-base:4.3.2

RUN apt-get update -y && apt-get install -y libssh-dev
RUN apt-get update -y && apt-get install -y libssh-dev python3-pip git libmariadb-dev

RUN R -q -e 'install.packages(c("ellipsis"), repos="https://cran.rstudio.com/")'
RUN R -q -e 'install.packages(c("shiny"), repos="https://cran.rstudio.com/")'
RUN R -q -e 'install.packages(c("shinyFeedback", "shinyWidgets", "shinydashboard", "shinydashboardPlus", "ssh", "remotes", "markdown", "lubridate", "jsonlite", "dplyr", "DT", "glue", "httr", "purrr", "RColorBrewer", "rlang", "shinyBS", "shinyjs", "tidyverse", "uuid", "memoise", "rclipboard", "shinyvalidate", "shinylogs", "testhat"), repos="https://cran.r-project.org")'
RUN R -q -e 'install.packages(c("shinyFeedback", "shinyWidgets", "shinydashboard", "shinydashboardPlus", "ssh", "remotes", "markdown", "lubridate", "jsonlite", "dplyr", "DT", "glue", "httr", "purrr", "RColorBrewer", "rlang", "shinyBS", "shinyjs", "tidyverse", "uuid", "memoise", "rclipboard", "shinyvalidate", "shinylogs", "testhat", "bsicons", "listviewer", "cookies", "RMariaDB", "DBI"), repos="https://cran.r-project.org")'

RUN R -q -e "remotes::install_github('getwilds/proofr@v0.2')"
RUN R -q -e "remotes::install_github('getwilds/proofr@v0.3.0')"

RUN R -q -e "remotes::install_github('getwilds/[email protected]')"
RUN R -q -e "remotes::install_github('getwilds/[email protected]')"

ADD .my.cnf /root/

# python wdl2mermaid setup:
RUN pip install git+https://github.com/chanzuckerberg/miniwdl-viz.git

RUN R -q -e "remotes::install_github('timelyportfolio/reactR')"

RUN rm -rf /srv/shiny-server/
COPY app/ /srv/shiny-server/
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RSCRIPT = Rscript --no-init-file
FILE_TARGET := "${FILE}"
DEPS := $(shell ${RSCRIPT} -e 'invisible(lapply(c("glue", "cli"), require, character.only = TRUE, quiet = TRUE))' -e 'deps = renv::dependencies(quiet = TRUE)' -e 'uniq_pkgs = sort(unique(deps$$Package))' -e 'uniq_pkgs = uniq_pkgs[!grepl("^proofr$$|^rcromwell$$", uniq_pkgs)]' -e 'cat(c("getwilds/proofr@v0.2", "getwilds/rcromwell@v3.2.1", uniq_pkgs), file="deps.txt", sep="\n")')
DEPS := $(shell ${RSCRIPT} -e 'invisible(lapply(c("glue", "cli"), require, character.only = TRUE, quiet = TRUE))' -e 'deps = renv::dependencies(quiet = TRUE)' -e 'uniq_pkgs = sort(unique(deps$$Package))' -e 'uniq_pkgs = uniq_pkgs[!grepl("^proofr$$|^rcromwell$$", uniq_pkgs)]' -e 'cat(c("getwilds/proofr@v0.3.0", "getwilds/rcromwell@v3.3.0", uniq_pkgs), file="deps.txt", sep="\n")')

run:
${RSCRIPT} -e "options(shiny.autoreload = TRUE)" \
Expand All @@ -10,6 +10,11 @@ run_docker:
docker build --platform linux/amd64 -t shiny-cromwell:app .
docker run --rm -it -p 3838:3838 shiny-cromwell:app

# use: `make branch=inputs-viewer run_branch`
run_branch:
docker pull nexus-registry.fredhutch.org/scicomp-nexus/shiny-cromwell:$(branch)
docker run --rm -it -p 3838:3838 nexus-registry.fredhutch.org/scicomp-nexus/shiny-cromwell:$(branch)

# use: `make style_file FILE=stuff.R`
# accepts 1 file only
style_file:
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can run this Shiny app locally. First you'll need to install required packag
(note: run `make pkg_deps_cmd` to update the below code block)

```r
pak::pak(c("getwilds/proofr@v0.2", "getwilds/rcromwell@v3.2.1", "dplyr", "DT", "ggplot2", "glue", "httr", "jsonlite", "lubridate", "magrittr", "memoise", "purrr", "rclipboard", "RColorBrewer", "rlang", "shiny", "shinyBS", "shinydashboard", "shinydashboardPlus", "shinyFeedback", "shinyjs", "shinylogs", "shinyvalidate", "shinyWidgets", "testthat", "tibble", "uuid"))
pak::pak(c("getwilds/proofr@v0.3.0", "getwilds/rcromwell@v3.3.0", "dplyr", "DT", "ggplot2", "glue", "httr", "jsonlite", "lubridate", "magrittr", "memoise", "purrr", "rclipboard", "RColorBrewer", "rlang", "shiny", "shinyBS", "shinydashboard", "shinydashboardPlus", "shinyFeedback", "shinyjs", "shinylogs", "shinyvalidate", "shinyWidgets", "testthat", "tibble", "uuid"))
```

And the above yourself in R.
Expand All @@ -38,6 +38,20 @@ Note that CTRL+C doesn't work to kill the container after running `make run_dock

Also note that docker commands can be specific to the host operating system, so if you run into errors you may need to modify the docker commands.

#### Run a feature branch locally

The make command `make run_branch` will run a remote branch locally on your machine. Whereas `make run_docker` runs the current branch you're on, `make run_branch` pulls down a docker image of the remote branch specified and runs that.

Make sure to run `docker login nexus-registry.fredhutch.org` before you try this make command. You only need to run this once.
Contact `scicomp` to get the username and password for this step.

A full example: `make branch=inputs-viewer run_branch`

Note that the branch specification has to be before the target name (`run_branch`).

You must be on FH campus or be on a VPN to use this make command.


### Debugging

- Use print statements as needed ...
Expand Down
67 changes: 67 additions & 0 deletions app/cookies-db.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
library(RMariaDB)
library(DBI)

COOKIE_EXPIRY_DAYS <- 14

to_base64 <- function(x) {
base64enc::base64encode(charToRaw(x))
}
from_base64 <- function(x) {
rawToChar(base64enc::base64decode(x))
}

db <- dbConnect(RMariaDB::MariaDB(), group = "shinycromwell")
if (!dbExistsTable(db, "users")) {
db_columns <- c(
user = "TEXT",
proof_token = "TEXT",
cromwell_url = "TEXT",
login_time = "TEXT"
)
dbCreateTable(db, "users", db_columns)
}
dbDisconnect(db)

make_db_con <- function() {
dbConnect(RMariaDB::MariaDB(), group = "shinycromwell")
}

user_from_db <- function(user, conn = make_db_con(), expiry = COOKIE_EXPIRY_DAYS) {
on.exit(dbDisconnect(conn))
dbReadTable(conn, "users") %>%
as_tibble() %>%
filter(
# !! needed to get the value of the variable
user == !!user,
login_time > now() - days(expiry)
) %>%
arrange(desc(login_time))
}
user_to_db <- function(user, token, url, drop_existing = FALSE, conn = make_db_con()) {
on.exit(dbDisconnect(conn))
# drop before inserting so we only have 1 row/user
if (drop_existing) {
# don't drop if user is empty
if (nzchar(user)) {
# don't disconnect from within drop fun
user_drop_from_db(user, disconnect = FALSE, conn = conn)
}
}
tibble(
user = user,
proof_token = token,
cromwell_url = url,
login_time = as.character(now())
) %>%
dbWriteTable(conn, "users", ., append = TRUE)
}
user_drop_from_db <- function(user, disconnect = TRUE, conn = make_db_con()) {
if (disconnect) {
on.exit(dbDisconnect(conn))
}
sql_delete <- glue::glue_sql("
DELETE from users
WHERE user = {user}
", .con = conn)
dbExecute(conn, sql_delete)
}
Loading

0 comments on commit cd3946a

Please sign in to comment.