First Release
This commit is contained in:
commit
11dee73b0f
|
@ -0,0 +1,52 @@
|
|||
# Dockerfile
|
||||
#
|
||||
# version: 1.0
|
||||
# author: Giancarlo Panichi
|
||||
# date: 2020/10/09
|
||||
|
||||
# R images
|
||||
# see for more image:
|
||||
# https://hub.docker.com/u/rocker/
|
||||
#
|
||||
|
||||
# Version-stable build of R, rstudio, and R packages ~2.48GB
|
||||
# FROM rocker/tidyverse:latest
|
||||
|
||||
#
|
||||
# In this case I will use the r-base image by adding some debian packages
|
||||
# necessary for the correct build of the image.
|
||||
# In this case I will obtain an image of ~1.2GB.
|
||||
# Better ad-hoc solutions can be found to reduce the image size.
|
||||
#
|
||||
# Base Version ~824MB
|
||||
FROM rocker/r-base:latest
|
||||
|
||||
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
|
||||
libssl-dev \
|
||||
libxml2-dev \
|
||||
libcairo2-dev \
|
||||
libssh2-1-dev \
|
||||
libsasl2-dev \
|
||||
libcurl4-openssl-dev
|
||||
|
||||
|
||||
## create directories
|
||||
RUN mkdir -p /code
|
||||
WORKDIR /code
|
||||
RUN mkdir -p src
|
||||
|
||||
## copy files
|
||||
COPY /src/* src/
|
||||
COPY sortapp .
|
||||
RUN chmod +x sortapp
|
||||
|
||||
## install R-packages
|
||||
RUN Rscript src/install_packages.R
|
||||
|
||||
|
||||
## create a link
|
||||
WORKDIR /
|
||||
RUN ln -sf /code/sortapp /usr/bin/sortapp
|
||||
|
||||
# RUN Script
|
||||
# CMD sortapp
|
|
@ -0,0 +1,58 @@
|
|||
# SortAppR
|
||||
|
||||
SortAppR is a simple example that allows you to sort a file in input.
|
||||
Starting from this example, you can first create an simple script R and then a docker image in which it is installed the created script.
|
||||
This example declare the sortapp command as entrypoint.
|
||||
So once you can use this command at command line to run the example:
|
||||
|
||||
```
|
||||
sortapp <token> <file-item-id> <temp-dir-item-id>
|
||||
```
|
||||
|
||||
The image created in this way can be executed in a container with the following command:
|
||||
|
||||
```
|
||||
docker run -i -t --rm --name sortappr-cont sortappr sortapp <token> <file-item-id> <temp-dir-item-id>
|
||||
```
|
||||
|
||||
To be able to create an image from this application you need to have Docker and Docker-Compose installed on your machine and the relative python packages, see:
|
||||
[Docker](https://docs.docker.com/engine/),
|
||||
[Docker-Compose](https://docs.docker.com/compose/install/) and
|
||||
[Docker Package for Python](https://pypi.org/project/docker/).
|
||||
|
||||
## Useful Commands
|
||||
|
||||
### Create Docker Image
|
||||
```
|
||||
docker build -t sortappr .
|
||||
```
|
||||
|
||||
### Save Docker Image in file
|
||||
```
|
||||
docker save sortappr | gzip > sortappr.tar.gz
|
||||
```
|
||||
|
||||
### Publish Docker Image on DockerHub
|
||||
Re-tagging an existing local image:
|
||||
|
||||
```
|
||||
docker tag sortappr <hub-user>/<repo-name>[:<tag>]
|
||||
```
|
||||
|
||||
Login in DockerHub(use your Docker ID):
|
||||
|
||||
```
|
||||
docker login
|
||||
```
|
||||
|
||||
Now you can push this repository to the registry designated by its name or tag:
|
||||
|
||||
```
|
||||
docker push <hub-user>/<repo-name>:<tag>
|
||||
```
|
||||
|
||||
Then logout for security:
|
||||
|
||||
```
|
||||
docker logout
|
||||
```
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# SortApp
|
||||
#
|
||||
# version: 1.0
|
||||
# author: Giancarlo Panichi
|
||||
# date: 2020/10/09
|
||||
#
|
||||
echo "Run Rscript"
|
||||
echo "Token: " $1
|
||||
echo "FileItemId: " $2
|
||||
echo "TempFolderItemId" $3
|
||||
|
||||
Rscript /code/src/sortapp.R $1 $2 $3
|
|
@ -0,0 +1,62 @@
|
|||
#
|
||||
# StorageHubCL.R
|
||||
#
|
||||
# version: 1.0
|
||||
# author: Giancarlo Panichi
|
||||
# date: 2020/10/09
|
||||
|
||||
# GoogleVIS is very verbose
|
||||
#suppressPackageStartupMessages(library(googleVis))
|
||||
|
||||
library(XML)
|
||||
require(XML)
|
||||
library(jsonlite)
|
||||
library(stringr)
|
||||
library(httr)
|
||||
require("httr")
|
||||
|
||||
|
||||
discoverStorageHub<-function(){
|
||||
|
||||
urlString = paste("http://registry.d4science.org/icproxy/gcube/service/GCoreEndpoint/DataAccess/StorageHub?gcube-token=",token,sep="")
|
||||
got<-GET(urlString, timeout(1*3600))
|
||||
xmlfile <- xmlTreeParse(got)
|
||||
class(xmlfile)
|
||||
xmltop = xmlRoot(xmlfile)
|
||||
|
||||
listxpath = xpathSApply(xmltop, "//Results/Result")
|
||||
print(listxpath)
|
||||
listx<-(rapply(listxpath, function(x) head(x, 1)))
|
||||
if (length(listx)>0){
|
||||
storagehubEP<<-as.character(listx[which(listx=="Endpoint")[[1]]+3])
|
||||
}else{
|
||||
cat("Found no storage ub endpoint\n")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
downloadSH<-function(itemid,filename){
|
||||
cat("About to download",itemid,"\n")
|
||||
cat("Downloading...\n")
|
||||
reqDownload<<-paste(sep="",storagehubEP,"/items/",itemid,"/download?exclude=hl:accounting&gcube-token=",token);
|
||||
download.file(url = reqDownload, destfile = filename, method="wget", quiet = T, mode = "w",cacheOK = FALSE)
|
||||
cat("All done.\n")
|
||||
}
|
||||
|
||||
uploadSH<-function(folderitemid,localfilename,filename, descr){
|
||||
cat("About to upload: [folder=",folderitemid,", filename=",filename,"\n")
|
||||
cat("Uploading...\n")
|
||||
reqUpload<<-paste(storagehubEP,"/items/",folderitemid,"/create/FILE?gcube-token=",token,sep="");
|
||||
|
||||
print(reqUpload)
|
||||
res<-POST(reqUpload,
|
||||
body=list(name=filename, description=descr, file=upload_file(localfilename)),
|
||||
add_headers("Content-Type" = "multipart/form-data"),
|
||||
verbose())
|
||||
print(res)
|
||||
cat("All done.\n")
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Install Packages
|
||||
#
|
||||
# Uncomment and add necessary packages
|
||||
#
|
||||
#install.packages("devtools", repos = "http://cran.rstudio.com/",dependencies=TRUE)
|
||||
#install.packages("dplyr", dependencies=TRUE)
|
||||
#install.packages("ggplot2", dependencies=TRUE)
|
||||
#install.packages("forcats", dependencies=TRUE)
|
||||
install.packages("XML", dependencies=TRUE)
|
||||
install.packages("jsonline", dependencies=TRUE)
|
||||
install.packages("stringr", dependencies=TRUE)
|
||||
install.packages("httr", dependencies=TRUE)
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# SortAppr.R
|
||||
#
|
||||
# version: 1.0
|
||||
# author: Giancarlo Panichi
|
||||
# date: 2020/10/09
|
||||
|
||||
|
||||
print("Start SortApp.R")
|
||||
|
||||
args <- commandArgs(trailingOnly = TRUE)
|
||||
print(args)
|
||||
|
||||
print(paste("current dir: ",getwd()),sep="")
|
||||
setwd("/code/src")
|
||||
print(paste("working dir: ",getwd()),sep="")
|
||||
|
||||
source("StorageHubCL.R")
|
||||
|
||||
token<-args[1]
|
||||
itemid<-args[2]
|
||||
tempfolderitemid<-args[3]
|
||||
|
||||
filename<-"sortableelements.txt"
|
||||
|
||||
discoverStorageHub()
|
||||
downloadSH(itemid,filename)
|
||||
|
||||
|
||||
print("Read from SH...")
|
||||
print("Read data from file...")
|
||||
df <- read.table("sortableelements.txt",header = FALSE)
|
||||
print("Sort data...")
|
||||
df <- df[order(df[,1]),]
|
||||
print(df)
|
||||
print("Write data to file...")
|
||||
write.table(df, "result.txt", append = FALSE, sep = " ", dec = ".",
|
||||
row.names = FALSE, col.names = FALSE)
|
||||
print("Save on SH...")
|
||||
|
||||
uploadSH(tempfolderitemid,"result.txt","result.txt","SortApp result")
|
||||
|
||||
print("SortApp.R done")
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue