Skip to content

Commit

Permalink
Added handling of different environments for speedtest.py call in adm…
Browse files Browse the repository at this point in the history
…in/updates (#747)

* Triage image upload now uploads image properly for patient profile photo

* updated iPhotoService javadoc

* Fixed update page, refresh internet status still broken

* python script needs to be ran first, working on it

* internet update button works admin/updates

* Merged Kevin's changes

* Changed scala file

* Added compatibility for running refresh internet status in docker and IDE
  • Loading branch information
bholt13 authored Nov 19, 2024
1 parent 260efe3 commit 28182dd
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 55 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
96 changes: 57 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
#ENTRYPOINT url=$DB_URL usr=$DB_USER pass=$DB_PASS sbt ~run
ENTRYPOINT ["/bin/bash", "-c", "/opt/bin/femr/bin/femr"]
12 changes: 11 additions & 1 deletion app/femr/business/services/system/UpdatesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.UnresolvedPermission;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -83,7 +85,15 @@ public ServiceResponse<List<? extends INetworkStatus>> updateNetworkStatuses()
ServiceResponse<List<? extends INetworkStatus>> response = new ServiceResponse<>();
ArrayList<String> data = new ArrayList<>();
try {
data = BackEndControllerHelper.executeSpeedTestScript("speedtest/sptest.py");
String isDocker = System.getenv("IS_DOCKER");
if("true".equals(isDocker)) { //running in docker
data = BackEndControllerHelper.executeSpeedTestScript("/usr/src/speedtest/sptest.py");
}else{ //running in IDE
Path speedPath = Paths.get(System.getProperty("user.dir"), "speedtest", "sptest.py");
data = BackEndControllerHelper.executeSpeedTestScript(speedPath.toString());
}
//data = BackEndControllerHelper.executeSpeedTestScript("/usr/src/speedtest/sptest.py");
//data = BackEndControllerHelper.executeSpeedTestScript("speedtest/sptest.py");
//Update Status
Float Ping = Float.parseFloat(data.get(2));
String updatedStatus = "Connection stable";
Expand Down
2 changes: 1 addition & 1 deletion app/femr/common/dtos/ServiceResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ServiceResponse() {
}

public boolean hasErrors() {
return errors.size() > 0;
return !errors.isEmpty();
}

public T getResponseObject() {
Expand Down
1 change: 1 addition & 0 deletions app/femr/data/DataModelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion app/femr/ui/controllers/BackEndControllerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public static void executePythonScript(String absPath) {
public static ArrayList<String> executeSpeedTestScript(String absPath) {
ArrayList<String> speedInfo = new ArrayList<>();
try {
ProcessBuilder pb = new ProcessBuilder("python", absPath);
ProcessBuilder pb;
if(absPath.equals("/usr/src/speedtest/sptest.py")){
pb = new ProcessBuilder("python3", absPath);
}else{
pb = new ProcessBuilder("python", absPath);
}
Process p = pb.start();
BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream(), "UTF-8"));

Expand Down
9 changes: 9 additions & 0 deletions app/femr/ui/controllers/admin/UpdatesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public Result manageGet() {
if (networkStatusesResponse.hasErrors()) {
throw new RuntimeException();
}


for (INetworkStatus ns : networkStatusesResponse.getResponseObject()) {
indexViewModel.setNetworkStatus(ns.getName(), ns.getValue());
}
Expand All @@ -83,6 +85,8 @@ public Result manageGet() {
if (kitStatusesResponse.hasErrors()) {
throw new RuntimeException();
}


for (IKitStatus ks : kitStatusesResponse.getResponseObject()) {
indexViewModel.setKitStatus(ks.getName(), ks.getValue());
}
Expand All @@ -91,6 +95,8 @@ public Result manageGet() {
if (databaseStatusResponse.hasErrors()) {
throw new RuntimeException();
}


for (IDatabaseStatus ds : databaseStatusResponse.getResponseObject()) {
indexViewModel.setDatabaseStatus(ds.getName(), ds.getValue());
}
Expand All @@ -101,6 +107,7 @@ public Result manageGet() {
if(languagesResponse.hasErrors()){
throw new RuntimeException();
}

for(ILanguageCode lang : languagesResponse.getResponseObject()) {
indexViewModel.setLanguages(lang);
}
Expand Down Expand Up @@ -140,6 +147,7 @@ public Result kitUpdatePost() {

return manageGet();
}

public Result refreshInternetStatus() {
ServiceResponse<List<? extends INetworkStatus>> updateResponse = updatesService.updateNetworkStatuses();
if (updateResponse.hasErrors()) {
Expand All @@ -151,6 +159,7 @@ public Result refreshInternetStatus() {
}

public Result updateLanguage(){

String langCode = request().getQueryString("code");
boolean updateScheduled = request().getQueryString("update").equals("true");

Expand Down
16 changes: 11 additions & 5 deletions app/femr/ui/views/admin/updates/manage.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
@additionalStyles = {
<link rel="stylesheet" href="@assets.path("css/admin/configure.css")">
}

@additionalMessages = {

@for(message <- messages) {
<p class="adminMessage">@message</p>
<p class="adminMessage">@message</p>
}

}
@downloadSpeed = @{viewModel.getNetworkStatus.get("Download").substring(0, viewModel.getNetworkStatus.get("Download").indexOf(".")).toInt}

@downloadSpeed = @{ viewModel.getNetworkStatus.get("Download").split(" ")(0).toFloat.toInt }

@admin("Updates", currentUser, styles = additionalStyles, assets = assets, message = additionalMessages) {

Expand All @@ -23,7 +27,7 @@
<div id="network-status">
<h2>Network Status</h2>

<table id="networkstatus">`
<table id="networkstatus">
<div>
<div>
@helper.form(action = UpdatesController.refreshInternetStatus()) {
Expand All @@ -42,7 +46,7 @@ <h2>Network Status</h2>
}
</div>
</div>
@for((key,valyew) <- viewModel.getNetworkStatus) {
@for((key,valyew) <- viewModel.getNetworkStatus) {
<tr>
<td>@key:</td>
<td>@valyew</td>
Expand Down Expand Up @@ -88,6 +92,7 @@ <h2>Languages</h2>
</div>
</div>


<div id="right-div">
<div id="language-package-updates">
<h2>Scheduled Languages</h2>
Expand Down Expand Up @@ -132,7 +137,7 @@ <h2>Database Status</h2>
<h2>Available Updates</h2>
<table>
<tr>
@if(viewModel.isUpdateAvailable) {
@if(viewModel.isUpdateAvailable) {
@helper.form(action = UpdatesController.kitUpdatePost()) {
<td>Kit Update: Available</td><td>
<input type="submit" class="fButton" value="Update"/></td>
Expand All @@ -145,4 +150,5 @@ <h2>Available Updates</h2>
</div>
</div>
</div>

}
6 changes: 3 additions & 3 deletions conf/application.docker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />

<root level="WARN">
<root level="INFO">
<appender-ref ref="ASYNCFILE" />
<appender-ref ref="ASYNCSTDOUT" />
</root>
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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'
IS_DOCKER: 'true'

volumes:
- ./speedtest:/usr/src/speedtest


volumes:
Expand Down

0 comments on commit 28182dd

Please sign in to comment.