From 68e2de863bf2d8477fda211b2ba19520da996fd3 Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 18:08:25 -0500 Subject: [PATCH 01/10] initial dockerfile --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..28f2821 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM openjdk:8-alpine + +RUN apk add --no-cache apache-ant + +COPY . /usr/src/unobot +WORKDIR /usr/src/unobot +RUN mvn package +CMD ["java", "-jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar"] From 33e3a0e41f3c8120fa4b9c528b06c9d0709e0bc8 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 22 Aug 2020 23:17:08 +0000 Subject: [PATCH 02/10] updating the dockerfile to properly build and run the container --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28f2821..0792132 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM openjdk:8-alpine -RUN apk add --no-cache apache-ant +RUN apk add --no-cache maven COPY . /usr/src/unobot WORKDIR /usr/src/unobot RUN mvn package -CMD ["java", "-jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar"] +CMD java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar From fcd05103ceaadd4d9b2643f889c0e2b7aecf439e Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 18:19:30 -0500 Subject: [PATCH 03/10] Update README.md adding a stub for the build and run with docker --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 34c93bd..fa48970 100755 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ and allows members of the channel to play a game of uno. It also has an AI so it 1. You must have Java 1.7 JDK or higher installed. 2. The Java bin folder must be in your classpath if you are running windows. 3. Maven +4. Alternatively: The bot can be run with only having docker installed. ## Installation @@ -17,6 +18,10 @@ and allows members of the channel to play a game of uno. It also has an AI so it 3. run `mvn package` (you will have to cd to UnoBot's directory) 4. run `UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` using the `java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` command +## Building with Docker +1. docker build . -t unobot +2. docker run unobot +3. ??? Environment variables to come for configuring the docker run ### values in the config file Server - if no value given it will default to localhost From 5c7d6f567a0e68196ed7af85881c514e9816cce4 Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 20:58:28 -0500 Subject: [PATCH 04/10] adding environment properties and java properties as inputs into the bot --- .../java/com/mjsalerno/unobot/UnoBotMain.java | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java index 8113a0d..54b8762 100755 --- a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java +++ b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java @@ -28,16 +28,43 @@ * @author roofis0 */ public class UnoBotMain { - - + + public static String getVarOrDefault(String key, String def) { + String javaProp = System.getProperty(key, def); + return System.getenv().getOrDefault(key, javaProp); + } public static void main(String[] args) throws Exception { Properties p = new Properties(); - try (FileInputStream in = new FileInputStream(new File("./config.ini"))) { - p.load(in); + + String path = getVarOrDefault("CONFIG_PATH","./"); + String filename = path + "/config.ini"; + File configFile = new File(filename); + if (configFile.exists()) { + try (FileInputStream in = new FileInputStream(configFile)) { + p.load(in); + } + } else { // Allows loading of the config values from either java properties or environment variables + p.setProperty("Server", getVarOrDefault("Server", "localhost")); + p.setProperty("Port", getVarOrDefault("Port", "6667")); + p.setProperty("Channel", getVarOrDefault("#uno", "")); + p.setProperty("Nick", getVarOrDefault("unoBot", "")); + + p.setProperty("BotOps", getVarOrDefault("BotOps", "")); + p.setProperty("ScoreBoardFileName", path + getVarOrDefault("ScoreBoardFileName", "/ScoreBoard.dat")); + p.setProperty("UpdateScript", getVarOrDefault("UpdateScript", null)); + p.setProperty("SSL", getVarOrDefault("SSL", "false")); + p.setProperty("Token", getVarOrDefault("Token", "!")); + p.setProperty("nickSrvPasswd", getVarOrDefault("nickSrvPasswd", null)); + p.setProperty("serverPasswd", getVarOrDefault("serverPasswd", null)); + p.setProperty("webIRCPasswd", getVarOrDefault("webIRCPasswd", null)); + + p.setProperty("aiWebIRCPasswd", getVarOrDefault("aiWebIRCPasswd", null)); + p.setProperty("aiServerPasswd", getVarOrDefault("aiServerPasswd", null)); + p.setProperty("aiNickSrvPasswd", getVarOrDefault("aiNickSrvPasswd", null)); + p.setProperty("AINick", getVarOrDefault("AINick", "unoAI")); } - // System.setProperty("socksProxyHost", "localhost"); // System.setProperty("socksProxyPort", "9999"); From 0f357d1429e8f5b193846f5d98f76e7ec640c6d7 Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 21:09:37 -0500 Subject: [PATCH 05/10] avoiding a null pointer exception if not setting a property from the env. --- .../java/com/mjsalerno/unobot/UnoBotMain.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java index 54b8762..716a7a1 100755 --- a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java +++ b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java @@ -33,6 +33,12 @@ public static String getVarOrDefault(String key, String def) { String javaProp = System.getProperty(key, def); return System.getenv().getOrDefault(key, javaProp); } + public static putToProperties(Properties p, String key, String value) { + if (value == null) { + return; + } + p.setProperty(key, value); + } public static void main(String[] args) throws Exception { @@ -46,24 +52,24 @@ public static void main(String[] args) throws Exception { p.load(in); } } else { // Allows loading of the config values from either java properties or environment variables - p.setProperty("Server", getVarOrDefault("Server", "localhost")); - p.setProperty("Port", getVarOrDefault("Port", "6667")); - p.setProperty("Channel", getVarOrDefault("#uno", "")); - p.setProperty("Nick", getVarOrDefault("unoBot", "")); + putToProperties(p, "Server", getVarOrDefault("Server", "localhost")); + putToProperties(p, "Port", getVarOrDefault("Port", "6667")); + putToProperties(p, "Channel", getVarOrDefault("#uno", "")); + putToProperties(p, "Nick", getVarOrDefault("unoBot", "")); - p.setProperty("BotOps", getVarOrDefault("BotOps", "")); - p.setProperty("ScoreBoardFileName", path + getVarOrDefault("ScoreBoardFileName", "/ScoreBoard.dat")); - p.setProperty("UpdateScript", getVarOrDefault("UpdateScript", null)); - p.setProperty("SSL", getVarOrDefault("SSL", "false")); - p.setProperty("Token", getVarOrDefault("Token", "!")); - p.setProperty("nickSrvPasswd", getVarOrDefault("nickSrvPasswd", null)); - p.setProperty("serverPasswd", getVarOrDefault("serverPasswd", null)); - p.setProperty("webIRCPasswd", getVarOrDefault("webIRCPasswd", null)); + putToProperties(p, "BotOps", getVarOrDefault("BotOps", "")); + putToProperties(p, "ScoreBoardFileName", path + getVarOrDefault("ScoreBoardFileName", "/ScoreBoard.dat")); + putToProperties(p, "UpdateScript", getVarOrDefault("UpdateScript", null)); + putToProperties(p, "SSL", getVarOrDefault("SSL", "false")); + putToProperties(p, "Token", getVarOrDefault("Token", "!")); + putToProperties(p, "nickSrvPasswd", getVarOrDefault("nickSrvPasswd", null)); + putToProperties(p, "serverPasswd", getVarOrDefault("serverPasswd", null)); + putToProperties(p, "webIRCPasswd", getVarOrDefault("webIRCPasswd", null)); - p.setProperty("aiWebIRCPasswd", getVarOrDefault("aiWebIRCPasswd", null)); - p.setProperty("aiServerPasswd", getVarOrDefault("aiServerPasswd", null)); - p.setProperty("aiNickSrvPasswd", getVarOrDefault("aiNickSrvPasswd", null)); - p.setProperty("AINick", getVarOrDefault("AINick", "unoAI")); + putToProperties(p, "aiWebIRCPasswd", getVarOrDefault("aiWebIRCPasswd", null)); + putToProperties(p, "aiServerPasswd", getVarOrDefault("aiServerPasswd", null)); + putToProperties(p, "aiNickSrvPasswd", getVarOrDefault("aiNickSrvPasswd", null)); + putToProperties(p, "AINick", getVarOrDefault("AINick", "unoAI")); } // System.setProperty("socksProxyHost", "localhost"); // System.setProperty("socksProxyPort", "9999"); From eef98cdbf2f785a2766d12bd1f64044379467fee Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 21:11:18 -0500 Subject: [PATCH 06/10] missed a void --- src/main/java/com/mjsalerno/unobot/UnoBotMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java index 716a7a1..476d84e 100755 --- a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java +++ b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java @@ -33,7 +33,7 @@ public static String getVarOrDefault(String key, String def) { String javaProp = System.getProperty(key, def); return System.getenv().getOrDefault(key, javaProp); } - public static putToProperties(Properties p, String key, String value) { + public static void putToProperties(Properties p, String key, String value) { if (value == null) { return; } From 76083eb817f0ab9a3e2a3f54edbf53598674c8de Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 21:14:15 -0500 Subject: [PATCH 07/10] correcting some mistypes on the environment variables --- src/main/java/com/mjsalerno/unobot/UnoBotMain.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java index 476d84e..f3a16f7 100755 --- a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java +++ b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java @@ -54,8 +54,8 @@ public static void main(String[] args) throws Exception { } else { // Allows loading of the config values from either java properties or environment variables putToProperties(p, "Server", getVarOrDefault("Server", "localhost")); putToProperties(p, "Port", getVarOrDefault("Port", "6667")); - putToProperties(p, "Channel", getVarOrDefault("#uno", "")); - putToProperties(p, "Nick", getVarOrDefault("unoBot", "")); + putToProperties(p, "Channel", getVarOrDefault("Channel", "#uno")); + putToProperties(p, "Nick", getVarOrDefault("Nick", "unoBot")); putToProperties(p, "BotOps", getVarOrDefault("BotOps", "")); putToProperties(p, "ScoreBoardFileName", path + getVarOrDefault("ScoreBoardFileName", "/ScoreBoard.dat")); From ef45ccff35d968d542c6640443a8974171dfdf3a Mon Sep 17 00:00:00 2001 From: Steve Date: Sun, 23 Aug 2020 02:22:15 +0000 Subject: [PATCH 08/10] providing an example docker-compose file using a local registry for the container --- docker-compose.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..62c429b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +--- +version: "3.2" + +services: + unobot: + image: 127.0.0.1:5000/unobot + environment: + CONFIG_PATH: /config/ # Primarily storing the scoreboard file + Server: irc.freenode.net + Port: 6697 + Nick: unoBot + Channel: #spdcx + BotOps: roofis0 + UpdateScript: ./runUnoBot.sh + Verbose: "true" + SSL: "true" + + volumes: + - /mnt/data/unobot:/config + From 344302c5db65467a10fdf9b45848b9daa2194a1b Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 21:25:51 -0500 Subject: [PATCH 09/10] Update README.md adding more docker details --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fa48970..70119ca 100755 --- a/README.md +++ b/README.md @@ -18,10 +18,13 @@ and allows members of the channel to play a game of uno. It also has an AI so it 3. run `mvn package` (you will have to cd to UnoBot's directory) 4. run `UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` using the `java -jar ./target/UnoBot-1.0-SNAPSHOT-jar-with-dependencies.jar` command -## Building with Docker -1. docker build . -t unobot -2. docker run unobot -3. ??? Environment variables to come for configuring the docker run +## Running with Docker + +1. `docker build . -t unobot` +2. `docker-compose up` +3. Set the CONFIG_PATH to provide a location to store the scoreboard file and the config.ini (if using the config.ini file). +4. All of the key:value pairs from the config file can be used when starting the docker container and have the same effect. If there is no config file found in the CONIFG_PATH, the environment variables will be used + ### values in the config file Server - if no value given it will default to localhost From bf161cb799c9723321035e3a71be5ceaa66a010a Mon Sep 17 00:00:00 2001 From: Stephen Date: Sat, 22 Aug 2020 21:29:36 -0500 Subject: [PATCH 10/10] moving the methods underneath the main --- .../java/com/mjsalerno/unobot/UnoBotMain.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java index f3a16f7..7d57709 100755 --- a/src/main/java/com/mjsalerno/unobot/UnoBotMain.java +++ b/src/main/java/com/mjsalerno/unobot/UnoBotMain.java @@ -29,17 +29,6 @@ */ public class UnoBotMain { - public static String getVarOrDefault(String key, String def) { - String javaProp = System.getProperty(key, def); - return System.getenv().getOrDefault(key, javaProp); - } - public static void putToProperties(Properties p, String key, String value) { - if (value == null) { - return; - } - p.setProperty(key, value); - } - public static void main(String[] args) throws Exception { Properties p = new Properties(); @@ -149,6 +138,18 @@ public static void main(String[] args) throws Exception { System.exit(0); } } + + public static String getVarOrDefault(String key, String def) { + String javaProp = System.getProperty(key, def); + return System.getenv().getOrDefault(key, javaProp); + } + + public static void putToProperties(Properties p, String key, String value) { + if (value == null) { + return; + } + p.setProperty(key, value); + } static class ExceptionListener extends ListenerAdapter { @Override