From fbf552d6303a8c38d4dd6aeec08d4483d6689658 Mon Sep 17 00:00:00 2001 From: Alexandru Mahmoud Date: Fri, 12 Jan 2024 10:28:20 -0500 Subject: [PATCH] Adding Docker building and galaxy wrapping GHA (#1) * Add shiny Dockerfile --- .github/scripts/galaxy-wrapper-template.xml | 27 +++++++++ .github/workflows/build_container.yaml | 62 +++++++++++++++++++++ DESCRIPTION | 2 +- Dockerfile | 14 +++++ R/BiocWorkshopSubmit.R | 26 +++++---- R/utils.R | 2 +- galaxy-wrapper.xml | 27 +++++++++ 7 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 .github/scripts/galaxy-wrapper-template.xml create mode 100644 .github/workflows/build_container.yaml create mode 100644 Dockerfile create mode 100644 galaxy-wrapper.xml diff --git a/.github/scripts/galaxy-wrapper-template.xml b/.github/scripts/galaxy-wrapper-template.xml new file mode 100644 index 0000000..7c178d9 --- /dev/null +++ b/.github/scripts/galaxy-wrapper-template.xml @@ -0,0 +1,27 @@ + + {{{NAME}}} BiocShiny App + + {{{CONTAINER}}} + + + + 3838 + + + + $__history_id__ + $__galaxy_url__ + $__galaxy_url__ + + + /init + + + + + + + + This is an auto-generated wrapper for a BiocShiny application. See source and report issues at {{{SOURCE}}}. + + diff --git a/.github/workflows/build_container.yaml b/.github/workflows/build_container.yaml new file mode 100644 index 0000000..c2f584e --- /dev/null +++ b/.github/workflows/build_container.yaml @@ -0,0 +1,62 @@ +name: Build shiny Docker image and generate Galaxy wrapper +on: + workflow_dispatch: {} + push: {} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Extract metadata for container image + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value={{branch}} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + platforms: linux/amd64 + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push container image to ghcr + uses: docker/build-push-action@v4 + with: + file: Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + + - name: Set variables + id: vars + run: | + echo "container=${{ steps.meta.outputs.tags }}" >> $GITHUB_OUTPUT + echo "source=https://github.com/${{github.repository}}" >> $GITHUB_OUTPUT + NAME="$(echo '${{github.repository}}' | awk -F'/' '{print $2}')" + echo "name=$NAME" >> $GITHUB_OUTPUT + echo "id=$(echo $NAME | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + + - name: Generate wrapper + run: | + cp .github/scripts/galaxy-wrapper-template.xml galaxy-wrapper.xml + sed -i 's#{{{CONTAINER}}}#${{steps.vars.outputs.container}}#g' galaxy-wrapper.xml + sed -i 's#{{{SOURCE}}}#${{steps.vars.outputs.source}}#g' galaxy-wrapper.xml + sed -i 's#{{{NAME}}}#${{steps.vars.outputs.name}}#g' galaxy-wrapper.xml + sed -i 's#{{{ID}}}#${{steps.vars.outputs.id}}#g' galaxy-wrapper.xml + git config --global --add safe.directory "$GITHUB_WORKSPACE" + git config user.name github-actions + git config user.email github-actions@github.com + git add galaxy-wrapper.xml + git commit -m "Update Galaxy Wrapper $(TZ=EST date '+%Y-%m-%d_%H-%M')" + git push diff --git a/DESCRIPTION b/DESCRIPTION index c0ba822..9dacbd9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BiocWorkshopSubmit Type: Package Title: Provides a shiny app for workshop submissions -Version: 0.99.8 +Version: 0.99.9 Authors@R: person( "Marcel", "Ramos", , "marcel.ramosperez@roswellpark.org", c("aut", "cre"), c(ORCID = "0000-0002-3242-0582") diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d2d439 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM ghcr.io/bioconductor/shiny:devel as build + +RUN chown -R shiny /usr/local/lib/R/site-library && chown -R shiny /usr/local/lib/R/library && rm -rf /srv/shiny-server/sample-apps && curl -o /srv/shiny-server/index.html https://gist.githubusercontent.com/almahmoud/58261d03bfb342274f2e642c4b2ebc4d/raw/4e0271990bce57ae091f622db47b15f8fd89fa29/index.html && mkdir -p /srv/shiny-server/biocshiny && sed -i '/^run_as shiny;/a app_init_timeout 300;\napp_idle_timeout 300;' /etc/shiny-server/shiny-server.conf + +COPY --chown=shiny:shiny . /tmp/repo/ + +USER shiny + +RUN cd /tmp/repo && Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); BiocManager::install(ask=FALSE)" && Rscript -e "options(repos = c(CRAN = 'https://cran.r-project.org')); devtools::install('.', dependencies=TRUE, build_vignettes=TRUE, repos = BiocManager::repositories())" && rm -rf /tmp/repo + +COPY --chown=shiny:shiny app.R /srv/shiny-server/biocshiny/app.R + +USER root + diff --git a/R/BiocWorkshopSubmit.R b/R/BiocWorkshopSubmit.R index 07c9335..6f7aa87 100644 --- a/R/BiocWorkshopSubmit.R +++ b/R/BiocWorkshopSubmit.R @@ -5,8 +5,8 @@ '## READ ONLY: DO NOT EDIT ##', '/request', 'id="{{id}}"', 'title="{{title}}"', 'description="{{description}}"', 'section="{{section}}"', - 'startfile="{{startfile}}"', 'source="https://github.com/{{ghrepo}}"', - 'docker="{{url}}:{{tag}}"' + 'startfile="{{startfile}}"', 'source="{{gitrepo}}"', + 'docker="{{url}}:{{tag}}"', 'pkglist="{{pkglist}}"', 'vignettes="{{vignettes}}"' ) .ISSUE_GH_REPO <- "Bioconductor/workshop-contributions" @@ -43,9 +43,9 @@ appCSS <- paste( #' #' @export BiocWorkshopSubmit <- function(...) { - fieldsMandatory <- c("id", "title", "section", "ghrepo", "url") + fieldsMandatory <- c("id", "title", "section") fieldsAll <- c("id", "title", "description", "section", - "startfile", "ghrepo", "url", "tag") + "startfile", "gitrepo", "url", "tag", "pkglist", "vignettes") ui <- fluidPage( useShinyjs(), inlineCSS(appCSS), @@ -100,19 +100,21 @@ BiocWorkshopSubmit <- function(...) { ## TODO: point out workshop.bioconductor.org examples textInput("description", "Description"), textInput( - "ghrepo", - label = mandatory("GitHub Repository"), - placeholder = "username/repository" + "gitrepo", + label = "Git Repository", + placeholder = "https://github.com/username/repository" ), textInput( "startfile", "Start File", value = "README.md" ), textInput( "url", - label = mandatory("Container URL"), + label = "Container URL", placeholder = "ghcr.io/username/repo" ), - textInput("tag", "Container Tag", value = "latest"), + textInput("tag", "Container Tag", placeholder = "devel"), + textInput("pkglist", "Packages to pre-install", placeholder="S4Vectors,username/repo,GenomicRanges"), + textInput("vignettes", "Vignettes to add to container (comma sep.)", placeholder="Relative paths to vignettes or URL list e.g., vignettes/workshop.Rmd OR https://gist.githubusercontent.com/user/repo/vignettes/workshop.Rmd"), actionButton("render", "Render", class = "btn-primary") ), hr(), @@ -181,9 +183,9 @@ BiocWorkshopSubmit <- function(...) { server <- function(input, output, session) { observeEvent(input$presubmit, { - ghrepo <- input[["prepop"]] - updateTextInput(session, "ghrepo", value = ghrepo) - descfile <- read_gh_file(ghrepo) + gitrepo <- paste0("https://github.com/", input[["prepop"]]) + updateTextInput(session, "gitrepo", value = gitrepo) + descfile <- read_gh_file(input[["prepop"]]) title <- descfile[, "Title"] updateTextInput(session, "title", value = unname(title)) description <- .parse_description(descfile) diff --git a/R/utils.R b/R/utils.R index 59fdc80..a721668 100644 --- a/R/utils.R +++ b/R/utils.R @@ -55,7 +55,7 @@ create_gh_issue <- function(ghrepo, title, body) { } add_comment_gh_issue <- function(ghrepo, title, body, issue_number) { - ghrepo <- unlist(strsplit(ghrepo, "/", fixed = TRUE)) + ghrepo <- tail(unlist(strsplit(ghrepo, "/", fixed = TRUE)), 2L) names(ghrepo) <- c("owner", "repo") gh( "POST /repos/{owner}/{repo}/issues/{issue_number}/comments", diff --git a/galaxy-wrapper.xml b/galaxy-wrapper.xml new file mode 100644 index 0000000..17501b1 --- /dev/null +++ b/galaxy-wrapper.xml @@ -0,0 +1,27 @@ + + BiocWorkshopSubmit BiocShiny App + + ghcr.io/almahmoud/biocworkshopsubmit:devel + + + + 3838 + + + + $__history_id__ + $__galaxy_url__ + $__galaxy_url__ + + + /init + + + + + + + + This is an auto-generated wrapper for a BiocShiny application. See source and report issues at https://github.com/almahmoud/BiocWorkshopSubmit. + +