Skip to content

Commit

Permalink
update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
thierrymoudiki committed Jan 13, 2024
1 parent 157f27c commit 67e0851
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ WORKDIR /app
RUN apt-get update && apt-get install -y \
r-base \
r-base-dev
RUN Rscript -e "utils::install.packages('foreach', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('Rcpp', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('snow', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('forecast', repos='https://cran.rstudio.com', dependencies=TRUE)"
RUN Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', dependencies=TRUE)"

# Copy all files from the current directory to /app in the container
COPY . .
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["thierrymoudiki <[email protected]>"]
version = "0.1.0"

[compat]
julia = "1.6"
julia = "1.10"
Pkg = "1.6.7"
RCall = "0.14.0"

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

## Note to self or developers

### Docker

```
docker build -t ahead .
docker run ahead
```

### Install locally

- Install `RCall`: https://juliainterop.github.io/RCall.jl/stable/installation/
- Getting started with `RCall`: https://juliainterop.github.io/RCall.jl/latest/gettingstarted.html
- Julia `RCall`: https://www.geeksforgeeks.org/julia-rcall/
Expand Down
50 changes: 32 additions & 18 deletions src/Ahead.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ module Ahead
# exports
export dynrmf

if Sys.islinux()
run(`ls -la`)
run(`sudo apt update`)
run(`sudo apt install r-base r-base-dev -y`)
run(`sudo apt-get install libcurl4-openssl-dev`)
run(`sudo apt update`)
run(`sudo apt upgrade`)
run(`Rscript --version`)
username = strip(chomp(read(`whoami`, String)))
run(`sudo chown -R $username:$username /usr/local/lib/R/site-library`) # check permissions
if Sys.islinux()
try
run(`ls -la`)
run(`sudo apt update`)
run(`sudo apt install r-base r-base-dev -y`)
run(`sudo apt-get install libcurl4-openssl-dev`)
run(`sudo apt update`)
run(`sudo apt upgrade`)
run(`Rscript --version`)
username = strip(chomp(read(`whoami`, String)))
run(`sudo chown -R $username:$username /usr/local/lib/R/site-library`) # check permissions
catch e
println("Either R is already installed, or can't be installed on this machine")
end
end

# Run the `which R` command to get the path to the R executable
Expand All @@ -30,8 +34,12 @@ module Ahead
using RCall

if Sys.islinux()
username = strip(chomp(read(`whoami`, String)))
run(`sudo usermod -aG staff $username`)
try
username = strip(chomp(read(`whoami`, String)))
run(`sudo usermod -aG staff $username`)
catch e
println("Can't define as staff")
end
end

if Sys.islinux() || Sys.isapple()
Expand All @@ -41,12 +49,18 @@ module Ahead
run(`sudo Rscript -e "utils::install.packages('snow', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('forecast', repos='https://cran.rstudio.com', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', dependencies=TRUE)"`)
catch e
run(`sudo Rscript -e "install.packages('foreach', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('Rcpp', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('snow', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('forecast', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', lib= '.', dependencies=TRUE)"`)
catch e1
try
run(`sudo Rscript -e "install.packages('foreach', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('Rcpp', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('snow', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "install.packages('forecast', repos='https://cran.rstudio.com', lib= '.', dependencies=TRUE)"`)
run(`sudo Rscript -e "utils::install.packages('ahead', repos='https://techtonique.r-universe.dev', lib= '.', dependencies=TRUE)"`)
catch e2
println("Can't run Rscript")
end
finally
println("Can't run Rscript")
end
end

Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Ahead
using Test

@testset "Ahead.jl" begin
val = Ahead.dynrmf([1,2,3,4,5,6,7,8,9,10])
val = Ahead.dynrmf([1,2,3,4,5,6,7,8,9,10])
println(val)
@test isapprox(round(val[:residuals][1]), 0)
end

0 comments on commit 67e0851

Please sign in to comment.