Skip to content

Commit

Permalink
Merge pull request chainguard-dev#1111 from chainguard-dev/R
Browse files Browse the repository at this point in the history
feat: Add build pipeline for R packages
  • Loading branch information
EyeCantCU committed Mar 26, 2024
2 parents 6bcb408 + 579ee5e commit dac40c7
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
95 changes: 95 additions & 0 deletions docs/PIPELINES-R.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Built-in R pipeline

Melange includes a built-in pipeline to compile R packages.

To get started quickly, checkout the `R/build` pipeline:
[cran-build.yaml](https://github.com/chainguard-dev/melange/blob/main/examples/R-build.yaml)

## Building R packages with `R/build`

The `R/build` pipeline is a declarative interface that leverages the R package
manager. This pipeline builds an R package from source and installs it to the
standard R library directory.

Here's a sample melange configuration file cloning and running the same
sample project as above:

```yaml
package:
name: cran-proxy
version: 0.4_27
epoch: 0
description: Distance and similarity measures
copyright:
- license: GPL-2.0-or-later

environment:
contents:
packages:
- R
- R-dev
- busybox

var-transforms:
- from: ${{package.version}}
match: '_'
replace: '-'
to: mangled-package-version

pipeline:
- uses: git-checkout
with:
repository: https://github.com/cran/proxy
tag: ${{vars.mangled-package-version}}
expected-commit: 311a8569a534460ef04473ffa442dc7b72ba9a41

- uses: R/build
with:
package: proxy
version: ${{vars.mangled-package-version}}

- uses: strip

update:
enabled: true
version-transform:
- match: '_'
replace: '-'
github:
identifier: cran/proxy
use-tag: true
```

(:bulb: Experiment with this code,
[download it from the examples directory](https://github.com/chainguard-dev/melange/blob/main/examples/R-build.yaml))

## Build Parameters

The `R/build` pipeline supports passing a few parameters the R package manager by
setting them in the melange configuration file. As of this writing, you can define
the following values:

```yaml
package:
description: |
The R package to install
required: true

path:
description: |
Path to R package source or source tarball
default: "."

version:
description: |
The R package version
required: true
```

For the most up to date supported features check the
[build](https://github.com/chainguard-dev/melange/blob/main/pkg/build/pipelines/R/build.yaml)
pipeline.

Feel free to request more features in the built-in pipelines by
[filing a new issue](https://github.com/chainguard-dev/melange/issues/new) in
the melange repository!
51 changes: 51 additions & 0 deletions examples/R-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# SPDX-FileCopyrightText: 2024 Chainguard, Inc
# SPDX-License-Identifier: Apache-2.0
#
# This is a sample configuration file to demonstrate how to build a software
# project using melange's built-in R/build pipeline.
#
# For more information about melange's built-in rust support check out:
# https://github.com/chainguard-dev/melange/blob/main/docs/PIPELINES-R.md
package:
name: cran-proxy
version: 0.4_27
epoch: 0
description: Distance and similarity measures
copyright:
- license: GPL-2.0-or-later

environment:
contents:
packages:
- R
- R-dev
- busybox

var-transforms:
- from: ${{package.version}}
match: '_'
replace: '-'
to: mangled-package-version

pipeline:
- uses: git-checkout
with:
repository: https://github.com/cran/proxy
tag: ${{vars.mangled-package-version}}
expected-commit: 311a8569a534460ef04473ffa442dc7b72ba9a41

- uses: R/build
with:
package: proxy
version: ${{vars.mangled-package-version}}

- uses: strip

update:
enabled: true
version-transform:
- match: '_'
replace: '-'
github:
identifier: cran/proxy
use-tag: true
35 changes: 35 additions & 0 deletions pkg/build/pipelines/R/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run a build using the R package manager

needs:
packages:
- R
- R-dev
- busybox

inputs:
package:
description: |
The R package to install
required: true

path:
description: |
Path to R package source or source tarball
default: "."

version:
description: |
The R package version
required: true

pipeline:
- runs: |
# Use default R library path
mkdir -p /usr/lib/R/library
mkdir -p ${{targets.contextdir}}/usr/lib/R/library
# Build R package from source
Rscript -e 'install.packages("${{inputs.path}}", repos = NULL, type = "source")'
# Install package
mv /usr/lib/R/library/${{inputs.package}} ${{targets.contextdir}}/usr/lib/R/library/

0 comments on commit dac40c7

Please sign in to comment.