Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cjyetman committed Jul 19, 2023
0 parents commit 057eb28
Show file tree
Hide file tree
Showing 30 changed files with 4,552 additions and 0 deletions.
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
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
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
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: 'PACTA-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
42 changes: 42 additions & 0 deletions .github/workflows/build-and-push-Docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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-build.outputs.full-image-name }}
jobs:
docker-build:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
timeout-minutes: 25
outputs:
full-image-name: ${{ steps.push-image.outputs.full-image-name }}

steps:
- name: Checkout
# https://github.com/actions/checkout
uses: actions/checkout@v3

- name: Build Docker image
run: docker build . --file Dockerfile --tag ${{ inputs.image-name }}

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin

- name: Push image
id: push-image
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]')
docker tag ${{ inputs.image-name }} $full_image_name
docker push $full_image_name
echo "full-image-name=$full_image_name" >> $GITHUB_OUTPUT
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.Rproj.user
.Rhistory
.RData
.Rdata
.Ruserdata
.httr-oauth
.quarto
.DS_Store
139 changes: 139 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# using rocker r-vers as a base with R 4.2.3
# 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-03-31
# https://packagemanager.posit.co/client/#/repos/2/overview
# https://packagemanager.posit.co/cran/__linux__/jammy/2023-03-31+MbiAEzHt
#
# sets CTAN repo to freeze TeX package dependencies to those available on
# 2021-12-31
# https://www.texlive.info/tlnet-archive/2021/12/31/tlnet/

ARG PLATFORM="linux/amd64"
ARG R_VERS="4.2.3"
FROM --platform=$PLATFORM rocker/r-ver:$R_VERS

LABEL org.opencontainers.image.source=https://github.com/RMI-PACTA/workflow.pacta
LABEL org.opencontainers.image.description="Docker image to run PACTA"
LABEL org.opencontainers.image.licenses=MIT

ARG CRAN_REPO="https://packagemanager.posit.co/cran/__linux__/jammy/2023-03-31+MbiAEzHt"
RUN echo "options(repos = c(CRAN = '$CRAN_REPO'))" >> "${R_HOME}/etc/Rprofile.site"

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

# install system dependencies
ARG SYS_DEPS="\
git \
libcurl4-openssl-dev \
libssl-dev \
openssh-client \
wget \
"
RUN apt-get update \
&& apt-get install -y --no-install-recommends $SYS_DEPS \
&& chmod -R a+rwX /root \
&& rm -rf /var/lib/apt/lists/*

# install system dependencies for R packages
ARG R_PKG_SYS_DEPS="\
libfontconfig1-dev \
libfreetype6-dev \
libfribidi-dev \
libgit2-dev \
libharfbuzz-dev \
libicu-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libxml2-dev \
libxt6 \
make \
pandoc \
perl \
zlib1g-dev \
"
RUN apt-get update \
&& apt-get install -y --no-install-recommends $R_PKG_SYS_DEPS \
&& rm -rf /var/lib/apt/lists/*

# install TeX system and fonts
ARG TEX_APT="\
texlive-xetex \
texlive-fonts-recommended \
texlive-fonts-extra \
lmodern \
xz-utils \
"
RUN apt-get update \
&& apt-get install -y --no-install-recommends $TEX_APT \
&& tlmgr init-usertree \
&& rm -rf /var/lib/apt/lists/*

# install tex package dependencies
ARG CTAN_REPO="https://www.texlive.info/tlnet-archive/2021/12/31/tlnet/"
ARG TEX_DEPS="\
geometry \
hyperref \
l3packages \
mdframed \
needspace \
tools \
xcolor \
zref \
"
RUN tlmgr --repository $CTAN_REPO install $TEX_DEPS

# install packages for dependency resolution and installation
RUN Rscript -e "install.packages('pak')"
RUN Rscript -e "pak::pkg_install(c('renv', 'yaml'))"

# copy in scripts from this repo
ARG WORKFLOW_DIR="/workflow.pacta"
COPY workflow.pacta $WORKFLOW_DIR

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

ARG summary_url="https://github.com/rmi-pacta/pacta.executive.summary"
ARG allocate_url="https://github.com/rmi-pacta/pacta.portfolio.allocate"
ARG audit_url="https://github.com/rmi-pacta/pacta.portfolio.audit"
ARG import_url="https://github.com/rmi-pacta/pacta.portfolio.import"
ARG report_url="https://github.com/rmi-pacta/pacta.portfolio.report"
ARG utils_url="https://github.com/rmi-pacta/pacta.portfolio.utils"

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

# set permissions for PACTA repos that need local content
RUN chmod -R a+rwX $WORKFLOW_DIR

# set the build_version environment variable
ARG image_tag
ENV build_version=$image_tag
ARG head_hashes
ENV head_hashes=$head_hashes

RUN exit 0
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Description

The Dockerfile in this repository creates an image containing a freshly
cloned copy of workflow.pacta. 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:$tag_name
data_folder=~/github/rmi-pacta/pacta-data
portfolio_name="1234"
user_folder=~/github/rmi-pacta/workflow.pacta/working_dir
docker run -ti --rm --network none \
--pull=always \
--mount type=bind,source=${user_folder},target=/workflow.pacta/working_dir \
--mount type=bind,readonly,source=${data_folder},target=/pacta-data \
$image_name \
/bound/bin/run-r-scripts-results-only "$portfolio_name"
```
9 changes: 9 additions & 0 deletions bin/run-r-scripts-results-only
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

# Set permissions so that new files can be deleted/overwritten outside docker
umask 000

cd ./bound

Rscript --vanilla web_tool_script_1.R "${1:-1234}" \
&& Rscript --vanilla web_tool_script_2.R "${1:-1234}"
18 changes: 18 additions & 0 deletions inst/rmd/user_errors.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: "User Error Report"
output: html_document
params:
errors: ""
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

During the course of preparing your PACTA report, the system encountered the errors detailed below. Please correct the errors and create a new reeport. If the errors persist, please contact Rocky Mountain Institute at `transitionmonitor@rmi.org`

## Errors

```{r errors, results = 'asis'}
cat(convert_user_errors_to_md(params[["errors"]]))
```
81 changes: 81 additions & 0 deletions parameter_files/AnalysisParameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
default:

reporting:
project_report_name: general
display_currency: USD
currency_exchange_value: 1

parameters:
timestamp: 2019Q4
dataprep_timestamp: 2019Q4_250220
start_year: 2020
horizon_year: 5
select_scenario: WEO2019_SDS
scenario_auto: ETP2017_B2DS
scenario_other: ETP2017_B2DS
portfolio_allocation_method: portfolio_weight
scenario_geography: Global

methodology:
has_map: TRUE
has_revenue: FALSE
has_credit: FALSE
inc_emissionfactors: TRUE

sectors:
tech_roadmap_sectors:
- Power
- Automotive
- Oil&Gas
- Coal
pacta_sectors_not_analysed:
- Steel
- Aviation
- Cement
green_techs:
- RenewablesCap
- HydroCap
- NuclearCap
- Hybrid
- Electric
- FuelCell
- Hybrid_HDV
- Electric_HDV
- FuelCell_HDV
- Dc-Electric Arc Furnace
- Ac-Electric Arc Furnace
alignment_techs:
- RenewablesCap
- CoalCap
- Coal
- Oil
- Gas
- Electric
- ICE

asset_types:
- Equity
- Bonds
- Others
- Funds

scenario_sources_list:
- ETP2017
- WEO2019
- WEO2020
- GECO2019

scenario_geography_list:
- Global
- GlobalAggregate
- NonOECD
- OECD

equity_market_list:
- GlobalMarket
- DevelopedMarket
- EmergingMarket

grouping_variables:
- investor_name
- portfolio_name
Loading

0 comments on commit 057eb28

Please sign in to comment.