Skip to content

Commit

Permalink
Try pushing to ghcr
Browse files Browse the repository at this point in the history
  • Loading branch information
bschilder committed Oct 11, 2023
1 parent 01e183e commit f05439a
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rworkflows_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- os: ubuntu-latest
r: devel
bioc: devel
cont: bioconductor/bioconductor_docker:devel
cont: ghcr.io/bioconductor/bioconductor_docker:devel
rspm: https://packagemanager.rstudio.com/cran/__linux__/focal/release
- os: macOS-latest
r: latest
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
* *actions.yml*:
- Add `force=TRUE` to the `remotes::install_local` steps. #86
- Add `runforesight/workflow-telemetry-action` step.
* `construct_cont`:
- Make registry explicit.
- New arg: `default_registry`
- New subfunction: `check_registry`

## Bug fixes

Expand Down
18 changes: 18 additions & 0 deletions R/check_registry.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' @title Check registry
#'
#' @description Check that the registry is valid.
#' @param registry A character vector of registry names.
#' @returns A single registry name.
#'
#' @keywords internal
check_registry <- function(registry){
registry <- registry[1]
if(!is.null(registry)){
if(!grepl("/$",registry)){
registry <- paste0(registry,"/")
}
return(registry)
} else {
return(NULL)
}
}
24 changes: 23 additions & 1 deletion R/construct_cont.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#'
#' @param run_check_cont Check whether the requested container repo
#' (and the tag, if specified) exist using \link[rworkflows]{check_cont}.
#' @param default_registry The default container registr to use.
#' Options include:
#' \itemize{
#' \item{"ghcr.io/" : }{\href{https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry}{GitHub Container Registry}}
#' \item{"docker.io/" : }{\href{https://hub.docker.com/}{DockerHub}}
#' }
#' @param default_cont The DockerHub container to default to.
#' Used when it's detected that only the tag has been given in one or more
#' \code{cont} entry.
Expand All @@ -13,7 +19,9 @@
#' @importFrom stats setNames
#' @examples
#' cont <- construct_cont()
construct_cont <- function(default_cont = "bioconductor/bioconductor_docker",
construct_cont <- function(default_registry = c("ghcr.io/",
"docker.io/"),
default_cont = "bioconductor/bioconductor_docker",
default_tag = "devel",
cont = list(
paste(default_cont,default_tag,sep=":"),
Expand All @@ -24,6 +32,7 @@ construct_cont <- function(default_cont = "bioconductor/bioconductor_docker",
verbose = TRUE){
# devoptera::args2vars(construct_cont)

default_registry <- check_registry(registry = default_registry)
#### Remove any trailing : (e.g. when default_tag=NULL) ####
cont <- lapply(cont, function(x){
if(is.null(x)) NULL else trimws(x,whitespace = ":")
Expand Down Expand Up @@ -57,6 +66,19 @@ construct_cont <- function(default_cont = "bioconductor/bioconductor_docker",
}
return(co)
})
#### Add registry ####
if(!is.null(default_registry)){
opts <- eval(formals(construct_cont)$default_registry)
cont2 <- lapply(cont2, function(co){
if(is.null(co)){
return(NULL)
} else if(!grepl(paste(paste0("^",opts),collapse = "|"),co)){
return(paste0(default_registry,co))
} else {
return(co)
}
})
}
#### Check that the Dockerhub repo exists ####
if(isTRUE(run_check_cont)){
check_cont(cont = cont2,
Expand Down
15 changes: 13 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ inputs:
description: >
Whether to build and push a Docker container to DockerHub.
default: false
docker_registry:
description: >
Docker container registry.
Options include:
- ghcr.io/ : [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry}{GitHub Container Registry)
- docker.io/ : [DockerHub](https://hub.docker.com/)
default: 'ghcr.io/'
docker_user:
description: >
DockerHub username.
Expand All @@ -75,6 +82,8 @@ inputs:
DOCKER_TOKEN:
description: >
DockerHub authentication token.
default:
'${{ secrets.DOCKER_TOKEN }}'
GITHUB_TOKEN:
description: >
GitHub authentication token with permissions to push
Expand All @@ -86,6 +95,8 @@ inputs:
(e.g. {{ secrets.PAT_GITHUB }}) which allows access to private
repositories. Read here for more details:
https://docs.github.com/en/actions/security-guides/automatic-token-authentication.
default:
'${{ secrets.GITHUB_TOKEN }}'
cache_version:
description: >
Which cache version to use.
Expand Down Expand Up @@ -484,14 +495,14 @@ runs:
path <- rworkflows::use_dockerfile()
shell: Rscript {0}

- name: Build and push to DockerHub 🐳 🚀
- name: Build and push to Docker registry 🐳 🚀
if: |
(!contains(github.event.head_commit.message, '/nodocker')) && inputs.run_docker == 'true' && runner.os == 'Linux'
uses: docker/build-push-action@v1
with:
username: ${{ inputs.docker_user }}
password: ${{ inputs.DOCKER_TOKEN }}
repository: ${{ inputs.docker_org }}/${{ env.packageName }}
repository: ${{ inputs.docker_registry }}/${{ inputs.docker_org }}/${{ env.packageName }}
tag_with_ref: true
tag_with_sha: false
tags: ${{ env.packageVersion }},latest
Expand Down
18 changes: 18 additions & 0 deletions man/check_registry.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/conda_export.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/construct_cont.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f05439a

Please sign in to comment.