Skip to content

Commit faf7f77

Browse files
authored
Retrieve config file from S3 bucket (#10)
* Download config file from config S3 bucket * Copy over sos_read operations to Docker container image * Fix bug that caused output file to not be sourced * Add local option for loading in config.R from prediagnostics directory
1 parent 2c88601 commit faf7f77

File tree

5 files changed

+64
-29
lines changed

5 files changed

+64
-29
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656
5757
# Check out GitHub repo
5858
- uses: actions/checkout@v4
59+
with:
60+
submodules: 'recursive'
5961

6062
# SNYK IAC scan and report - TODO
6163
# - name: Run Snyk IAC to test and report

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "sos_read"]
2+
path = sos_read
3+
url = https://github.com/SWOT-Confluence/sos_read

Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN echo "America/New_York" | tee /etc/timezone \
66
build-essential \
77
gcc \
88
gfortran \
9-
locales \
9+
locales \
1010
libcurl4-gnutls-dev \
1111
libfontconfig1-dev \
1212
libfribidi-dev \
@@ -34,15 +34,22 @@ RUN apt -y install \
3434
r-base \
3535
r-base-dev \
3636
&& /usr/bin/Rscript -e "install.packages('RNetCDF', dependencies=TRUE, repos='http://cran.rstudio.com/')" \
37-
&& /usr/bin/Rscript -e "install.packages('rjson', dependencies=TRUE, repos='http://cran.rstudio.com/')"\
38-
&& /usr/bin/Rscript -e "install.packages('dplyr', dependencies=TRUE, repos='http://cran.rstudio.com/')"
37+
&& /usr/bin/Rscript -e "install.packages('rjson', dependencies=TRUE, repos='http://cran.rstudio.com/') "\
38+
&& /usr/bin/Rscript -e "install.packages('dplyr', dependencies=TRUE, repos='http://cran.rstudio.com/')" \
39+
&& /usr/bin/Rscript -e "install.packages('reticulate', dependencies=TRUE, repos='http://cran.rstudio.com/')" \
40+
&& /usr/bin/Rscript -e "install.packages('optparse', dependencies=TRUE, repos='http://cran.rstudio.com/')"
3941

40-
# STAGE 2 set up I/O directories, copy geobamdata installer and R script
42+
# STAGE 2 - Python and python packages for S3 functionality
4143
FROM stage1 as stage2
42-
COPY ./prediagnostics/ /app/prediagnostics/
44+
RUN apt update && apt -y install python3 python3-dev python3-pip python3-venv python3-boto3
4345

44-
# STAGE 3 - Execute algorithm
46+
# STAGE 3 set up I/O directories, copy geobamdata installer and R script
4547
FROM stage2 as stage3
48+
COPY ./prediagnostics/ /app/prediagnostics/
49+
COPY ./sos_read /app/prediagnostics/sos_read/
50+
51+
# STAGE 4 - Execute algorithm
52+
FROM stage3 as stage4
4653
LABEL version="1.0" \
4754
description="Containerized prediagnostics module." \
4855
"confluence.contact"="ntebaldi@umass.edu" \
Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
source("/app/prediagnostics/config.R")
1+
library(optparse)
2+
library(reticulate)
3+
24
source("/app/prediagnostics/input.R")
3-
source("/app/prediagnostics/prediagnostics.R")
45
source("/app/prediagnostics/output.R")
6+
source("/app/prediagnostics/prediagnostics.R")
7+
8+
PYTHON_EXE = "/usr/bin/python3"
9+
PYTHON_FILE = "/app/prediagnostics/sos_read/sos_read.py"
10+
TMP_PATH = "/tmp"
511

612
start = Sys.time()
713

@@ -10,29 +16,45 @@ input_dir = file.path("/mnt", "data", "input")
1016
output_dir = file.path("/mnt", "data", "output")
1117

1218
# Command line arguments
13-
args = commandArgs(trailingOnly=TRUE)
14-
# we want to specify index and reach json for local run
15-
if (length(args)>=2){
16-
index = strtoi(args[1]) + 1
17-
reaches_json = file.path(input_dir, paste(args[2]))
18-
19-
# we want to specify reach json for aws run
20-
if (length(args)>=3){
21-
index = strtoi(Sys.getenv("AWS_BATCH_JOB_ARRAY_INDEX")) + 1
22-
}
23-
24-
# we want to specify only index for local run
25-
} else if (length(args)>=1) {
26-
index = strtoi(args[1]) + 1
27-
reaches_json = file.path(input_dir, 'reaches.json')
28-
# we want to run on default settings for aws
29-
} else{
30-
index = strtoi(Sys.getenv("AWS_BATCH_JOB_ARRAY_INDEX")) + 1
31-
reaches_json = file.path(input_dir, 'reaches.json')
19+
option_list <- list(
20+
make_option(c("-i", "--index"), type = "integer", default = NULL, help = "Index to run on"),
21+
make_option(c("-b", "--config_bucket"), type = "character", default = "", help = "Bucket key to find the sos"),
22+
make_option(c("-r", "--reaches_json"), type = "character", default = "reaches.json", help = "Name of reaches.json")
23+
)
24+
opt_parser <- OptionParser(option_list = option_list)
25+
opts <- parse_args(opt_parser)
26+
27+
index <- opts$index
28+
if (index == -256){
29+
index <- strtoi(Sys.getenv("AWS_BATCH_JOB_ARRAY_INDEX"))
3230
}
31+
index <- index + 1 # Add 1 to AWS 0-based index
3332

34-
# Run Diagnostics
35-
output=run_diagnostics(input_dir, reaches_json, index, output_dir)
33+
config_bucket <- opts$config_bucket
34+
reaches_json = file.path(input_dir, opts$reaches_json)
35+
36+
# Load Config file from S3
37+
if (config_bucket != "") {
38+
use_python(PYTHON_EXE)
39+
source_python(PYTHON_FILE)
40+
41+
config_filepath = file.path(TMP_PATH, "config.R")
42+
download_sos(config_bucket, config_filepath)
43+
44+
# Run Diagnostics on S3 config file
45+
if (file.exists(config_filepath)) {
46+
source(config_filepath)
47+
output=run_diagnostics(input_dir, reaches_json, index, output_dir)
48+
} else {
49+
print("Config file could not be downloaded and prediagnostics will not run.")
50+
}
51+
52+
# Run Diagnostics on local config file
53+
} else {
54+
print("Config file will be run on local config: '/app/prediagnostics/config.R'")
55+
source("/app/prediagnostics/config.R")
56+
output=run_diagnostics(input_dir, reaches_json, index, output_dir)
57+
}
3658

3759
end = Sys.time()
3860
print(paste0("Execution time: ", end - start))

sos_read

Submodule sos_read added at 652bf6a

0 commit comments

Comments
 (0)