Skip to content

Commit

Permalink
Merge pull request #2 from RMI-PACTA/feat/1-enable-report-generation
Browse files Browse the repository at this point in the history
Feat/1 enable report generation
  • Loading branch information
AlexAxthelm authored Mar 11, 2024
2 parents 8db6ff0 + 0b2c96e commit bab33df
Show file tree
Hide file tree
Showing 13 changed files with 768 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/build-Docker-image-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on:
schedule:
- cron: '0 0 * * 1,2,3,4,5'

jobs:
build_docker_image:
name: "Call build and push action"
uses: ./.github/workflows/build-and-push-Docker-image.yml
secrets: inherit
with:
image-name: workflow.pacta.report
image-tag: nightly
12 changes: 12 additions & 0 deletions .github/workflows/build-Docker-image-on-push-to-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on:
push:
branches: [main]

jobs:
build_docker_image:
name: "Call build and push action"
uses: ./.github/workflows/build-and-push-Docker-image.yml
secrets: inherit
with:
image-name: workflow.pacta.report
image-tag: main
37 changes: 37 additions & 0 deletions .github/workflows/build-Docker-image-on-push-to-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
pull_request:

jobs:
build_docker_image:
name: "Call build and push action"
uses: ./.github/workflows/build-and-push-Docker-image.yml
secrets: inherit
with:
image-name: workflow.pacta.report
image-tag: pr${{ github.event.pull_request.number }}

add_comment:
needs: build_docker_image
runs-on: ubuntu-latest
steps:
- name: Find Comment
# https://github.com/peter-evans/find-comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Docker image from this PR

- name: Create or update comment
# https://github.com/peter-evans/create-or-update-comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Docker image from this PR (${{ github.event.pull_request.head.sha }}) created
```
docker pull ${{ needs.build_docker_image.outputs.full-image-name }}
```
edit-mode: replace
67 changes: 67 additions & 0 deletions .github/workflows/build-and-push-Docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: Build and push docker image

on:
workflow_call:
inputs:
image-name:
required: true
type: string
image-tag:
required: true
type: string
outputs:
full-image-name:
description: "Full pushed image name including host/registry, name, and tag"
value: ${{ jobs.docker.outputs.full-image-name }}

jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
timeout-minutes: 25
outputs:
full-image-name: ${{ steps.image-name.outputs.full-image-name }}

steps:

- name: Define image name
id: image-name
run: |
full_image_name="ghcr.io/${{ github.repository_owner }}/${{ inputs.image-name }}:${{ inputs.image-tag }}"
full_image_name=$(echo $full_image_name | tr '[A-Z]' '[a-z]')
echo "full-image-name=$full_image_name" >> "$GITHUB_OUTPUT"
echo "$full_image_name" > full-image-name
- uses: actions/upload-artifact@v3
with:
name: full-image-name
path: .

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.image-name.outputs.full-image-name }}
cache-from: type=gha
cache-to: type=gha,mode=min
no-cache-filters: install-pacta

check-system-dependencies:
name: "Check System Dependencies"
needs: docker
uses: ./.github/workflows/check-R-sysdeps.yml
with:
image: ${{ needs.docker.outputs.full-image-name }}
32 changes: 32 additions & 0 deletions .github/workflows/check-R-sysdeps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Check R system dependencies

on:
workflow_call:
inputs:
image:
required: true
type: string

jobs:

check-system-dependencies:
runs-on: ubuntu-latest
steps:
- name: 'Pull image'
run: |
echo ${{ inputs.image }}
docker pull ${{ inputs.image }}
- name: 'Run pak::sysreqs_check_installed()'
run: |
docker run \
--rm \
--entrypoint "/bin/sh" \
${{ inputs.image }} \
-c "Rscript -e '
x <- pak::sysreqs_check_installed()
print(x)
is_installed <- as.data.frame(x)[[\"installed\"]]
stopifnot(all(is_installed))
'"
11 changes: 11 additions & 0 deletions .github/workflows/run-hadolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
on: [push, pull_request]

jobs:
hadolint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
11 changes: 11 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Type: PACTA
Description: Run PACTA.
Depends:
dplyr,
fs,
jsonlite,
logger,
pacta.executive.summary,
pacta.portfolio.report,
pacta.portfolio.utils,
readr
76 changes: 76 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# using rocker r-vers as a base with R 4.3.1
# https://hub.docker.com/r/rocker/r-ver
# https://rocker-project.org/images/versioned/r-ver.html
#
# sets CRAN repo to use Posit Package Manager to freeze R package versions to
# those available on 2023-10-30
# https://packagemanager.posit.co/client/#/repos/2/overview
# https://packagemanager.posit.co/cran/__linux__/jammy/2023-10-30

# set proper base image
ARG R_VERS="4.3.1"
FROM ghcr.io/rmi-pacta/workflow.pacta:main AS base

# set Docker image labels
LABEL org.opencontainers.image.source=https://github.com/RMI-PACTA/workflow.pacta.report
LABEL org.opencontainers.image.description="Docker image to run PACTA"
LABEL org.opencontainers.image.licenses=MIT
LABEL org.opencontainers.image.title=""
LABEL org.opencontainers.image.revision=""
LABEL org.opencontainers.image.version=""
LABEL org.opencontainers.image.vendor=""
LABEL org.opencontainers.image.base.name=""
LABEL org.opencontainers.image.ref.name=""
LABEL org.opencontainers.image.authors=""

# set apt-get to noninteractive mode
ARG DEBIAN_FRONTEND="noninteractive"
ARG DEBCONF_NOWARNINGS="yes"

# install system dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libpng-dev=1.6.* \
libxt6=1:1.2.* \
pandoc=2.9.* \
&& chmod -R a+rwX /root \
&& rm -rf /var/lib/apt/lists/*

# set frozen CRAN repo
ARG CRAN_REPO="https://packagemanager.posit.co/cran/__linux__/jammy/2023-10-30"
RUN echo "options(repos = c(CRAN = '$CRAN_REPO'), pkg.sysreqs = FALSE)" >> "${R_HOME}/etc/Rprofile.site" \
# install packages for dependency resolution and installation
&& Rscript -e "install.packages('pak'); pak::pkg_install('renv')"

FROM base AS install-pacta

# copy in everything from this repo
COPY DESCRIPTION /DESCRIPTION

# PACTA R package tags
ARG report_tag="/tree/main"
ARG summary_tag="/tree/main"
ARG utils_tag="/tree/main"

ARG report_url="https://github.com/rmi-pacta/pacta.portfolio.report"
ARG summary_url="https://github.com/rmi-pacta/pacta.executive.summary"
ARG utils_url="https://github.com/rmi-pacta/pacta.portfolio.utils"

# install R package dependencies
RUN Rscript -e "\
gh_pkgs <- \
c( \
paste0('$report_url', '$report_tag'), \
paste0('$summary_url', '$summary_tag'), \
paste0('$utils_url', '$utils_tag') \
); \
workflow_pkgs <- renv::dependencies('DESCRIPTION')[['Package']]; \
workflow_pkgs <- grep('^pacta[.]', workflow_pkgs, value = TRUE, invert = TRUE); \
pak::pak(c(gh_pkgs, workflow_pkgs)); \
"

COPY . /

# set default run behavior
ENTRYPOINT ["/run-pacta.sh"]
CMD ["input_dir/default_config.json"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 RMI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
# `workflow.pacta.report`
# workflow.pacta.report

# Description

The Dockerfile in this repository creates an image containing a freshly
cloned copy of `workflow.pacta.report`. It also installs the relevant PACTA R
packages that it depends on.

# Notes

Running PACTA also requires pacta-data, which needs to be mounted into the
container at run-time.

# Using Docker images pushed to GHCR automatically by GH Actions

``` {.bash}
tag_name=main
image_name=ghcr.io/rmi-pacta/workflow.pacta.report:$tag_name
data_dir=~/Downloads/2022Q4_transition_monitor_inputs_2023-07-11/
input_dir=./input_dir
output_dir=./output_dir
# Build
docker build . -t $image_name
# Run
docker run --rm \
--network none \
--platform linux/amd64 \
--env LOG_LEVEL=DEBUG \
--mount type=bind,readonly,source=${data_dir},target=/pacta-data \
--mount type=bind,source=${output_dir},target=/output_dir \
--mount type=bind,source=${input_dir},target=/input_dir \
$image_name
```

```sh

# Run R in container
docker run -it --rm \
--network none \
--platform linux/amd64 \
--env LOG_LEVEL=TRACE \
--mount type=bind,readonly,source=${data_dir},target=/pacta-data \
--mount type=bind,source=${output_dir},target=/output_dir \
--mount type=bind,source=${input_dir},target=/input_dir \
--entrypoint R
$image_name

```
Loading

0 comments on commit bab33df

Please sign in to comment.