Skip to content

Commit

Permalink
Adding the container building logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kaybenleroll committed Dec 16, 2022
1 parent b67a9ec commit d62c7d5
Show file tree
Hide file tree
Showing 14 changed files with 4,321 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: build-docker-image

on:
push:
branches:
- 'main'

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: kaybenleroll/btydbayes_investigation:latest
107 changes: 107 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
FROM rocker/verse:4.2.1

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
byobu \
clang \
ditaa \
graphviz \
htop \
less \
libclang-dev \
libglpk-dev \
libgsl-dev \
libnlopt-dev \
p7zip-full \
pbzip2 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p $HOME/.R \
&& echo "" > $HOME/.R/Makevars \
&& echo "CXX=clang++" >> $HOME/.R/Makevars \
&& echo "CXXFLAGS=-Os" >> $HOME/.R/Makevars \
&& echo "CXXFLAGS+= -Wno-unused-variable -Wno-unused-function" >> $HOME/.R/Makevars \
&& echo "CXXFLAGS+= -Wno-unknown-pragmas -Wno-macro-redefined" >> $HOME/.R/Makevars \
&& echo "" >> $HOME/.R/Makevars \
&& echo "CXX14=clang++" >> $HOME/.R/Makevars \
&& echo "CXX14FLAGS=-Os" >> $HOME/.R/Makevars \
&& echo "CXX14FLAGS+= -Wno-unused-variable -Wno-unused-function" >> $HOME/.R/Makevars \
&& echo "CXX14FLAGS+= -Wno-unknown-pragmas -Wno-macro-redefined" >> $HOME/.R/Makevars \
&& echo "" >> $HOME/.R/Makevars \
&& install2.r --error \
anytime \
bayesplot \
brms \
BTYD \
BTYDplus \
CLVTools \
conflicted \
cowplot \
DataExplorer \
directlabels \
evir \
fitdistrplus \
fs \
furrr \
loo \
modeltime \
posterior \
projpred \
prophet \
pryr \
quarto \
rfm \
rstan \
rstanarm \
sessioninfo \
shinybrms \
shinystan \
snakecase \
tictoc \
tidybayes \
tidyquant \
timetk


WORKDIR /tmp

COPY build/docker_install_sys_rpkgs.R /tmp
RUN Rscript /tmp/docker_install_sys_rpkgs.R

COPY build/test_report.qmd /tmp
RUN quarto render test_report.qmd --to pdf \
&& rm -fv /tmp/test_report.pdf


RUN git clone https://github.com/lindenb/makefile2graph.git \
&& cd makefile2graph \
&& make \
&& make install

RUN cp -r $HOME/.R /home/rstudio \
&& chown -R rstudio:rstudio /home/rstudio/.R


WORKDIR /home/rstudio
USER rstudio

COPY build/conffiles.7z /tmp
RUN 7z x /tmp/conffiles.7z \
&& cp conffiles/.bash* . \
&& cp conffiles/.gitconfig . \
&& cp conffiles/.Renviron . \
&& cp conffiles/.Rprofile . \
&& mkdir -p .config/rstudio \
&& cp conffiles/rstudio-prefs.json .config/rstudio/ \
&& rm -rfv conffiles/ \
&& touch /home/rstudio/.bash_eternal_history

COPY build/docker_install_user_rpkgs.R /tmp
RUN Rscript /tmp/docker_install_user_rpkgs.R


USER root

RUN chown -R rstudio:rstudio /home/rstudio

99 changes: 99 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
### repo variables
PROJECT_USER=kaybenleroll
PROJECT_NAME=btydbayes-investigation
PROJECT_TAG=latest

IMAGE_TAG=${PROJECT_USER}/${PROJECT_NAME}:${PROJECT_TAG}

DOCKER_USER=rstudio
DOCKER_PASS=CHANGEME
DOCKER_UID=$(shell id -u)
DOCKER_GID=$(shell id -g)

RSTUDIO_PORT=8787

PROJECT_FOLDER=btydwork


### Set GITHUB_USER with 'gh config set gh_user <<user>>'
GITHUB_USER=$(shell gh config get gh_user)

CONTAINER_NAME=btyd-work

### Project build targets
.SUFFIXES: .qmd .html .dot .png

QMD_FILES := $(wildcard *.qmd)
HTML_FILES := $(patsubst %.qmd,%.html,$(QMD_FILES))

all-html: $(HTML_FILES)

.qmd.html:
echo "TIMESTAMP:" `date` "- Rendering script $<" >> output.log 2>&1
Rscript -e 'quarto::quarto_render("$<")' >> output.log 2>&1
echo "TIMESTAMP:" `date` "- Finished $*.html" >> output.log 2>&1


.dot.png:
dot -Tpng -o$*.png $<

full_deps.dot:
makefile2graph all-html > full_deps.dot

depgraph: full_deps.png




mrproper: clean-cache clean-data clean-html clean-models
rm -fv data/*.xlsx
rm -fv *.dot
rm -fv output.log

clean-data:
rm -fv data/*.rds
rm -fv data/*.csv

clean-html:
rm -fv *.html

clean-cache:
rm -rfv *_cache
rm -rfv *_files

clean-models:
rm -fv stan_models/*


### Docker targets
docker-build-image: Dockerfile
docker build -t ${IMAGE_TAG} -f Dockerfile .

docker-run:
docker run --rm -d \
-p ${RSTUDIO_PORT}:8787 \
-e USER=${DOCKER_USER} \
-e PASSWORD=${DOCKER_PASS} \
-e USERID=${DOCKER_UID} \
-e GROUPID=${DOCKER_GID} \
-v "${PWD}":"/home/${DOCKER_USER}/${PROJECT_FOLDER}":rw \
--name ${CONTAINER_NAME} \
${IMAGE_TAG}

docker-bash:
docker exec -it -u ${DOCKER_USER} ${CONTAINER_NAME} bash

docker-stop:
docker stop ${CONTAINER_NAME}

docker-rm:
docker rm ${CONTAINER_NAME}

docker-start:
docker start ${CONTAINER_NAME}

docker-clean: docker-stop-all
docker rm $(shell docker ps -q -a)

docker-pull:
docker pull ${IMAGE_TAG}
18 changes: 18 additions & 0 deletions btydwork.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Makefile
Binary file added build/conffiles.7z
Binary file not shown.
5 changes: 5 additions & 0 deletions build/docker_install_sys_rpkgs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
remotes::install_github(
"mjskay/tidybayes",
ref = "1efbdef9c1c59c5fa9dc20fdd78e41c9a99113e5"
)

36 changes: 36 additions & 0 deletions build/docker_install_user_rpkgs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
remotes::install_github(
"paul-buerkner/brms",
ref = "v2.18.0",
upgrade = "always"
)

remotes::install_github(
"stan-dev/cmdstanr",
ref = "v0.5.3",
upgrade = "never"
)


remotes::install_github(
"rmcelreath/rethinking",
ref = "v2.2.1",
upgrade = "never"
)


library(cmdstanr)

cmdstan_flags <- list(
"CXX" = "clang++",
"CXXFLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined",
"CXX14" = "clang++",
"CXX14FLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined"
)

install_cmdstan(
cores = parallel::detectCores(),
cpp_options = cmdstan_flags,
quiet = FALSE,
overwrite = FALSE,
version = "2.31.0"
)
71 changes: 71 additions & 0 deletions build/test_report.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: "Temporary Quarto Document"
author: "Mick Cooney <[email protected]>"
date: "`r Sys.Date()`"
---


```{r knit_opts, include = FALSE}
library(conflicted)
library(tidyverse)
library(magrittr)
library(rlang)
library(scales)
library(cowplot)
resolve_conflicts <- function(pkg_priority) {
get_index <- function(pkg_name) {
idx <- str_which(pkg_priority, pkg_name)
if(length(idx) == 0) {
idx <- 0L
}
return(idx)
}
conflict_lst <- conflict_scout()
for(func_name in names(conflict_lst)) {
pkg_index <- map_int(conflict_lst[[func_name]], get_index)
pkg_index <- pkg_index[pkg_index > 0]
if(length(pkg_index) == 0) {
pkg_use <- conflict_lst[[func_name]][1]
} else {
pkg_use <- pkg_index %>%
min() %>%
pkg_priority[.]
}
conflict_prefer(func_name, pkg_use)
}
return(conflict_lst)
}
conflict_lst <- resolve_conflicts(
c("xml2", "magrittr", "rlang", "dplyr", "readr", "purrr", "ggplot2")
)
knitr::opts_chunk$set(
tidy = FALSE,
cache = FALSE,
warning = FALSE,
message = FALSE,
fig.height = 8,
fig.width = 11
)
options(
width = 80L,
warn = 1,
mc.cores = parallel::detectCores()
)
set.seed(42)
theme_set(theme_cowplot())
```
4 changes: 4 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.txt
*.zip
*.xlsx
*.rds
Loading

0 comments on commit d62c7d5

Please sign in to comment.