Skip to content

Commit

Permalink
i hate putting everything in a new repo
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchard committed Nov 29, 2024
0 parents commit 264e056
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
AUTHOR: Marc Suchard <[email protected]>

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 }}
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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)"
57 changes: 57 additions & 0 deletions app.R
Original file line number Diff line number Diff line change
@@ -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"
)
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 264e056

Please sign in to comment.