diff --git a/app/Http/Controllers/ExercicioController.php b/app/Http/Controllers/ExercicioController.php index 6bf6841..2a6aaa0 100644 --- a/app/Http/Controllers/ExercicioController.php +++ b/app/Http/Controllers/ExercicioController.php @@ -170,7 +170,7 @@ private function corretoR(Exercicio $exercicio, string $file) try { $cnx = new Connection('r'); - $rcode = 'source("/usr/local/src/notar/corretor.R");' + $rcode = '' // database auth . 'dbusr <- "' . env('DB_USERNAME') . '";' . 'dbpass <- "' . env('DB_PASSWORD') . '";' @@ -178,13 +178,17 @@ private function corretoR(Exercicio $exercicio, string $file) . 'con <- connect(dbusr, dbpass, dbname);' // import files . 'file.copy(list.files("/arquivos/",recursive=TRUE,full.names=TRUE),".");' + // Limits memory usage + . 'rlimit_as(1e10);' + . 'rlimit_cpu(15);' // run corretoR . 'res <- notaR(' . $exercicio->id . ',"' . $file . '");' . 'unlink("*",recursive=TRUE);' + // Returns the "res" object to caller . 'res;' ; $r = $cnx->evalString($rcode); - } catch (RserveException $e) { + } catch (Exception $e) { return [ 'status' => 'danger', 'mensagem' => 'Ocorreu um erro na correção do exercício! Por favor verifique seu código ou contate um administrador.', @@ -343,12 +347,15 @@ private function recebeCodigo(string $codigo, Exercicio $exercicio, \Illuminate\ * Show the form for editing the specified resource. * * @param \App\Models\Exercicio $exercicio - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\View\View */ public function edit(Exercicio $exercicio) { $this->authorize('edit', $exercicio); - return View('exercicio.edit')->with('exercicio', $exercicio)->with('exercicio.testes', $exercicio->testes)->with('pacotesR', $this->getInstalledPackages()); + return View('exercicio.edit') + ->with('exercicio', $exercicio) + ->with('exercicio.testes', $exercicio->testes) + ->with('pacotesR', $this->getInstalledPackages()); } /** diff --git a/deploy.sh b/deploy.sh index 6e230e0..ed70cd7 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,6 +1,14 @@ #!/bin/sh git pull -docker-compose down -docker-compose build -docker-compose up -d -docker exec -t --env-file .env notar_app_1 ./docker-deploy.sh +COMPOSE="docker compose" +CONTAINER="notar-app-1" +if command -v docker-compose; then + echo "Using docker-compose" + COMPOSE="docker-compose" + CONTAINER="notar_app_1" +fi + +$COMPOSE down +$COMPOSE build +$COMPOSE up -d +docker exec -t --env-file .env $CONTAINER ./docker-deploy.sh diff --git a/docker-compose.local-override.yml b/docker-compose.local-override.yml deleted file mode 100644 index a6eedda..0000000 --- a/docker-compose.local-override.yml +++ /dev/null @@ -1,19 +0,0 @@ -# For more information: https://laravel.com/docs/sail -version: '3' -services: - mailhog: - image: 'mailhog/mailhog:latest' - ports: - - 1025:1025 - - 8025:8025 - networks: - - sail - r: - build: - context: ./docker/R/ - dockerfile: Dockerfile - image: r - expose: - - '6311' - networks: - - sail diff --git a/docker-compose.yml b/docker-compose.yml index 82a5822..1a93164 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,4 @@ # For more information: https://laravel.com/docs/sail -version: '3' services: app: build: diff --git a/docker-deploy.sh b/docker-deploy.sh index ce80715..0f602ba 100755 --- a/docker-deploy.sh +++ b/docker-deploy.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Installs and upgrades any new PHP libraries if [ "$APP_ENV" == "production" ]; then diff --git a/docker/R/Dockerfile b/docker/R/Dockerfile index b991070..155ed5c 100644 --- a/docker/R/Dockerfile +++ b/docker/R/Dockerfile @@ -12,12 +12,6 @@ RUN apt-get update --fix-missing \ r-cran-rmysql \ && rm -rf /var/lib/apt/lists/* - -# Copies the required files for notaR -RUN mkdir -p /usr/local/src/notar -COPY . /usr/local/src/notar -WORKDIR /usr/local/src/notar - # Install packages used in exercises RUN apt-get update --fix-missing \ && apt-get install -y --no-install-recommends \ @@ -30,11 +24,16 @@ RUN apt-get update --fix-missing \ RUN install2.r --error --skipinstalled --ncpus -1 \ Rsampling \ EcoVirtual \ + unix \ && rm -rf /tmp/downloaded_packages +# Copies the required files for notaR +RUN mkdir -p /usr/local/src/notar +COPY . /usr/local/src/notar +WORKDIR /usr/local/src/notar # We will listen on 6311 EXPOSE 6311 # Run the Rserve library: -CMD R --vanilla -e "library(Rserve);" -e "run.Rserve(remote=TRUE);" +CMD Rscript bootstrap.R diff --git a/docker/R/bootstrap.R b/docker/R/bootstrap.R new file mode 100644 index 0000000..4c33f90 --- /dev/null +++ b/docker/R/bootstrap.R @@ -0,0 +1,4 @@ +library(Rserve); +library(unix); +source("/usr/local/src/notar/corretor.R"); +run.Rserve(remote=TRUE); diff --git a/docker/R/corretor.R b/docker/R/corretor.R index 40eea4e..ca3926a 100644 --- a/docker/R/corretor.R +++ b/docker/R/corretor.R @@ -75,4 +75,4 @@ notaR <- function (id.exerc, arquivo) { # con <- connect('notaR', 'notaRPW', 'notaR') # corretoR(1, "y<-1;x<-2") # ou -# notaR(1, "/tmp/file.R") \ No newline at end of file +# notaR(1, "/tmp/file.R")