diff --git a/.circleci/config.yml b/.circleci/config.yml index 2bc2aa4ed..11e615743 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,6 +18,7 @@ jobs: apt-get update apt-get install -y python-pip git pip install awscli + pip install psutil pip install argostranslate apt-get clean && apt-get autoclean - checkout @@ -54,6 +55,7 @@ jobs: apt-get install -y python-pip git pip install awscli pip install argostranslate + pip install psutil apt-get clean && apt-get autoclean - checkout - restore_cache: diff --git a/Dockerfile b/Dockerfile index 33966b605..3b03f6931 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,66 +1,84 @@ -FROM ubuntu - -RUN apt-get update -y -RUN apt-get install -y sudo - -#get java -RUN sudo apt install -y openjdk-8-jdk - -RUN sudo apt-get install -y wget -RUN sudo apt-get install -y unzip -RUN sudo apt-get install -y curl +FROM sbtscala/scala-sbt:eclipse-temurin-jammy-8u352-b08_1.9.0_2.12.17 AS builder #build varaibles -ENV SBT_VERSION 1.1.5 +#ENV SBT_VERSION 1.1.5 ENV PROJECT_HOME /usr/src -#database variables -ENV DB_URL "jdbc:mysql://localhost:3306/femr_db?characterEncoding=UTF-8&useSSL=false" -ENV DB_USER "username" -ENV DB_PASS "password" +#RUN mkdir -p $PROJECT_HOME/activator $PROJECT_HOME/app -RUN mkdir -p $PROJECT_HOME/activator $PROJECT_HOME/app +RUN apt-get update && apt-get install -y \ + unzip \ + && rm -rf /var/lib/apt/lists/* -WORKDIR $PROJECT_WORKPLACE/activator +#WORKDIR $PROJECT_WORKPLACE/activator +#RUN wget https://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip && \ +# unzip typesafe-activator-1.3.6.zip && chmod a+x activator-dist-1.3.6/activator +#ENV PATH $PATH:/activator-1.3.6 # Install Play Framework -RUN curl -O https://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip +#RUN curl -O https://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip -RUN unzip typesafe-activator-1.3.6.zip -d / && rm typesafe-activator-1.3.6.zip && ls && sudo chmod a+x /activator-dist-1.3.6/activator -ENV PATH $PATH:/activator-1.3.6 +#RUN unzip typesafe-activator-1.3.6.zip -d / && rm typesafe-activator-1.3.6.zip && ls && sudo chmod a+x /activator-dist-1.3.6/activator # Install curl -RUN \ - apt-get update && \ - apt-get -y install curl +#RUN \ + # apt-get update && \ + # apt-get -y install curl # Install sbt -RUN \ - mkdir /working/ && \ - cd /working/ && \ - curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/debian/sbt-$SBT_VERSION.deb && \ - dpkg -i sbt-$SBT_VERSION.deb && \ - rm sbt-$SBT_VERSION.deb && \ - apt-get update && \ - apt-get install sbt && \ - cd && \ - rm -r /working/ && \ - sbt sbtVersion +#RUN \ + #mkdir /working/ && \ + #cd /working/ && \ + #curl -L -o sbt-$SBT_VERSION.deb https://repo.scala-sbt.org/scalasbt/debian/sbt-$SBT_VERSION.deb && \ + #dpkg -i sbt-$SBT_VERSION.deb && \ + #rm sbt-$SBT_VERSION.deb && \ + #apt-get update && \ + #apt-get install sbt && \ + #cd && \ + #rm -r /working/ && \ + #sbt sbtVersion + +COPY Build.sbt . +COPY project ./project + +RUN --mount=type=cache,target=/root/.ivy2 \ + --mount=type=cache,target=/root/.sbt \ + sbt update # Setup path variables and copy fEMR into container -ENV PATH $PROJECT_HOME/activator/activator-dist-1.3.10/bin:$PATH -ENV PATH $PROJECT_WORKPLACE/build/target/universal/stage/bin:$PATH +#ENV PATH $PROJECT_HOME/activator/activator-dist-1.3.10/bin:$PATH +#ENV PATH $PROJECT_WORKPLACE/build/target/universal/stage/bin:$PATH COPY . $PROJECT_HOME/app +COPY ../speedtest /usr/src/speedtest WORKDIR $PROJECT_HOME/app RUN \ rm $PROJECT_HOME/app/conf/application.conf && \ mv $PROJECT_HOME/app/conf/application.docker.conf $PROJECT_HOME/app/conf/application.conf -RUN sbt clean compile +#RUN sbt clean compile +RUN --mount=type=cache,target=/root/.ivy2 \ + --mount=type=cache,target=/root/.sbt \ + sbt dist + +WORKDIR $PROJECT_HOME/app/target/universal +RUN unzip femr-*.zip && rm femr-*.zip + +FROM openjdk:jre-alpine + +RUN apk add --no-cache bash python3 py3-pip gcc python3-dev musl-dev linux-headers +RUN pip3 install psutil + +#database variables +ENV DB_URL "jdbc:mysql://localhost:3306/femr_db?characterEncoding=UTF-8&useSSL=false" +ENV DB_USER "username" +ENV DB_PASS "password" + +COPY --from=builder /usr/src/app/target/universal/femr-* /opt/bin/femr #open port 9000 for connections EXPOSE 9000 # run fEMR using env variables -ENTRYPOINT url=$DB_URL usr=$DB_USER pass=$DB_PASS sbt ~run \ No newline at end of file +#ENTRYPOINT url=$DB_URL usr=$DB_USER pass=$DB_PASS sbt ~run +ENTRYPOINT ["/bin/bash", "-c", "/opt/bin/femr/bin/femr"] \ No newline at end of file diff --git a/app/femr/business/services/system/UpdatesService.java b/app/femr/business/services/system/UpdatesService.java index 5407fa26d..d0b743585 100644 --- a/app/femr/business/services/system/UpdatesService.java +++ b/app/femr/business/services/system/UpdatesService.java @@ -83,7 +83,7 @@ public ServiceResponse> updateNetworkStatuses() ServiceResponse> response = new ServiceResponse<>(); ArrayList data = new ArrayList<>(); try { - data = BackEndControllerHelper.executeSpeedTestScript("speedtest/sptest.py"); + data = BackEndControllerHelper.executeSpeedTestScript("/usr/src/speedtest/sptest.py"); //Update Status Float Ping = Float.parseFloat(data.get(2)); String updatedStatus = "Connection stable"; diff --git a/app/femr/common/dtos/ServiceResponse.java b/app/femr/common/dtos/ServiceResponse.java index cbec5dfc8..898e106fe 100644 --- a/app/femr/common/dtos/ServiceResponse.java +++ b/app/femr/common/dtos/ServiceResponse.java @@ -34,7 +34,7 @@ public ServiceResponse() { } public boolean hasErrors() { - return errors.size() > 0; + return !errors.isEmpty(); } public T getResponseObject() { diff --git a/app/femr/data/DataModelMapper.java b/app/femr/data/DataModelMapper.java index 8fa6fe3cf..661bcce65 100644 --- a/app/femr/data/DataModelMapper.java +++ b/app/femr/data/DataModelMapper.java @@ -451,6 +451,7 @@ public IPhoto createPhoto(String description, String filePath, byte[] photoData) if (StringUtils.isNullOrWhiteSpace(description)) photo.setDescription(""); else photo.setDescription(description); photo.setFilePath(filePath); + photo.setInsertTS(new Date()); if(photoData != null) photo.setPhotoBlob(photoData); diff --git a/app/femr/ui/controllers/BackEndControllerHelper.java b/app/femr/ui/controllers/BackEndControllerHelper.java index dc3db7dde..0b4480566 100644 --- a/app/femr/ui/controllers/BackEndControllerHelper.java +++ b/app/femr/ui/controllers/BackEndControllerHelper.java @@ -23,7 +23,7 @@ public static void executePythonScript(String absPath) { public static ArrayList executeSpeedTestScript(String absPath) { ArrayList speedInfo = new ArrayList<>(); try { - ProcessBuilder pb = new ProcessBuilder("python", absPath); + ProcessBuilder pb = new ProcessBuilder("python3", absPath); Process p = pb.start(); BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream(), "UTF-8")); diff --git a/app/femr/ui/controllers/admin/UpdatesController.java b/app/femr/ui/controllers/admin/UpdatesController.java index 344c958fc..bd35d6d9f 100644 --- a/app/femr/ui/controllers/admin/UpdatesController.java +++ b/app/femr/ui/controllers/admin/UpdatesController.java @@ -75,6 +75,8 @@ public Result manageGet() { if (networkStatusesResponse.hasErrors()) { throw new RuntimeException(); } + + for (INetworkStatus ns : networkStatusesResponse.getResponseObject()) { indexViewModel.setNetworkStatus(ns.getName(), ns.getValue()); } @@ -83,6 +85,8 @@ public Result manageGet() { if (kitStatusesResponse.hasErrors()) { throw new RuntimeException(); } + + for (IKitStatus ks : kitStatusesResponse.getResponseObject()) { indexViewModel.setKitStatus(ks.getName(), ks.getValue()); } @@ -91,6 +95,8 @@ public Result manageGet() { if (databaseStatusResponse.hasErrors()) { throw new RuntimeException(); } + + for (IDatabaseStatus ds : databaseStatusResponse.getResponseObject()) { indexViewModel.setDatabaseStatus(ds.getName(), ds.getValue()); } @@ -101,6 +107,7 @@ public Result manageGet() { if(languagesResponse.hasErrors()){ throw new RuntimeException(); } + for(ILanguageCode lang : languagesResponse.getResponseObject()) { indexViewModel.setLanguages(lang); } @@ -140,6 +147,7 @@ public Result kitUpdatePost() { return manageGet(); } + public Result refreshInternetStatus() { ServiceResponse> updateResponse = updatesService.updateNetworkStatuses(); if (updateResponse.hasErrors()) { @@ -151,6 +159,7 @@ public Result refreshInternetStatus() { } public Result updateLanguage(){ + String langCode = request().getQueryString("code"); boolean updateScheduled = request().getQueryString("update").equals("true"); diff --git a/app/femr/ui/views/admin/updates/manage.scala.html b/app/femr/ui/views/admin/updates/manage.scala.html index 2c94b47c0..adf8eec08 100644 --- a/app/femr/ui/views/admin/updates/manage.scala.html +++ b/app/femr/ui/views/admin/updates/manage.scala.html @@ -9,12 +9,16 @@ @additionalStyles = { } + @additionalMessages = { + @for(message <- messages) { -

@message

+

@message

} + } - @downloadSpeed = @{viewModel.getNetworkStatus.get("Download").substring(0, viewModel.getNetworkStatus.get("Download").indexOf(".")).toInt} + + @downloadSpeed = @{viewModel.getNetworkStatus.get("Download").substring(0, viewModel.getNetworkStatus.get("Download").indexOf(".")).toInt} @admin("Updates", currentUser, styles = additionalStyles, assets = assets, message = additionalMessages) { @@ -23,7 +27,7 @@

Network Status

- ` +
@helper.form(action = UpdatesController.refreshInternetStatus()) { @@ -42,7 +46,7 @@

Network Status

}
- @for((key,valyew) <- viewModel.getNetworkStatus) { + @for((key,valyew) <- viewModel.getNetworkStatus) { @@ -88,6 +92,7 @@

Languages

+

Scheduled Languages

@@ -132,7 +137,7 @@

Database Status

Available Updates

@key: @valyew
- @if(viewModel.isUpdateAvailable) { + @if(viewModel.isUpdateAvailable) { @helper.form(action = UpdatesController.kitUpdatePost()) { @@ -145,4 +150,5 @@

Available Updates

+ } diff --git a/conf/application.docker.conf b/conf/application.docker.conf index 9734866f2..408088703 100644 --- a/conf/application.docker.conf +++ b/conf/application.docker.conf @@ -21,9 +21,9 @@ play.il8n.langs="en" #Register MySQL database settings db.default.driver="com.mysql.jdbc.Driver" -db.default.url=${?url} -db.default.username=${?usr} -db.default.password=${?pass} +db.default.url=${?DB_URL} +db.default.username=${?DB_USER} +db.default.password=${?DB_PASS} db.default.logStatements=false #Register paths for photos diff --git a/conf/logback.xml b/conf/logback.xml index 957302953..a16636dee 100644 --- a/conf/logback.xml +++ b/conf/logback.xml @@ -34,7 +34,7 @@ - + diff --git a/docker-compose.yml b/docker-compose.yml index 3ba626d26..c37c3cafb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,15 +28,14 @@ services: tty: true ports: - '9000:9000' - expose: - - '9000' - volumes: - - ./femr/conf:/home/femrapp/conf + environment: DB_URL: 'jdbc:mysql://db:3306/femr_db?characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true' DB_USER: 'femr' DB_PASS: 'password' + volumes: + - ./speedtest:/usr/src/speedtest volumes:
Kit Update: Available