Skip to content

Commit

Permalink
Adding Docker building and galaxy wrapping GHA (#1)
Browse files Browse the repository at this point in the history
* Add shiny Dockerfile
  • Loading branch information
almahmoud authored Jan 12, 2024
1 parent 4b1cfbf commit fbf552d
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 14 deletions.
27 changes: 27 additions & 0 deletions .github/scripts/galaxy-wrapper-template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<tool id="interactivetool_biocshiny_{{{ID}}}" tool_type="interactive" name="{{{NAME}}}" version="0.1">
<description>{{{NAME}}} BiocShiny App</description>
<requirements>
<container type="docker">{{{CONTAINER}}}</container>
</requirements>
<entry_points>
<entry_point name="{{{ID}}}" requires_domain="True">
<port>3838</port>
</entry_point>
</entry_points>
<environment_variables>
<environment_variable name="HISTORY_ID">$__history_id__</environment_variable>
<environment_variable name="REMOTE_HOST">$__galaxy_url__</environment_variable>
<environment_variable name="GALAXY_URL">$__galaxy_url__</environment_variable>
<environment_variable name="API_KEY" inject="api_key" />
</environment_variables>
<command detect_errors="aggressive">/init</command>
<inputs>
</inputs>
<outputs>
</outputs>
<tests>
</tests>
<help>
This is an auto-generated wrapper for a BiocShiny application. See source and report issues at {{{SOURCE}}}.
</help>
</tool>
62 changes: 62 additions & 0 deletions .github/workflows/build_container.yaml
Original file line number Diff line number Diff line change
@@ -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 [email protected]
git add galaxy-wrapper.xml
git commit -m "Update Galaxy Wrapper $(TZ=EST date '+%Y-%m-%d_%H-%M')"
git push
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]",
c("aut", "cre"), c(ORCID = "0000-0002-3242-0582")
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

26 changes: 14 additions & 12 deletions R/BiocWorkshopSubmit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions galaxy-wrapper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<tool id="interactivetool_biocshiny_biocworkshopsubmit" tool_type="interactive" name="BiocWorkshopSubmit" version="0.1">
<description>BiocWorkshopSubmit BiocShiny App</description>
<requirements>
<container type="docker">ghcr.io/almahmoud/biocworkshopsubmit:devel</container>
</requirements>
<entry_points>
<entry_point name="biocworkshopsubmit" requires_domain="True">
<port>3838</port>
</entry_point>
</entry_points>
<environment_variables>
<environment_variable name="HISTORY_ID">$__history_id__</environment_variable>
<environment_variable name="REMOTE_HOST">$__galaxy_url__</environment_variable>
<environment_variable name="GALAXY_URL">$__galaxy_url__</environment_variable>
<environment_variable name="API_KEY" inject="api_key" />
</environment_variables>
<command detect_errors="aggressive">/init</command>
<inputs>
</inputs>
<outputs>
</outputs>
<tests>
</tests>
<help>
This is an auto-generated wrapper for a BiocShiny application. See source and report issues at https://github.com/almahmoud/BiocWorkshopSubmit.
</help>
</tool>

0 comments on commit fbf552d

Please sign in to comment.