From d310aea7b0410d036a280960cb9a33a72f238901 Mon Sep 17 00:00:00 2001
From: Sahil Malhotra <smalhotra@mitre.org>
Date: Wed, 9 Feb 2022 09:54:18 -0500
Subject: [PATCH 1/4] debugger

---
 .gitignore          |  2 --
 .vscode/launch.json | 15 +++++++++++++++
 Dockerfile.dev      |  1 +
 dockerRunnerDev.sh  |  4 ++--
 server/build.gradle |  5 +++++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 .vscode/launch.json

diff --git a/.gitignore b/.gitignore
index 626e6a9fc..847e55ffd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -131,7 +131,6 @@ gradle-app.setting
 
 # Settings, classpath and bin directories
 .settings/
-.vscode/
 .classpath
 */.settings
 */.classpath
@@ -148,7 +147,6 @@ gradle-app.setting
 .classpath
 .settings/
 bin/
-.vscode/
 
 # ignore the embeded CDS Library
 CDS-Library
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 000000000..428157c64
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,15 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "java",
+            "name": "Debug CRD (Local + Docker)", // gradle bootRun -Pdebug,
+            "request": "attach",
+            "hostName": "localhost",
+            "port": 8091,
+        }
+    ]
+}
\ No newline at end of file
diff --git a/Dockerfile.dev b/Dockerfile.dev
index f7bba100e..4f3f4a708 100644
--- a/Dockerfile.dev
+++ b/Dockerfile.dev
@@ -9,5 +9,6 @@ WORKDIR /CRD
 RUN gradle build
 # Expose port to access the app
 EXPOSE 8090
+EXPOSE 8091
 # Command to run our app
 CMD ./dockerRunnerDev.sh
diff --git a/dockerRunnerDev.sh b/dockerRunnerDev.sh
index 451690a2e..a605a6e87 100755
--- a/dockerRunnerDev.sh
+++ b/dockerRunnerDev.sh
@@ -19,8 +19,8 @@ gradle build --continuous 2>&1 | tee ./logs/builder.log & CONTINUOUS_BUILD_PID=$
 ( while ! grep -m1 'BUILD SUCCESSFUL' < ./logs/builder.log; do
     sleep 1
 done
-echo "starting crd server..."
-gradle bootRun 2>&1 | tee ./logs/runner.log ) & SERVER_PID=$!
+echo "starting crd server in debug mode..."
+gradle bootRun -Pdebug | tee ./logs/runner.log ) & SERVER_PID=$!
 
 # Handle application background process exiting
 wait $CONTINUOUS_BUILD_PID $SERVER_PID
diff --git a/server/build.gradle b/server/build.gradle
index 5ecf3db06..00c860cdc 100644
--- a/server/build.gradle
+++ b/server/build.gradle
@@ -24,6 +24,11 @@ processResources {
     }
 }   
 
+bootRun {  
+    if (project.hasProperty('debug')) { 
+        jvmArgs=["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:8091"]
+    }
+}
 
 dependencies {
     developmentOnly("org.springframework.boot:spring-boot-devtools")

From 876252dfb63d2a0268ca2edbfa4b7c725c8993d3 Mon Sep 17 00:00:00 2001
From: Sahil Malhotra <smalhotra@mitre.org>
Date: Wed, 9 Feb 2022 10:23:48 -0500
Subject: [PATCH 2/4] delete dockerRunner

---
 dockerRunner.sh | 27 ---------------------------
 1 file changed, 27 deletions(-)
 delete mode 100755 dockerRunner.sh

diff --git a/dockerRunner.sh b/dockerRunner.sh
deleted file mode 100755
index fc2adb2ac..000000000
--- a/dockerRunner.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-
-# Handle closing application on signal interrupt (ctrl + c)
-trap 'kill $CONTINUOUS_BUILD_PID $SERVER_PID; gradle --stop; exit' INT
-
-# Reset log file content for new application boot
-echo "*** Logs for 'gradle installBootDist --continuous' ***" > builder.log
-echo "*** Logs for 'gradle bootRun' ***" > runner.log
-
-# Print that the application is starting in watch mode
-echo "starting application in watch mode..."
-
-# Start the continious build listener process
-echo "starting continuous build listener..."
-gradle build --continuous 2>&1 | tee builder.log & CONTINUOUS_BUILD_PID=$!
-
-# Start server process once initial build finishes  
-( while ! grep -m1 'BUILD SUCCESSFUL' < builder.log; do
-    sleep 15
-done
-echo "starting crd server..."
-gradle bootRun 2>&1 | tee runner.log ) & SERVER_PID=$!
-
-# Handle application background process exiting
-wait $CONTINUOUS_BUILD_PID $SERVER_PID
-EXIT_CODE=$?
-echo "application exited with exit code $EXIT_CODE..."
\ No newline at end of file

From f138afceaf679a7e5bee845f5e3c4b043080e7a9 Mon Sep 17 00:00:00 2001
From: Sahil Malhotra <smalhotra@mitre.org>
Date: Wed, 9 Feb 2022 11:59:30 -0500
Subject: [PATCH 3/4] remove dockerhub hooks, not necessary anymore

---
 hooks/post_checkout | 2 --
 1 file changed, 2 deletions(-)
 delete mode 100644 hooks/post_checkout

diff --git a/hooks/post_checkout b/hooks/post_checkout
deleted file mode 100644
index 8a8a8ef62..000000000
--- a/hooks/post_checkout
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-git clone https://github.com/HL7-DaVinci/CDS-Library.git server/CDS-Library
\ No newline at end of file

From fc059dd98671e7dfd9154c08de2989d57c6531df Mon Sep 17 00:00:00 2001
From: Sahil Malhotra <smalhotra@mitre.org>
Date: Fri, 11 Feb 2022 12:02:47 -0500
Subject: [PATCH 4/4] docker/git ignore

---
 .dockerignore | 12 ++++++++++++
 .gitignore    |  1 +
 2 files changed, 13 insertions(+)
 create mode 100644 .dockerignore

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 000000000..b59fc9b0f
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,12 @@
+.git
+target
+build
+bin
+logs
+.gradle
+server/.gradle
+server/bin
+server/build
+server/ValueSetCache
+operations/build
+resources/build
diff --git a/.gitignore b/.gitignore
index 847e55ffd..9a2fd3381 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,6 +69,7 @@ fabric.properties
 
 # Log file
 *.log
+logs/
 
 # BlueJ files
 *.ctxt
