diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..aa45d8f --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,77 @@ +name: build-and-push-ohdsi-docker-image-to-Docker-Hub + +# on: +# release: +# types: [published] +# workflow_dispatch: + +on: [push] + +env: + APP_NAME: EstimationTutorial # the Shiny application name in the OHDSI ShinyProxyDeploy gitHub repo application.yml file + DOCKER_IMAGE: ohdsi/estimationtutorial + MAINTAINER: Marc Suchard + AUTHOR: Marc Suchard + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: ${{ env.DOCKER_IMAGE }} + tag-match: v(.*) + tag-match-group: 1 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build Docker image and push to Docker Hub + id: build_and_push + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache,mode=max + platforms: linux/amd64,linux/arm64 + push: true + secrets: | + build_github_pat=${{ secrets.GH_TOKEN }} + build-args: | + APP_NAME=${{ env.APP_NAME }} + GIT_BRANCH=${{ steps.docker_meta.outputs.version }} + GIT_COMMIT_ID_ABBREV=${{ steps.build_params.outputs.sha8 }} + tags: ${{ steps.docker_meta.outputs.tags }} + labels: | + ${{ steps.docker_meta.outputs.labels }} + maintainer=${{ env.MAINTAINER }} + org.opencontainers.image.authors=${{ env.AUTHOR }} + org.opencontainers.image.vendor=OHDSI + org.opencontainers.image.licenses=Apache-2.0 + + - name: Inspect Docker image + run: | + docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} + docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f514c33 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# get shiny server and R from the rocker project +FROM ohdsi/broadsea-shiny:1.0.0 + +# JNJ Specific +# RUN apt-get install -y ca-certificates +# COPY ZscalerRootCA.crt /root/ZscalerRootCA.crt +# RUN cat /root/ZscalerRootCA.crt >> /etc/ssl/certs/ca-certificates.crt +# COPY ZscalerRootCA.crt /usr/local/share/ca-certificates +# RUN update-ca-certificates + +# Set an argument for the app name and port +ARG APP_NAME +ARG SHINY_PORT + +# Set arguments for the GitHub branch and commit id abbreviation +ARG GIT_BRANCH=unknown +ARG GIT_COMMIT_ID_ABBREV=unknown + +# system libraries +# Try to only install system libraries you actually need +# Package Manager is a good resource to help discover system deps +RUN apt-get update && \ + apt-get install -y python3-pip && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# install R packages required +RUN R -e 'install.packages(c("remotes", "rJava", "dplyr", "DatabaseConnector", "ggplot2", "plotly", "shinyWidgets", "shiny", "ResultModelManager"), repos="http://cran.rstudio.com/")' + +RUN R CMD javareconf + +# Set workdir and copy app files +WORKDIR /srv/shiny-server/${APP_NAME} + +# copy the app directory into the image +COPY ./app.R . + +RUN --mount=type=secret,id=build_github_pat \ + cp /usr/local/lib/R/etc/Renviron /tmp/Renviron \ + && echo "GITHUB_PAT=$(cat /run/secrets/build_github_pat)" >> /usr/local/lib/R/etc/Renviron \ + && R -e "remotes::install_github('OHDSI/ShinyAppBuilder', ref='v3.1.0')" \ + && R -e "remotes::install_github('OHDSI/OhdsiShinyModules', ref='v3.1.0')" \ + && cp /tmp/Renviron /usr/local/lib/R/etc/Renviron + +ENV DATABASECONNECTOR_JAR_FOLDER /root +RUN R -e "DatabaseConnector::downloadJdbcDrivers('postgresql', pathToDriver='/root')" + +# run app +EXPOSE 3838 +CMD R -e "shiny::runApp('./', host = '0.0.0.0', port = 3838)" diff --git a/app.R b/app.R new file mode 100644 index 0000000..5a947a3 --- /dev/null +++ b/app.R @@ -0,0 +1,57 @@ +################################################################################ +# INSTRUCTIONS: The code below assumes you uploaded results to a PostgreSQL +# or SQLite database per the UploadResults.R script.This script will launch a +# Shiny results viewer to analyze results from the study. +# +# See the Working with results section +# of the UsingThisTemplate.md for more details. +# +# More information about working with results produced by running Glp1Dili +# is found at: +# https://ohdsi.github.io/Glp1Dili/articles/WorkingWithResults.html +# ############################################################################## + +library(ShinyAppBuilder) +library(OhdsiShinyModules) + +shinyConfig <- initializeModuleConfig() |> + addModuleConfig( + createDefaultAboutConfig() + ) |> + addModuleConfig( + createDefaultDatasourcesConfig() + ) |> + addModuleConfig( + createDefaultCohortGeneratorConfig() + ) |> + addModuleConfig( + createDefaultCohortDiagnosticsConfig() + ) |> + addModuleConfig( + createDefaultCharacterizationConfig() + ) |> + addModuleConfig( + createDefaultPredictionConfig() + ) |> + addModuleConfig( + createDefaultEstimationConfig() + ) + +cli::cli_h1("Starting shiny server") +serverStr <- paste0(Sys.getenv("shinydbServer"), "/", Sys.getenv("shinydbDatabase")) +cli::cli_alert_info("Connecting to {serverStr}") +connectionDetails <- DatabaseConnector::createConnectionDetails( + dbms = "postgresql", + server = serverStr, + port = Sys.getenv("shinydbPort"), + user = "marc", + password = Sys.getenv("shinydbPw") +) + +cli::cli_h2("Loading schema") +ShinyAppBuilder::createShinyApp( + config = shinyConfig, + connectionDetails = connectionDetails, + resultDatabaseSettings = createDefaultResultDatabaseSettings(schema = "strategus_tutorial"), + title = "Population-level Estimation Tutorial with Strategus" +) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..be10a13 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' +services: + estimationtutorial: + image: ohdsi/estimationtutorial:1.0.0 + env_file: .env + build: + context: . + args: + APP_NAME: EstimationTutorial + ports: + - "3838:3838"