Skip to content

Commit

Permalink
perf: containerize the app and enabe gh actions to publish image
Browse files Browse the repository at this point in the history
  • Loading branch information
danlu1 committed Apr 10, 2023
1 parent 648e0cc commit 85fd8dc
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 543 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
- {os: macOS-latest, r: 'devel'}
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-18.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-18.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-18.04, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-latest, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-latest, r: '3.4', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand All @@ -35,13 +35,13 @@ jobs:
SYNAPSE_AUTH_TOKEN: ${{ secrets.SYNAPSE_PAT }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master
- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
Expand All @@ -62,7 +62,7 @@ jobs:
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y update
sudo apt-get install -y make python-minimal pandoc pandoc-citeproc git-core libv8-dev libxml2-dev libcurl4-openssl-dev libssl-dev libssh2-1-dev zlib1g-dev libgit2-dev
sudo apt-get install -y make python-is-python3 pandoc pandoc-citeproc git-core libv8-dev libxml2-dev libcurl4-openssl-dev libssl-dev libssh2-1-dev zlib1g-dev libgit2-dev
- name: Install system dependencies (macOS)
if: runner.os == 'macOS' && matrix.config.r == 'devel'
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/Release_Docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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 Github release and generate Docker image

on:
push:
branches:
- 'master'
tags:
- 'v*'
env:
REGISTRY: ghcr.io
IMAGE_PATH: ghcr.io/${{ github.repository }}

jobs:
tagging:
runs-on: ubuntu-latest
outputs:
tag: ${{steps.tag_version.outputs.new_tag}}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_release_rules: fix:patch:Bug Fixes,chore:patch:Chores,feat:minor:Features,perf:Major:Performance
- 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:
needs: tagging
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/[email protected]
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/[email protected]
with:
images: ${{ env.IMAGE_PATH }}
tags: ${{ needs.tagging.outputs.tag}}

- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags}}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v2

- name: Query dependencies
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@master
- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-pandoc@master
- uses: r-lib/actions/setup-pandoc@v2

- name: Query dependencies
run: |
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)"

# 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 dccvalidator_PEC_startup.sh
CMD ["./dccvalidator_PEC_startup.sh"]
2 changes: 1 addition & 1 deletion app.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# To deploy, run: rsconnect::deployApp()
# Or use the blue button on top of this file

Sys.setenv(R_CONFIG_ACTIVE = "pec") # Replace "default" with your config
Sys.setenv(R_CONFIG_ACTIVE = Sys.getenv("R_CONFIG_ACTIVE")) # Replace "default" with your config
pkgload::load_all()
options("golem.app.prod" = TRUE)
dccvalidator::run_app() # add parameters here (if any)
11 changes: 11 additions & 0 deletions dccvalidator_PEC_startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/bash

# Pass environment variable to Shiny
echo "" >> .Renviron
echo APP_REDIRECT_URL=$APP_REDIRECT_URL >> .Renviron
echo R_CONFIG_ACTIVE=$R_CONFIG_ACTIVE >> .Renviron
echo client_id=$client_id >> .Renviron
echo client_name=$client_name >> .Renviron
echo client_secret=$client_secret >> .Renviron
# Now run the base start-up script
./startup.sh
1 change: 0 additions & 1 deletion inst/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ amp-ad:
contact_email: "[email protected]"

pec:
app_url: "https://shinypro.synapse.org/users/danlu/dccvalidator/"
parent: "syn21763123"
path_to_markdown: "inst/using-the-dccvalidator-pec.Rmd"
study_table: "syn20968992"
Expand Down
Loading

0 comments on commit 85fd8dc

Please sign in to comment.