Skip to content

Commit

Permalink
Merge pull request #3 from beauraines/aws
Browse files Browse the repository at this point in the history
Modifications to use AWS
  • Loading branch information
beauraines authored Mar 6, 2022
2 parents 122b69a + 5b3df52 commit a659a25
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ COPY processDashboard.sh .
COPY upload.R .

FROM dashboard
ARG AZURE_STORAGE_ACCOUNT
ARG AZURE_STORAGE_KEY
ENV AZURE_STORAGE_ACCOUNT=${AZURE_STORAGE_ACCOUNT}
ENV AZURE_STORAGE_KEY=${AZURE_STORAGE_KEY}

ARG AWS_KEY
ARG AWS_SECRET
ARG AWS_REGION
ARG AWS_BUCKET

ENV AWS_KEY=${AWS_KEY}
ENV AWS_SECRET=${AWS_SECRET}
ENV AWS_REGION=${AWS_REGION}
ENV AWS_BUCKET=${AWS_BUCKET}

CMD /bin/bash processDashboard.sh


10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ Covid Metrics Dashboard in R
## The Container

```sh
AZURE_STORAGE_ACCOUNT=<your storage account>
AZURE_STORAGE_KEY=<your storage key>
AWS_KEY=< your AWS_KEY >
AWS_SECRET=< your AWS_SECRET >
AWS_REGION=<your AWS_REGION >
AWS_BUCKET=<your AWS_BUCKET >
IMAGE_NAME=<your image name>
docker build --pull --rm -f "Dockerfile" -t ${IMAGE_NAME} --build-arg AZURE_STORAGE_ACCOUNT=${AZURE_STORAGE_ACCOUNT} --build-arg AZURE_STORAGE_KEY=${AZURE_STORAGE_KEY} .
docker build --pull --rm -f "Dockerfile" -t ${IMAGE_NAME} --build-arg AWS_KEY=${AWS_KEY} --build-arg AWS_SECRET=${AWS_SECRET} --build-arg AWS_REGION=${AWS_REGION} --build-arg AWS_BUCKET=${AWS_BUCKET} .
```

The container can then be pushed to an Azure Container Registry and with an Azure Container Registry Task, scheduled to run at a specific time.
The container can then be pushed to an AWS ECR and scheduled to run at a specific time, with Event Bridge.


3 changes: 2 additions & 1 deletion processDashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ wget https://raw.githubusercontent.com/beauraines/covid-r/main/CovidDashboard.Rm
wget https://raw.githubusercontent.com/beauraines/covid-r/main/CumulativeDeathsAndCases.R

Rscript -e "rmarkdown::render('CovidDashboard.Rmd')"
Rscript upload.R $AZURE_STORAGE_ACCOUNT $AZURE_STORAGE_KEY CovidDashboard.html
Rscript upload.R $AWS_KEY $AWS_SECRET $AWS_REGION $AWS_BUCKET

31 changes: 24 additions & 7 deletions upload.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
library(AzureStor)
options(azure_storage_progress_bar=TRUE)
print("Uploading to azure")
library(aws.s3)
args = commandArgs(trailingOnly=TRUE)
if (length(args)==0) {
stop("At least one argument must be supplied, the key", call.=FALSE)
}
print('uploading to AWS')

cont <- blob_container(endpoint=paste("https://",args[1],".blob.core.windows.net/$web",sep=""),
key=args[2])
upload_blob(cont, args[3], dest=args[3])
print("Uploaded to azure")

key = args[1]
secret = args[2]
region=args[3]
bucket = args[4]

put_object(
file = file.path(".", "CovidDashboard.html"),
object = "CovidDashboard.html",
bucket = bucket,
multipart = TRUE,
region = region,
key = key,
secret = secret,
headers=c('content-type' = 'text/html')
)

get_bucket(bucket = bucket,key = key, secret = secret ,region = region)
head_object(object='CovidDashboard.html', bucket = bucket,key = key, secret = secret ,region = region)
)


print('uploaded')

0 comments on commit a659a25

Please sign in to comment.