Skip to content

Commit

Permalink
Fix broken docker build (#427)
Browse files Browse the repository at this point in the history
Closes #410
  • Loading branch information
gowerc authored Sep 26, 2024
1 parent 84df256 commit 25e71ba
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 214 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/build_docker.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build fixed version Docker images
name: Build latest version Docker images

env:
REGISTRY: ghcr.io

on:
schedule:
- cron: '0 5 1 * *'
workflow_dispatch:


Expand All @@ -18,16 +20,7 @@ jobs:
matrix:
config:
- {
src_image: "rocker/r-ver:4.0.4",
cran_url: "https://packagemanager.rstudio.com/cran/2021-04-20",
tag: "rbmi:r404",
mmrm_version : "v0.1.5"
}
- {
src_image: "rocker/r-ver:4.1.0",
cran_url: "https://packagemanager.rstudio.com/cran/2021-08-04",
tag: "rbmi:r410",
mmrm_version : "v0.1.5"
tag: "rbmi:latest"
}

# Token permissions
Expand All @@ -37,8 +30,8 @@ jobs:

# Build steps
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
Expand All @@ -64,9 +57,6 @@ jobs:
run: |
echo push = ${{ github.event_name == 'push' }}
echo tag = ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.config.tag }}
echo IMAGE=${{ matrix.config.src_image }}
echo CRANURL=${{ matrix.config.cran_url }}
echo MMRM_VERSION=${{ matrix.config.mmrm_version }}
- name: Build and push image
uses: docker/build-push-action@v3
Expand All @@ -75,9 +65,6 @@ jobs:
push: true
tags: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.config.tag }}
build-args: |
IMAGE=${{ matrix.config.src_image }}
CRANURL=${{ matrix.config.cran_url }}
MMRM_VERSION=${{ matrix.config.mmrm_version }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

Expand Down
85 changes: 0 additions & 85 deletions .github/workflows/build_docker_latest.yaml

This file was deleted.

55 changes: 0 additions & 55 deletions .github/workflows/check_for_cran.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/on_biweekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
fail-fast: true
matrix:
config:
# - { image: "ghcr.io/${{ github.repository_owner }}/rbmi:r404"}
# - { image: "ghcr.io/${{ github.repository_owner }}/rbmi:r410"}
- { image: "ghcr.io/${{ github.repository_owner }}/rbmi:latest"}

runs-on: ubuntu-latest
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/on_pr_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ name: On Pull Request
jobs:

rcmdcheck:

strategy:
fail-fast: true
matrix:
config:
# - { image: "ghcr.io/${{ github.repository_owner }}/rbmi:r404"}
# - { image: "ghcr.io/${{ github.repository_owner }}/rbmi:r410"}
- { image: "ghcr.io/${{ github.repository_owner }}/rbmi:latest"}
runs-on: ubuntu-latest
container:
Expand All @@ -44,8 +41,6 @@ jobs:
fail-fast: true
matrix:
config:
# - { image: "ghcr.io/${{ github.repository_owner }}/rbmi:r404"}
# - { image: "ghcr.io/${{ github.repository_owner }}/rbmi:r410"}
- { image: "ghcr.io/${{ github.repository_owner }}/rbmi:latest"}
runs-on: ubuntu-latest
container:
Expand Down
16 changes: 6 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,20 @@ test_that("some unit test", {

The scheduled tests can also be manually activated by going to "https://github.com/insightsengineering/rbmi" -> "Actions" -> "Bi-Weekly" -> "Run Workflow". It is advisable to do this before releasing to CRAN.

### CRAN Releases

In order to release a package to CRAN it needs to be tested across multiple different OS's and versions of R. This has been implemented in this project via a GitHub Action Workflow titled "Check for CRAN" which needs to be manually activated. To do this go to "https://github.com/insightsengineering/rbmi" -> "Actions" -> "Check for CRAN" -> "Run Workflow".

If all these tests pass then the package can be safely released to CRAN (after updating the relevant `cran-comments.md` file)


### Docker Images

To support CI/CD in terms of reducing installation time, several Docker images have been pre-built which contain all the packages and system dependencies that this project needs. The current relevant images can be found at:
To support CI/CD, in terms of reducing setup time, a Docker images has been created which contains all the packages and system dependencies required for this project. The image can be found at:

- ghcr.io/insightsengineering/rbmi:r404
- ghcr.io/insightsengineering/rbmi:r410
- ghcr.io/insightsengineering/rbmi:latest

The `latest` image is automatically re-built once a month to contain the latest version of R and its packages. The other versions are built with older versions of R (as indicated by the tag number) and contain package versions as they were when that version of R was released. This is important to ensure that the package works with older versions of R which many companies typically run due to delays in their validation processes.
This image is automatically re-built once a month to contain the latest version of R and its packages. The code to create this images can be found in `misc/docker`.

The code to create these images can be found in `misc/docker`. The legacy images (i.e. everything excluding the "latest" image) are only built on manual request by running the corresponding GitHub Actions Workflow.
To build the image locally run the following from the project root directory:
```
docker build -f misc/docker/Dockerfile -t rbmi:latest .
```


### Reproducibility, Print Tests & Snaps
Expand Down
10 changes: 4 additions & 6 deletions misc/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
ARG IMAGE

FROM ${IMAGE}

ARG CRANURL
ARG MMRM_VERSION
FROM rocker/r-ver:latest

ENV REQD_PKGS="\
libicu-dev \
Expand Down Expand Up @@ -39,13 +35,15 @@ ENV REQD_PKGS="\
qpdf \
devscripts \
cmake \
libpq-dev \
"

RUN apt-get update -y --fix-missing && \
apt-get upgrade -y && \
apt-get install -y $REQD_PKGS

ADD install_packages.R /
ADD misc/docker/install_packages.R /
ADD DESCRIPTION /

RUN Rscript /install_packages.R

Expand Down
82 changes: 50 additions & 32 deletions misc/docker/install_packages.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@


# Determine which OS we are on
# Rocker images are Ubuntu based so should be jammy / focal / etc
OS_CODENAME <- system(
'cat /etc/os-release | grep "VERSION_CODENAME" | sed -e "s/VERSION_CODENAME=//"',
intern = TRUE
)

# Configure PPM URL for binary package installation
CRANURL <- sprintf(
"https://packagemanager.posit.co/cran/__linux__/%s/latest",
OS_CODENAME
)

# Configure useragent to enable binary package installation from PPM
options(
"repos" = list("CRAN" = CRANURL),
"HTTPUserAgent" = sprintf(
"R/%s R (%s)",
getRversion(),
paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])
)
)

# Throw errors if any warnings arise
options(warn = 2)

install.packages("remotes", repos = Sys.getenv("CRANURL"))

# mmrm wasn't available when in-house servers locked their package versions
# and instead had v0.13 of mmrm patched in after the fact
# here we allow the build to specify "latest" to grab the latest version of mmrm
# or a specific named version from github
mmrm_version <- Sys.getenv("MMRM_VERSION")
if (mmrm_version == "latest") {
install.packages("mmrm", repos = Sys.getenv("CRANURL"), dependencies = TRUE)
} else {
remotes::install_git("https://github.com/openpharma/mmrm.git", ref = mmrm_version, upgrade = FALSE)
if (!requireNamespace("desc", quietly = TRUE)) {
install.packages("desc")
}

pkgs <- c(
"tidyverse",
"glmmTMB",
"mvtnorm",
"devtools",
"rstan",
"rstantools",
"RcppParallel",
"Rcpp",
"R6",
"assertthat",
"emmeans",
"covr",
"testthat",
"nlme",
"roxygen2",
"tinytex",
"bookdown",
"RhpcBLASctl",
"R.rsp"

# Get a list of all packages that we claim we depend on in the DESCRIPTION file
pkgs <- desc::desc("DESCRIPTION")$get_deps()$package |> unique()

# Add on additional packages that might be needed in the future
pkgs <- c(pkgs, "tidyverse", "devtools")


# R will error if you try to update the base packages so remove them
# if they are in any of the imports / suggests / depends list
base_pkgs <- c(
"KernSmooth", "class", "foreign", "methods", "rpart", "survival",
"MASS", "cluster", "grDevices", "mgcv", "spatial", "tcltk",
"Matrix", "codetools", "graphics", "nlme", "splines", "tools",
"base", "compiler", "grid", "nnet", "stats", "translations",
"boot", "datasets", "lattice", "parallel", "stats4", "utils",
"R"
)
pkgs <- pkgs[!pkgs %in% base_pkgs]

install.packages(pkgs, repos = Sys.getenv("CRANURL"), dependencies = TRUE)
install.packages(pkgs, dependencies = TRUE)

# Install cmdstanr (not available from CRAN)
install.packages(
"cmdstanr",
repos = c("https://stan-dev.r-universe.dev", getOption("repos"))
)

0 comments on commit 25e71ba

Please sign in to comment.