Skip to content

Commit

Permalink
Add tests before Docker builds, general clean up (#2)
Browse files Browse the repository at this point in the history
* clean up requirements
* clean up lasso experiment remnants
* sync package loading with req.txt file
* fix checkInstalledPackages
* clean up redundant code to check and install packages
* clean up server.R
* cleaned req.txt
* clean up main directory
* set up tests for mzML and Bruker file loading
* add test that checks if processing was successful
* activate GHA caching
* update GHA to use versions instead of hashes
* removed more left overs from LASSO experiment
* remove library() calls from individual functions
  • Loading branch information
thomas-enzlein committed May 28, 2024
1 parent 8a34f20 commit 4c26569
Show file tree
Hide file tree
Showing 34 changed files with 309 additions and 620 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
78 changes: 46 additions & 32 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
push:
branches:
branches:
- main
- dev
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches:
branches:
- main
- dev

env:
# Use docker.io for Docker Hub if empty
REGISTRY: docker.io
# github.repository as <account>/<repo>
IMAGE_NAME: thomasenzlein/m2ara

GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
Expand All @@ -31,51 +23,73 @@ jobs:
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 #v3.1.1
# Set up R environment
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
cosign-release: 'v2.1.1'
r-version: '4.4.0'

# Install system dependencies for R packages
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get -y install libcurl4-openssl-dev libssl-dev libxml2-dev build-essential libxml2-dev libgit2-dev libudunits2-dev librsvg2-dev tk libharfbuzz-dev libfribidi-dev
# Install R package dependencies from req.txt
- name: Install R packages from req.txt
run: |
R -e "install.packages('devtools')"
R -e "devtools::install_github('CeMOS-Mannheim/MALDIcellassay')"
R -e "packages <- readLines('req.txt'); install.packages(packages)"
# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
# Install testthat if it's not listed in req.txt
- name: Install testthat
run: R -e "if (!require('testthat')) install.packages('testthat')"

# Run tests
- name: Run tests
run: R -e "source('tests/testthat.R')"

# This step will be skipped if the tests fail
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
uses: docker/setup-buildx-action@v3.3.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.dockeriouser }}
password: ${{ secrets.dockeriopwd }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Create cache directory
run: mkdir -p /tmp/.buildx-cache

- name: Cache Docker layers
id: cache-docker-layers
uses: actions/cache@v4.0.2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
uses: docker/build-push-action@v5.3.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
Expand Down
28 changes: 13 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny-verse:latest

# copy necessary files
## renv.lock file
#COPY ./renv.lock ./renv.lock
## app folder
COPY ./ ./app
RUN apt-get update && apt-get install -y \
sudo \
libudunits2-dev \
librsvg2-dev \
tk

# install renv
#RUN Rscript -e 'install.packages("renv")'
# Copy the req.txt file to the Docker image
COPY req.txt /req.txt

# set renv library path
#ENV RENV_PATHS_LIBRARY renv/library
# Install R packages from req.txt
RUN R -e "packages <- readLines('/req.txt'); install.packages(packages)"

# restore packages
#RUN Rscript -e 'renv::restore()'
# Install the MALDIcellassay from GitHub
RUN R -e "devtools::install_github('CeMOS-Mannheim/MALDIcellassay')"

# install main package
RUN Rscript -e 'install.packages("devtools")'
RUN Rscript -e 'devtools::install_github("CeMOS-Mannheim/MALDIcellassay")'
RUN Rscript -e 'source("/app/install_packages.R")'
## copy app folder into container
COPY ./ ./app

# expose port
EXPOSE 3838
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="M2ara_Logo.png" alt="M²ara overview" width="100" height="100">
<img src="figures/M2ara_Logo.png" alt="M²ara overview" width="100" height="100">

# M²ara - MALDI MS Bioassays Evaluation and Classification App

Expand Down
Binary file removed Workflow_figure.png
Binary file not shown.
44 changes: 1 addition & 43 deletions app.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,6 @@
(function(req_file, install = T, update = F, silent = F) {

# Read text file containing required packages
if(!file.exists("req.txt")) {
warning("req.txt was not found. No packages installed or checked.")
return()
}

req <- scan(req_file, character(), quiet = T)

# Update packages
if (update) {
update.packages(repos = "https://cloud.r-project.org", ask = F)
}

# Install missing packages
if (length(req) > 0 & install) {
missing_packages <- req[!(req %in% installed.packages()[,"Package"])]
if (length(missing_packages) > 0) {
install.packages(
missing_packages,
repos = "https://cloud.r-project.org",
dependencies = T,
clean = T
)
}
}



# Load packages
if (silent) {
suppressPackageStartupMessages(invisible(lapply(req, library, character.only = T)))
} else {
lapply(req, library, character.only = T)
}


})("req.txt", silent = F)


# check if all required packages are installed

source("functions/checkInstalledPackages.R")
checkInstalledPackages()
checkInstalledPackages(req_file = "req.txt")

knit("manual.Rmd", quiet = TRUE)

Expand Down
67 changes: 0 additions & 67 deletions components/lassoTab.R

This file was deleted.

1 change: 0 additions & 1 deletion components/mainpanel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
source("components/mainTab.R")
source("components/qcTab.R")
source("components/pcaTab.R")
source("components/lassoTab.R")
source("components/hcTab.R")

appMainPanel <- function(defaults) {
Expand Down
1 change: 0 additions & 1 deletion components/qcTab.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ qcTab <- function() {
"Selected-mz",
"PC-x",
"PC-y",
"LASSO-error",
"Outlier-mz",
"Outlier-all"),
multiple = FALSE,
Expand Down
Loading

0 comments on commit 4c26569

Please sign in to comment.