From 43dd193379feaceebb9df165d4132c865d632ef7 Mon Sep 17 00:00:00 2001 From: ymarcon Date: Mon, 6 Jan 2025 13:46:25 +0100 Subject: [PATCH] feat: docker file and R bin --- .github/workflows/publish-app-container.yml | 55 +++++++++++++++++++++ Dockerfile | 26 ++++++++++ Makefile | 5 ++ R/app.R | 6 +++ R/install.R | 23 +++++++++ README.md | 5 ++ 6 files changed, 120 insertions(+) create mode 100644 .github/workflows/publish-app-container.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 R/app.R create mode 100644 R/install.R create mode 100644 README.md diff --git a/.github/workflows/publish-app-container.yml b/.github/workflows/publish-app-container.yml new file mode 100644 index 0000000..b2c664d --- /dev/null +++ b/.github/workflows/publish-app-container.yml @@ -0,0 +1,55 @@ +name: Docker Shiny App + +on: + push: + # Publish `main` as Docker `latest` image. + branches: + - main + + # Publish `v1.2.3` tags as releases. + tags: + - v* + +env: + IMAGE_NAME: airspec-app + +jobs: + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + lfs: true + + - name: Build image + run: docker build backend --tag $IMAGE_NAME + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2427aeb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Use the R Shiny base image +FROM rocker/shiny:latest + +# Install R packages +COPY R/install.R /srv +RUN Rscript /srv/install.R + +# Copy your app into the container +COPY R/app.R /srv/shiny-server/ + +# Create a new user +RUN useradd -m -u 1000 shiny_user \ + && chown -R shiny_user:shiny_user /srv/shiny-server + +# Set proper permissions +RUN chown -R shiny_user:shiny_user /usr/local/lib/R/site-library/AIRSpec/ShinyApp/ + +# Switch to non-root user +USER shiny_user + +# Make the app available at port 3838 +EXPOSE 3838 + +# Run the app +#CMD ["/usr/bin/shiny-server"] +CMD ["Rscript", "/srv/shiny-server/app.R"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d152ff7 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +build: + docker build --pull --no-cache=false -t airspec-app . + +run: + docker run -p 3838:3838 airspec-app \ No newline at end of file diff --git a/R/app.R b/R/app.R new file mode 100644 index 0000000..18634f5 --- /dev/null +++ b/R/app.R @@ -0,0 +1,6 @@ +library(shiny) +library(methods) +library(AIRSpec) + +AIRSPECDir <- "/usr/local/lib/R/site-library/AIRSpec/ShinyApp/" +runApp(appDir = AIRSPECDir, host = "0.0.0.0", port = 3838) \ No newline at end of file diff --git a/R/install.R b/R/install.R new file mode 100644 index 0000000..9f30d22 --- /dev/null +++ b/R/install.R @@ -0,0 +1,23 @@ +#pkglist <- c("AIRSpec", "Rfunctools", "APRLspec", "APRLmpf", "APRLmvr", "APRLssb") +# pkglist <- c("AIRSpec", "APRLspec", "APRLmpf", "APRLmvr", "APRLssb") +# +# for (pkg in pkglist) { +# print(paste("Installing package:", pkg, "...")) +# remotes::install_gitlab(sprintf('aprl/%s', pkg), dependencies = TRUE) +# } + +extras <- c("RSQLite", "RJSONIO", "tidyverse", "shinythemes", "purrr", "shiny", "pls", "grDevices", "envDocument", "reshape2", "pryr", "Hmisc", "quantreg", "abind", "remotes") +for (p in extras) { + install.packages(p) +} + +url <- "https://www.dropbox.com/scl/fo/zcvv8xhvjg1wgad6gwep2/ABJGNldXXWS1z_w0_IuNHxk?rlkey=ch45dvbwcmohu6csa3eqxonn0&e=2&dl=1" +destzip <- file.path(tempdir(), "AIRSpec_packages.zip") +download.file(url, destzip) +destfolder <- file.path(tempdir(), "AIRSpec_packages") +unzip(destzip, exdir = destfolder) + +pkglist <- c("AIRSpec", "Rfunctools", "APRLspec", "APRLmpf", "APRLmvr", "APRLssb") +for (pkg in pkglist) { + remotes::install_local(file.path(destfolder, pkg), dependencies = TRUE, force = TRUE) +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1b286be --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# AIRSpec + +R Shiny app exposing Tools for Aerosol InfraRed Spectroscopy. + +See [https://airspec.epfl.ch](https://airspec.epfl.ch). \ No newline at end of file