Skip to content

Commit

Permalink
feat: docker file and R bin
Browse files Browse the repository at this point in the history
  • Loading branch information
ymarcon committed Jan 6, 2025
1 parent 195f7d9 commit 43dd193
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/publish-app-container.yml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
docker build --pull --no-cache=false -t airspec-app .

run:
docker run -p 3838:3838 airspec-app
6 changes: 6 additions & 0 deletions R/app.R
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions R/install.R
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# AIRSpec

R Shiny app exposing Tools for Aerosol InfraRed Spectroscopy.

See [https://airspec.epfl.ch](https://airspec.epfl.ch).

0 comments on commit 43dd193

Please sign in to comment.