From ad63258b11ef452119a2ab3f5fbc084c50d78294 Mon Sep 17 00:00:00 2001 From: avahoffman Date: Thu, 16 May 2024 22:39:26 -0400 Subject: [PATCH] Add anvil image --- ottr_anvil/Dockerfile | 78 ++++++++++++++++++++++++++++++ ottr_anvil/github_package_list.tsv | 8 +++ ottr_anvil/install_github.R | 52 ++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 ottr_anvil/Dockerfile create mode 100644 ottr_anvil/github_package_list.tsv create mode 100644 ottr_anvil/install_github.R diff --git a/ottr_anvil/Dockerfile b/ottr_anvil/Dockerfile new file mode 100644 index 0000000..04dc76f --- /dev/null +++ b/ottr_anvil/Dockerfile @@ -0,0 +1,78 @@ +FROM rocker/tidyverse:4.4.0 +LABEL maintainer="avamariehoffman@gmail.com" +WORKDIR /rocker-build/ + +COPY install_github.R . + +# Install apt-getable packages to start +RUN apt-get update && apt-get install -y --no-install-recommends apt-utils dialog +RUN apt-get install -y --no-install-recommends \ + libxt6 \ + libpoppler-cpp-dev \ + vim \ + libglpk40 \ + curl \ + gpg + +# Install gh +RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg; +RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null; +RUN apt update && apt install -y gh; + +# Uninstall old version of pandoc +RUN sudo apt-get purge pandoc pandoc-citeproc pandoc-data \ + && sudo apt-get autoremove --purge + +# Install pandoc +RUN wget https://github.com/jgm/pandoc/releases/download/2.14.1/pandoc-2.14.1-1-amd64.deb \ + && sudo apt-get install ./pandoc-2.14.1-1-amd64.deb + +# Create new symlinks +RUN ln -s /usr/bin/pandoc /usr/lib/rstudio-server/bin/pandoc + +# Add curl, bzip2 +RUN apt-get update -qq && apt-get -y --no-install-recommends install \ + bzip2 \ + curl + +# Install pip3 and installation tools +RUN apt-get -y --no-install-recommends install \ + python3-pip python3-dev + +RUN Rscript -e "remove.packages('rlang')" + +# Commonly used R packages +RUN Rscript -e "options(warn = 2);install.packages( \ + c('rlang', \ + 'bookdown', \ + 'emojifont', \ + 'here', \ + 'leanpubr', \ + 'optparse', \ + 'oro.nifti', \ + 'qpdf', \ + 'R.utils', \ + 'rprojroot', \ + 'rgoogleslides', \ + 'servr', \ + 'spelling', \ + 'styler', \ + 'reticulate', \ + 'googlesheets4', \ + 'tibble'), \ + repos = 'https://cloud.r-project.org/')" + +# cow needs this dependency: +RUN Rscript -e "devtools::install_version('gitcreds', version = '0.1.1', repos = 'http://cran.us.r-project.org')" + +# Copy over git token and package list +COPY git_token.txt . +COPY github_package_list.tsv . + +# Install packages from github +RUN Rscript install_github.R \ + --packages github_package_list.tsv \ + --token git_token.txt + +# Set final workdir for commands +WORKDIR /home/rstudio diff --git a/ottr_anvil/github_package_list.tsv b/ottr_anvil/github_package_list.tsv new file mode 100644 index 0000000..d25f995 --- /dev/null +++ b/ottr_anvil/github_package_list.tsv @@ -0,0 +1,8 @@ +rstudio/rmarkdown HEAD +yihui/xfun HEAD +yihui/knitr HEAD +jhudsl/ottrpal HEAD +tidyverse/rvest 4fe39fb5089512d77b6a9cc026e5c895258ff6ce +R-lib/testthat e99155af85261e065192feb946dcfa6679cffae4 +rstudio/bookdown HEAD +jhudsl/cow HEAD \ No newline at end of file diff --git a/ottr_anvil/install_github.R b/ottr_anvil/install_github.R new file mode 100644 index 0000000..fb532ec --- /dev/null +++ b/ottr_anvil/install_github.R @@ -0,0 +1,52 @@ +#!/usr/bin/env Rscript + +if (!"optparse" %in% installed.packages()) { + install.packages("optparse") +} + +library(optparse) + +################################ Set up options ################################ +# Set up optparse options +option_list <- list( + make_option( + opt_str = c("-p", "--packages"), type = "character", + default = "github_package_list.tsv" , + help = "Path to a TSV with a list of packages to be installed through Github, + where file where the first column is the github package name e.g. + jhudsl/ottrpal and the second column is the commit ID to be installed + (to be supplied to the ref argument). + ", + metavar = "character" + ), + make_option( + opt_str = c("--token"), type = "character", + default = NULL, + help = "GITHUB PAT file", + metavar = "character" + ) +) + +# Parse options +opt <- parse_args(OptionParser(option_list = option_list)) + +# Read in the token +token <- as.character(readLines(opt$token)[1]) + +# Reset GITHUB PAT to be token +Sys.unsetenv("GITHUB_PAT") +Sys.setenv(GITHUB_PAT = token) + +# set up list of packages to install +packages <- readr::read_tsv(opt$packages, + col_names = c("package_name", "ref")) + +purrr::pmap( + packages, + ~remotes::install_github(..1, + auth_token = token, + ref = ..2) + ) + +# Remove the file after we are done +file.remove(opt$token)