Skip to content

Commit

Permalink
29 container image for tracking memory usage (#40)
Browse files Browse the repository at this point in the history
* Adding valgrind container

* to revert - run build

* completing exclusion criteria

* fixing path to R installation

* single include for valgrind

* to revert - targeting only valgrind

* fixing wrong R path

* adding DrMemory

* fixing path

* minor cleaning up

* make it executable
  • Loading branch information
j-i-l authored Jun 23, 2024
1 parent fae40b5 commit 8e158b0
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 22 deletions.
59 changes: 37 additions & 22 deletions .github/workflows/create-publish-docker.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Create Docker image and publish to GH Packages

on:
push:
pull_request:
branches: [ main ] # create a new version whenever we push to main
schedule:
- cron: "12 2 2 * *" # run at 2:12 of the 2nd of every month

env:
DOCKER_REGISTRY: ghcr.io # where to register the image
Expand All @@ -13,6 +11,8 @@ env:
# Set the path to the package where the DESCRIPTION file can be found
PACKAGE_PATH: ${{ vars.PACKAGE_PATH || './' }}
JAGS: JAGS-4.3.2
# this if for the valgrind container only
DRMEMORY: "2.6.0"
CHGLOG_RELEASE: git-chglog_0.15.4_linux_amd64
CHGLOG_PATH: https://github.com/git-chglog/git-chglog/releases/download/v0.15.4

Expand Down Expand Up @@ -45,18 +45,26 @@ jobs:
strategy:
fail-fast: false
matrix:
target-os: ['debian', 'fedora']
# NOTE: valgrind container is fedora, gcc, devel
# see https://r-hub.github.io/containers/containers.html#valgrind
# target-os: ['debian', 'fedora']
target-os: ['debian']
compiler: ['gcc', 'clang']
r-version: ['devel', 'release', 'patched']
exclude:
- target-os: 'fedora'
r-version: 'release'
- target-os: 'fedora'
r-version: 'patched'
- compiler: 'clang'
r-version: 'patched'
- compiler: 'clang'
r-version: 'release'
- target-os: 'debian'
# - target-os: 'fedora'
# r-version: 'release'
# - target-os: 'fedora'
# r-version: 'patched'
# - compiler: 'clang'
# r-version: 'patched'
# - compiler: 'clang'
# r-version: 'release'
include:
- target-os: 'valgrind'
compiler: 'gcc'
r-version: 'devel'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -95,7 +103,8 @@ jobs:
R_VERSION=${{ matrix.r-version }}
PACKAGE_PATH=${{ env.PACKAGE_PATH}}
REPO_PATH=${{ env.REPO_PATH }}
JAGS=${{ env.JAGS}}
JAGS=${{ env.JAGS }}
DRMEMORY=${{ env.DRMEMORY }}
# For private repo cloned via ssh
# secret-files: |
# key=./ssh_key
Expand All @@ -113,18 +122,24 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
target-os: ['debian', 'fedora']
# target-os: ['debian', 'fedora']
target-os: ['debian']
compiler: ['gcc', 'clang']
r-version: ['devel', 'release', 'patched']
exclude:
- target-os: 'fedora'
r-version: 'release'
- target-os: 'fedora'
r-version: 'patched'
- compiler: 'clang'
r-version: 'patched'
- compiler: 'clang'
r-version: 'release'
- target-os: 'debian'
# - target-os: 'fedora'
# r-version: 'release'
# - target-os: 'fedora'
# r-version: 'patched'
# - compiler: 'clang'
# r-version: 'patched'
# - compiler: 'clang'
# r-version: 'release'
include:
- target-os: 'valgrind'
compiler: 'gcc'
r-version: 'devel'
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down
119 changes: 119 additions & 0 deletions containers/valgrind/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Before the build stage
ARG TARGET_OS
ARG COMPILER
ARG R_VERSION

# For the valgrind container, target_os, compiler and r_vresion are not specified
# Hovever, the valgrind container is fedora, gcc, devel
# see https://r-hub.github.io/containers/containers.html#valgrind
FROM rhub/${TARGET_OS}

# Build stage: ARGs need to be redeclared
ARG TARGET_OS
ARG COMPILER
ARG R_VERSION
# ARG PACKAGE
ARG PACKAGE_PATH
ARG REPO_PATH
ARG JAGS
ARG DRMEMORY
# # sets the date for the CRAN snapshot (e.g. BUILD_DATE=2023-12-20)
# ARG BUILD_DATE

# Update package repositories
RUN dnf check-update && dnf -y install \
openssl-devel \
libcurl-devel

# Install dependencies for DrMemory
RUN dnf -y install libunwind
# Install DrMemory
ADD https://github.com/DynamoRIO/drmemory/releases/download/release_$DRMEMORY/DrMemory-Linux-$DRMEMORY.tar.gz /tmp/drmemory.tar.gz
WORKDIR /tmp/
RUN mkdir -p /opt/DrMemory
RUN tar -xf drmemory.tar.gz --directory /opt/DrMemory
RUN rm drmemory.tar.gz
# add DrMemory to PATH
RUN chmod 755 /opt/DrMemory/DrMemory-Linux-$DRMEMORY/bin/drmemory
ENV PATH="/opt/DrMemory/DrMemory-Linux-$DRMEMORY/bin:${PATH}"

# add R to PATH
ENV PATH="/opt/R/devel-valgrind/bin:${PATH}"

# diff to debian: /lib/ > /lib64/
# ENV PATH "$PATH:/opt/R-devel/bin/"
# Set a mirror for CRAN
RUN RPATH=/opt/R/devel-valgrind \
&& echo 'options(repos =c(CRAN = "https://cran.rstudio.com"))' >> ${RPATH}/lib/R/library/base/R/Rprofile

# rjags:
RUN dnf -y install \
lapack* blas* atlas*
ADD https://sourceforge.net/projects/mcmc-jags/files/JAGS/4.x/Source/$JAGS.tar.gz/download /tmp/jags.tar.gz
WORKDIR /tmp/
RUN tar -xf jags.tar.gz
RUN rm jags.tar.gz
WORKDIR /tmp/$JAGS
# Building JAGS requires the same environment that is then used to build rjags.
# To achieve this we follow the approach for building JAGS with Clang outlined
# in the JAGS installation guide
# (https://usermanual.wiki/Document/jagsinstallationmanual.880863585.pdf)
# and substitute the compilers with the specifics from the R installation that
# we can get by using the `R CMD config CC/CXX/BLAS_LIBS/LAPACK_LIBS' commands:
RUN if [ "$COMPILER" = "clang" ]; then RCC=/usr/bin/clang RCXX="/usr/bin/clang++ -std=gnu++17 -stdlib=libc++"; else RRCC=/usr/bin/gcc RCXX="/usr/bin/g++"; fi \
&& LD="llvm-ld" CC="${RCC}" CXX="${RCXX}" ./configure --with-blas="-L/opt/R/devel-valgrind/lib/R/lib -lRblas" --with-lapack="-L/opt/R/devel-valgrind/lib/R/lib -lRlapack" --libdir=/usr/local/lib && make && make install
RUN ls /tmp/$JAGS
# ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# RUN R -e "install.packages('rjags')"
RUN R -e "install.packages('rjags', configure.args = '--enable-rpath')"

# Get and install packages for local debugging
RUN R -e "install.packages('devtools')" \
&& R -e "install.packages('remotes')" \
&& R -e "install.packages('R.rsp')" \
&& R -e "install.packages('renv')" \
&& R -e "install.packages('desc')"

# Prepare for potential check to be run
RUN R -e "install.packages('urlchecker')"

# Install dependencies not managed by CRAN
# - lme4 and gsl:
RUN dnf -y install \
gsl-devel \
sqlite-devel \
NLopt-devel
# RUN R -e "install.packages('lme4')"
# RUN R -e "install.packages('gsl')"

# Graphviz
RUN R -e "install.packages('BiocManager')" \
&& R -e "BiocManager::install('Rgraphviz')"

# INLA
# - sf
RUN dnf -y install \
udunits2-devel gdal-devel geos-devel proj-devel
# RUN R -e "install.packages('sf')"
# - fmesher
RUN dnf -y install \
udunits2-devel
# RUN R -e "install.packages('fmesher')"
# - INLA
RUN R -e "install.packages('INLA',repos=c(getOption('repos'),INLA='https://inla.r-inla-download.org/R/stable'), dep=TRUE)"

###
# install all package dependencies
###
RUN dnf -y install \
git \
openssh-clients
WORKDIR /root/
# get a shallow copy of the target repository
# # Note: If the repository is private you must use a deploy token here (ssh key)
# RUN --mount=type=secret,id=key,dst=/root/.ssh/key GIT_SSH_COMMAND="ssh -i /root/.ssh/key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone --depth=1 git@$REPO_PATH target
RUN git clone --depth=1 https://$REPO_PATH target
WORKDIR target/
# get a list of all dependencies; install remaining packages
# escape=\
RUN R -e "renv::deactivate();pckgs<-unique(renv::dependencies('$PACKAGE_PATH')[,'Package']);pres_pckgs<-installed.packages()[,'Package'];install.packages(pckgs[!(pckgs %in% pres_pckgs)])"

0 comments on commit 8e158b0

Please sign in to comment.