Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

def files, bash scipts for containers, testing yaml #369

Merged
merged 15 commits into from
Oct 1, 2024
Merged
73 changes: 73 additions & 0 deletions .github/workflows/test-container-dl-calc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Test Coverage for Download and Calculate via Apptainer

on:
push:
branches: [main, master, dev]
pull_request:
branches: [main, master, dev]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create run_dl_calc_tests.R dynamically
run: |
mkdir -p tests/testthat # Ensure the directory exists
echo 'testthat::test_file("tests/testthat/test_download.R")' > tests/testthat/run_dl_calc_tests.R
echo 'testthat::test_file("tests/testthat/test_calculate.R")' >> tests/testthat/run_dl_calc_tests.R

- name: Install Apptainer dependencies
run: |
sudo apt-get update && sudo apt-get install -y \
libseccomp-dev \
squashfs-tools \
cryptsetup \
wget

- name: Install Apptainer
run: |
wget https://github.com/apptainer/apptainer/releases/download/v1.1.0/apptainer-1.1.0.tar.gz
tar -xvf apptainer-1.1.0.tar.gz
cd apptainer-1.1.0
./mconfig && make -C builddir && sudo make -C builddir install

- name: Restore .sif file from cache
id: cache-sif
uses: actions/cache@v3
with:
path: beethoven_dl_calc.sif
key: sif-cache-${{ runner.os }}-${{ hashFiles('container/beethoven_dl_calc.def') }}
restore-keys: |
sif-cache-${{ runner.os }}-

- name: Build the Apptainer container (if cache miss)
if: steps.cache-sif.outputs.cache-hit != 'true'
run: |
apptainer build --fakeroot beethoven_dl_calc.sif container/beethoven_dl_calc.def

- name: Cache the .sif file
if: steps.cache-sif.outputs.cache-hit != 'true'
uses: actions/cache@v3
with:
path: beethoven_dl_calc.sif
key: sif-cache-${{ runner.os }}-${{ hashFiles('container/beethoven_dl_calc.def') }}

- name: Check if .sif file exists
run: |
if [ ! -f beethoven_dl_calc.sif ]; then
echo "Error: .sif file not found!"
exit 1
fi

- name: Run R tests
run: |
apptainer exec \
--bind $PWD/inst:/pipeline \
--bind $PWD/input:/input \
--bind $PWD:/mnt \
beethoven_dl_calc.sif \
Rscript /mnt/tests/testthat/run_dl_calc_tests.R
6 changes: 1 addition & 5 deletions container/beethoven_dl_calc.def
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
BootStrap: docker
From: rocker/geospatial:latest

%files
/ddn/gs1/tools/set/R432/lib64/R/library /R_packages


%post
# Update package list
apt-get update
Expand All @@ -27,7 +23,7 @@ From: rocker/geospatial:latest
mkdir /input
mkdir /opt/_targets

Rscript -e "install.packages(c('pak','targets','tarchetypes','crew','crew.cluster'))"
Rscript -e "install.packages(c('pak','targets','tarchetypes','crew','crew.cluster','testthat'))"
Rscript -e "pak::pkg_install('NIEHS/amadeus')"
Rscript -e "remotes::install_github('NIEHS/beethoven')"

Expand Down
8 changes: 8 additions & 0 deletions container/build_dl_calc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# usage: build_apptainer_image.sh [full file path]
# where full file path ends with .sif, with full directory path to save the image
# after the image is built, group write/execution privileges are given

# Recommended to run this script interactively via `sh build_dl_calc.sh`
apptainer build --fakeroot beethoven_dl_calc.sif beethoven_dl_calc.def
23 changes: 23 additions & 0 deletions container/run_container_dl_calc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
#SBATCH --job-name=beethoven_001
#SBATCH --partition=geo
#SBATCH --mem=128G
#SBATCH --cpus-per-task=4
#SBATCH --ntasks=16
#SBATCH --output=slurm_messages/slurm-%j.out
#SBATCH --error=slurm_messages/slurm-%j.err
#SBATCH [email protected]
#SBATCH --mail-type=ALL




apptainer exec \
--bind $PWD/inst:/pipeline \
--bind $PWD/input:/input \
--bind $PWD/_targets:/opt/_targets \
--bind $PWD:/mnt \
beethoven_dl_calc.sif \
Rscript /mnt/run.R


23 changes: 23 additions & 0 deletions container/run_dl_calc_local_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
#SBATCH --job-name=dl_calc_tests
#SBATCH --partition=geo
#SBATCH --mem=128G
#SBATCH --cpus-per-task=4
#SBATCH --ntasks=16
#SBATCH --output=slurm_messages/slurm-%j.out
#SBATCH --error=slurm_messages/slurm-%j.err
#SBATCH [email protected]
#SBATCH --mail-type=ALL




apptainer exec \
--bind $PWD/../inst:/pipeline \
--bind $PWD/../input:/input \
--bind $PWD/../_targets:/opt/_targets \
--bind $PWD/..:/mnt \
beethoven_dl_calc.sif \
Rscript /mnt/tests/testthat/test_download.R


13 changes: 13 additions & 0 deletions tests/testthat/test_calculate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
################################################################################
##### unit and integration tests for covariate calculations
##### Currently arbitrary placeholders
#####

################################################################################
#####
testthat::test_that("calculate targets work", {

a <- 1
testthat::expect_equal(a, 1)

})
16 changes: 16 additions & 0 deletions tests/testthat/test_download.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
################################################################################
##### unit and integration tests for data download
##### Currently arbitrary placeholders
#####

################################################################################
##### loadargs
testthat::test_that("download targets work", {

a <- 1
testthat::expect_equal(a, 1)

b <- 2
testthat::expect_equal(b, 2)

})
Loading