From 8dc5fc9b9199f61472ee50c94bee7e4d7f4b2dbd Mon Sep 17 00:00:00 2001 From: gowerc Date: Thu, 26 Sep 2024 13:46:48 +0100 Subject: [PATCH] initial --- .github/workflows/build_docker.yaml | 25 ++----- .github/workflows/build_docker_latest.yaml | 85 ---------------------- misc/docker/Dockerfile | 6 +- misc/docker/install_packages.R | 47 ++++++++---- 4 files changed, 39 insertions(+), 124 deletions(-) delete mode 100644 .github/workflows/build_docker_latest.yaml diff --git a/.github/workflows/build_docker.yaml b/.github/workflows/build_docker.yaml index 2f160565b..e949137aa 100644 --- a/.github/workflows/build_docker.yaml +++ b/.github/workflows/build_docker.yaml @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/build_docker_latest.yaml b/.github/workflows/build_docker_latest.yaml deleted file mode 100644 index 0e1ff1df9..000000000 --- a/.github/workflows/build_docker_latest.yaml +++ /dev/null @@ -1,85 +0,0 @@ -name: Build latest version Docker images - -env: - REGISTRY: ghcr.io - -on: - schedule: - - cron: '0 5 1 * *' - workflow_dispatch: - - -jobs: - build: - runs-on: ubuntu-latest - name: Build & Deploy Docker Images - - - strategy: - fail-fast: true - matrix: - config: - - { - src_image: "rocker/r-ver:latest", - cran_url: "https://packagemanager.rstudio.com/cran/latest", - tag: "rbmi:latest", - mmrm_version : "v0.1.5" - } - - # Token permissions - permissions: - contents: read - packages: write - - # Build steps - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - id: buildx - with: - install: true - - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: docker-cache-${{ matrix.config.tag }} - - - - name: debug - 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 }} - - - name: Build and push image - uses: docker/build-push-action@v3 - with: - context: ./misc/docker - 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 - - # Fix bug where docker cache just continiously grows as it doesn't purge older layers - # That are no longer in use - # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#local-cache - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/misc/docker/Dockerfile b/misc/docker/Dockerfile index 33acc5c4c..8b1080052 100644 --- a/misc/docker/Dockerfile +++ b/misc/docker/Dockerfile @@ -1,9 +1,5 @@ -ARG IMAGE -FROM ${IMAGE} - -ARG CRANURL -ARG MMRM_VERSION +FROM rocker/r-ver:latest ENV REQD_PKGS="\ libicu-dev \ diff --git a/misc/docker/install_packages.R b/misc/docker/install_packages.R index 006164187..43d97ffc9 100644 --- a/misc/docker/install_packages.R +++ b/misc/docker/install_packages.R @@ -1,32 +1,42 @@ +OS_CODENAME <- system( + 'cat /etc/os-release | grep "VERSION_CODENAME" | sed -e "s/VERSION_CODENAME=//"', + intern = TRUE +) -options(warn = 2) +CRANURL <- sprintf( + "https://packagemanager.posit.co/cran/__linux__/%s/latest", + OS_CODENAME +) -install.packages("remotes", repos = Sys.getenv("CRANURL")) +options( + "repos" = list("CRAN" = CRANURL), + "HTTPUserAgent" = sprintf( + "R/%s R (%s)", + getRversion(), + paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"]) + ) +) -# 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) -} +options(warn = 2) pkgs <- c( - "tidyverse", - "glmmTMB", + "dplyr", + "purrr", + "tibble", + "lubridate", + "purrr", "mvtnorm", "devtools", "rstan", "rstantools", "RcppParallel", "Rcpp", + "knitr", "R6", "assertthat", + "rmarkdown", "emmeans", "covr", "testthat", @@ -38,4 +48,11 @@ pkgs <- c( "R.rsp" ) -install.packages(pkgs, repos = Sys.getenv("CRANURL"), dependencies = TRUE) +install.packages(pkgs, dependencies = TRUE) + +install.packages( + "cmdstanr", + repos = c("https://stan-dev.r-universe.dev", getOption("repos")) +) + +cmdstanr::install_cmdstan(cores = 2)